🎯 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:
33
test-direct-service.js
Normal file
33
test-direct-service.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const { DriftTradingService } = require('./lib/drift-trading.ts')
|
||||
|
||||
async function testDirectBalance() {
|
||||
console.log('🔍 Testing direct balance retrieval with detailed logging...')
|
||||
|
||||
try {
|
||||
const driftService = new DriftTradingService()
|
||||
|
||||
console.log('🔐 Attempting login...')
|
||||
const loginResult = await driftService.login()
|
||||
console.log('✅ Login result:', JSON.stringify(loginResult, null, 2))
|
||||
|
||||
if (loginResult.isLoggedIn && loginResult.userAccountExists) {
|
||||
console.log('\n💰 Getting account balance...')
|
||||
const balance = await driftService.getAccountBalance()
|
||||
console.log('📊 Balance result:', JSON.stringify(balance, null, 2))
|
||||
|
||||
console.log('\n📈 Getting positions...')
|
||||
const positions = await driftService.getPositions()
|
||||
console.log('📊 Positions result:', JSON.stringify(positions, null, 2))
|
||||
} else {
|
||||
console.log('❌ Login failed or account does not exist')
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error:', error.message)
|
||||
console.error('📊 Stack trace:', error.stack)
|
||||
}
|
||||
}
|
||||
|
||||
testDirectBalance()
|
||||
.then(() => console.log('✅ Test completed'))
|
||||
.catch(error => console.error('❌ Test failed:', error))
|
||||
Reference in New Issue
Block a user