feat: switch from Helius to Alchemy RPC provider
Changes: - Updated SOLANA_RPC_URL to use Alchemy (https://solana-mainnet.g.alchemy.com/v2/...) - Migrated from Helius free tier to Alchemy free tier - Includes previous rate limit fixes (8s backoff, 2s operation delays) Context: - Helius free tier: 10 req/sec sustained, 100 req/sec burst - Alchemy free tier: 300M compute units/month (more generous) - User hit 239 rate limit errors in 10 minutes on Helius - User registered Alchemy account and provided API key Impact: - Should significantly reduce 429 rate limit errors - Better free tier limits for trading bot operations - Combined with delay fixes for optimal RPC usage
This commit is contained in:
2
.env
2
.env
@@ -33,7 +33,7 @@ API_SECRET_KEY=2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb
|
||||
#
|
||||
# RECOMMENDED: Helius (best performance, free tier available)
|
||||
# Get free API key at: https://helius.dev
|
||||
SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=7485e2bf-0681-4215-be31-76e2707f31cc
|
||||
SOLANA_RPC_URL=https://solana-mainnet.g.alchemy.com/v2/5A0iA5UYpsmP9gkuezYeg
|
||||
|
||||
# Alternative RPC providers (if not using Helius):
|
||||
#
|
||||
|
||||
@@ -299,6 +299,9 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
console.log(` Leverage: ${leverage}x`)
|
||||
console.log(` Total position: $${positionSizeUSD}`)
|
||||
|
||||
// Helper function for rate limit spacing
|
||||
const rpcDelay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
// Open position
|
||||
const openResult = await openPosition({
|
||||
symbol: driftSymbol,
|
||||
@@ -306,6 +309,9 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
sizeUSD: positionSizeUSD,
|
||||
slippageTolerance: config.slippageTolerance,
|
||||
})
|
||||
|
||||
// Wait 2 seconds before placing exit orders to space out RPC calls
|
||||
await rpcDelay(2000)
|
||||
|
||||
if (!openResult.success) {
|
||||
return NextResponse.json(
|
||||
@@ -331,6 +337,9 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
|
||||
try {
|
||||
console.log(`⚠️ Closing phantom position immediately for safety...`)
|
||||
// Wait 2 seconds to space out RPC calls
|
||||
await rpcDelay(2000)
|
||||
|
||||
closeResult = await closePosition({
|
||||
symbol: driftSymbol,
|
||||
percentToClose: 100, // Close 100% of whatever size exists
|
||||
|
||||
@@ -654,7 +654,7 @@ export async function closePosition(
|
||||
async function retryWithBackoff<T>(
|
||||
fn: () => Promise<T>,
|
||||
maxRetries: number = 3,
|
||||
baseDelay: number = 5000 // Increased from 2s to 5s: 5s → 10s → 20s progression
|
||||
baseDelay: number = 8000 // Increased from 5s to 8s: 8s → 16s → 32s progression for better RPC recovery
|
||||
): Promise<T> {
|
||||
const startTime = Date.now()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user