feat: Hybrid RPC fallback system (Alchemy → Helius)
- Automatic fallback after 2 consecutive rate limits - Primary: Alchemy (300M CU/month, stable for normal ops) - Fallback: Helius (10 req/sec, backup for startup bursts) - Reduced startup validation: 6h window, 5 trades (was 24h, 20 trades) - Multi-position safety check (prevents order cancellation conflicts) - Rate limit-aware retry logic with exponential backoff Implementation: - lib/drift/client.ts: Added fallbackConnection, switchToFallbackRpc() - .env: SOLANA_FALLBACK_RPC_URL configuration - lib/startup/init-position-manager.ts: Reduced validation scope - lib/trading/position-manager.ts: Multi-position order protection Tested: System switched to fallback on startup, Position Manager active Result: 1 active trade being monitored after automatic RPC switch
This commit is contained in:
@@ -52,6 +52,7 @@ async function validateOpenTrades() {
|
||||
|
||||
// Get both truly open trades AND recently "closed" trades (last 24h)
|
||||
// Recently closed trades might still be open if close transaction failed
|
||||
// TEMPORARILY REDUCED: Check only last 5 closed trades to avoid rate limiting on startup
|
||||
const [openTrades, recentlyClosedTrades] = await Promise.all([
|
||||
prisma.trade.findMany({
|
||||
where: { status: 'open' },
|
||||
@@ -60,10 +61,10 @@ async function validateOpenTrades() {
|
||||
prisma.trade.findMany({
|
||||
where: {
|
||||
exitReason: { not: null },
|
||||
exitTime: { gte: new Date(Date.now() - 24 * 60 * 60 * 1000) } // Last 24 hours
|
||||
exitTime: { gte: new Date(Date.now() - 6 * 60 * 60 * 1000) } // Last 6 hours (reduced from 24h)
|
||||
},
|
||||
orderBy: { exitTime: 'desc' },
|
||||
take: 20 // Check last 20 closed trades
|
||||
take: 5 // Reduced from 20 to avoid rate limiting
|
||||
})
|
||||
])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user