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:
53
scripts/place-manual-orders.mjs
Normal file
53
scripts/place-manual-orders.mjs
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Emergency script to manually place TP/SL orders for unprotected position
|
||||
*/
|
||||
|
||||
const API_URL = 'http://localhost:3001'
|
||||
|
||||
// Trade details from database
|
||||
const tradeId = 'cmhyw5pn7000imo07n65ihi8y'
|
||||
const symbol = 'SOL-PERP'
|
||||
const direction = 'long'
|
||||
const entryPrice = 137.069998
|
||||
const positionSizeUSD = 42.92421
|
||||
const stopLossPrice = 135.69929802
|
||||
const tp1Price = 137.618277992
|
||||
const tp2Price = 138.029487986
|
||||
|
||||
console.log('🚨 EMERGENCY: Placing TP/SL orders manually')
|
||||
console.log(`Trade ID: ${tradeId}`)
|
||||
console.log(`Symbol: ${symbol}`)
|
||||
console.log(`Direction: ${direction}`)
|
||||
console.log(`Entry: $${entryPrice}`)
|
||||
console.log(`Size: $${positionSizeUSD}`)
|
||||
console.log(`SL: $${stopLossPrice}`)
|
||||
console.log(`TP1: $${tp1Price}`)
|
||||
console.log(`TP2: $${tp2Price}`)
|
||||
|
||||
// Call internal API
|
||||
const response = await fetch(`${API_URL}/api/trading/execute`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
action: 'place_exit_orders_only',
|
||||
symbol,
|
||||
direction,
|
||||
entryPrice,
|
||||
positionSizeUSD,
|
||||
stopLossPrice,
|
||||
tp1Price,
|
||||
tp2Price,
|
||||
})
|
||||
})
|
||||
|
||||
const result = await response.json()
|
||||
console.log('\n📊 Result:', JSON.stringify(result, null, 2))
|
||||
|
||||
if (result.success) {
|
||||
console.log('✅ Orders placed successfully!')
|
||||
} else {
|
||||
console.error('❌ Failed to place orders:', result.error)
|
||||
}
|
||||
Reference in New Issue
Block a user