feat: Hybrid RPC strategy (Helius init + Alchemy trades)
CRITICAL: Fix rate limiting by using dual RPC approach Problem: - Helius RPC gets overwhelmed during trade execution (429 errors) - Exit orders fail to place, leaving positions UNPROTECTED - No on-chain TP/SL orders = unlimited risk if container crashes Solution: Hybrid RPC Strategy - Helius for Drift SDK initialization (handles burst subscriptions well) - Alchemy for trade operations (better sustained rate limits) - Falls back to Helius if Alchemy not configured Implementation: - DriftService now has two connections: connection (Helius) + tradeConnection (Alchemy) - Added getTradeConnection() method for trade operations - Updated openPosition() and closePosition() to use trade connection - Added ALCHEMY_RPC_URL to .env (optional, falls back to Helius) Benefits: - Helius: 0 subscription errors during init (proven reliable for SDK setup) - Alchemy: 300M compute units/month for sustained trade operations - Best of both worlds: reliable init + reliable trades Files: - lib/drift/client.ts: Dual connection support - lib/drift/orders.ts: Use getTradeConnection() for confirmations - .env: Added ALCHEMY_RPC_URL Testing: Deploy and execute test trade to verify orders place successfully
This commit is contained in:
2
.env
2
.env
@@ -35,6 +35,8 @@ API_SECRET_KEY=2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb
|
||||
# Drift SDK REQUIRES WebSocket subscriptions - Alchemy doesn't support this
|
||||
# Alchemy "working" state was temporary - always breaks after first trade or shortly after init
|
||||
SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=5e236449-f936-4af7-ae38-f15e2f1a3757
|
||||
# Alchemy RPC URL for trade operations (better sustained rate limits, optional)
|
||||
ALCHEMY_RPC_URL=https://solana-mainnet.g.alchemy.com/v2/fDKYNe7eL83HRH5Y4xW54qg6tTk0L7y0
|
||||
|
||||
# Alternative RPC providers (reference):
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user