diff --git a/package-lock.json b/package-lock.json index 29995b3..3b46b02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "recharts": "^3.8.1", "tailwind-merge": "^3.5.0", "tailwindcss-animate": "^1.0.7", + "undici": "^8.1.0", "zod": "^4.3.6" }, "devDependencies": { @@ -9215,6 +9216,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici": { + "version": "8.1.0", + "resolved": "https://registry.npmmirror.com/undici/-/undici-8.1.0.tgz", + "integrity": "sha512-E9MkTS4xXLnRPYqxH2e6Hr2/49e7WFDKczKcCaFH4VaZs2iNvHMqeIkyUAD9vM8kujy9TjVrRlQ5KkdEJxB2pw==", + "license": "MIT", + "engines": { + "node": ">=22.19.0" + } + }, "node_modules/undici-types": { "version": "6.21.0", "resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-6.21.0.tgz", diff --git a/package.json b/package.json index 8574403..545f474 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "recharts": "^3.8.1", "tailwind-merge": "^3.5.0", "tailwindcss-animate": "^1.0.7", + "undici": "^8.1.0", "zod": "^4.3.6" }, "devDependencies": { diff --git a/src/actions/market.ts b/src/actions/market.ts index 72000fd..a1b90bd 100644 --- a/src/actions/market.ts +++ b/src/actions/market.ts @@ -1,5 +1,6 @@ 'use server'; +import { ProxyAgent } from 'undici'; import { db } from '@/db'; import { assets } from '@/db/schema'; import { eq } from 'drizzle-orm'; @@ -22,6 +23,9 @@ export async function syncAllMarketPrices() { .select() .from(assets); + const proxyUrl = process.env.HTTPS_PROXY; + const proxyDispatcher = proxyUrl ? new ProxyAgent(proxyUrl) : undefined; + let successCount = 0; for (const asset of allAssets) { @@ -48,7 +52,7 @@ export async function syncAllMarketPrices() { } } else if (asset.type === 'CRYPTO') { const cryptoSymbol = asset.symbol.trim().toUpperCase() + 'USDT'; - const response = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=${cryptoSymbol}`, { cache: 'no-store' }); + const response = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=${cryptoSymbol}`, { cache: 'no-store', dispatcher: proxyDispatcher } as RequestInit & { dispatcher?: any }); if (response.ok) { const data = await response.json();