🎯 Fix Drift trading bot backend - correct account balance detection

- Fix backend to correctly display 18 Net USD Value and 6.81 SOL position
- Replace failing SDK subscriptions with direct blockchain account parsing
- Parse USDC balance at offset 106 (.53) and SOL position at offset 1208 (6.81 SOL)
- Update balance API to return correct totalValue: 18.05 matching Drift UI
- Implement direct account data fetching bypassing RPC 410 errors
- Create analysis scripts for debugging account data structure
- Update /api/drift/balance and /api/drift/positions endpoints

Backend now correctly matches Drift UI:
- Net USD Value: 18.05 
- SOL Position: 6.81 SOL 
- USDC Balance: .53 
- Unrealized PnL: 4.37 
This commit is contained in:
mindesbunister
2025-07-14 10:52:22 +02:00
parent 23cab77200
commit 52051e1cad
7 changed files with 728 additions and 1832 deletions

View File

@@ -3,7 +3,7 @@ import { driftTradingService } from '../../../../lib/drift-trading'
export async function GET() {
try {
const balance = await driftTradingService.getAccountBalance()
const balance = await driftTradingService.getTradingBalance()
return NextResponse.json(balance)
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 })