Files
trading_bot_v3/test-corrected-trade.js
mindesbunister fb194f1b12 Implement working Drift leverage trading
Key Features:
-  Drift SDK v2.126.0-beta.14 integration with Helius RPC
-  User account initialization and balance reading
-  Leverage trading API with real trades executed
-  Support for SOL, BTC, ETH, APT, AVAX, BNB, MATIC, ARB, DOGE, OP
-  Transaction confirmed: gNmaWVqcE4qNK31ksoUsK6pcHqdDTaUtJXY52ZoXRF

API Endpoints:
- POST /api/drift/trade - Main trading endpoint
- Actions: get_balance, place_order
- Successfully tested with 0.01 SOL buy order at 2x leverage

Technical Fixes:
- Fixed RPC endpoint blocking with Helius API key
- Resolved wallet signing compatibility issues
- Implemented proper BigNumber handling for amounts
- Added comprehensive error handling and logging

Trading Bot Status: 🚀 FULLY OPERATIONAL with leverage trading!
2025-07-22 12:23:51 +02:00

55 lines
2.0 KiB
JavaScript

// Test the corrected trade calculation
async function testCorrectedTrade() {
console.log('=== CORRECTED TRADE CALCULATION TEST ===')
// Simulate current SOL price
const currentPrice = 189.50
// Simulate config
const config = {
tradingAmount: 100, // $100 USD investment
riskPercentage: 100, // 100% of trading amount
symbol: 'SOLUSD'
}
// Simulate analysis
const analysis = {
confidence: 75, // 75% confidence
recommendation: 'BUY'
}
// Calculate position size (this is what should happen)
const baseAmount = config.tradingAmount
const riskAdjustment = config.riskPercentage / 100
const confidenceAdjustment = analysis.confidence / 100
const usdAmount = baseAmount * riskAdjustment * confidenceAdjustment
const tokenAmount = usdAmount / currentPrice
console.log(`💰 Trading Amount: $${config.tradingAmount}`)
console.log(`📊 Risk Adjustment: ${(riskAdjustment * 100)}%`)
console.log(`🎯 Confidence Adjustment: ${(confidenceAdjustment * 100)}%`)
console.log(`💵 USD Amount to Invest: $${usdAmount}`)
console.log(`📈 Current SOL Price: $${currentPrice}`)
console.log(`🪙 Token Amount: ${tokenAmount.toFixed(4)} SOL`)
console.log('\n=== COMPARISON ===')
console.log(`❌ Old (Wrong): 2.04 SOL at $100 = $204 position size`)
console.log(`✅ New (Correct): ${tokenAmount.toFixed(4)} SOL at $${currentPrice} = $${(tokenAmount * currentPrice).toFixed(2)} position size`)
// Simulate slippage and execution
const slippage = 0.002 // 0.2%
const executionPrice = currentPrice * (1 + slippage)
console.log('\n=== EXECUTION ===')
console.log(`🎲 Slippage: ${(slippage * 100).toFixed(2)}%`)
console.log(`💱 Execution Price: $${executionPrice.toFixed(2)}`)
console.log(`📝 Trade Record:`)
console.log(` - Side: BUY`)
console.log(` - Amount: ${tokenAmount.toFixed(4)} SOL`)
console.log(` - Price: $${executionPrice.toFixed(2)}`)
console.log(` - Total Value: $${(tokenAmount * executionPrice).toFixed(2)}`)
}
testCorrectedTrade()