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!
This commit is contained in:
mindesbunister
2025-07-22 12:23:51 +02:00
parent 491ff51ba9
commit fb194f1b12
28 changed files with 7285 additions and 198 deletions

View File

@@ -33,14 +33,6 @@ export async function GET() {
}
// Get actual trade data to calculate real statistics
// Get ALL trades count for consistency
const totalTradesCount = await prisma.trade.count({
where: {
userId: session.userId,
symbol: session.symbol
}
})
const trades = await prisma.trade.findMany({
where: {
userId: session.userId,
@@ -70,7 +62,7 @@ export async function GET() {
mode: session.mode,
symbol: session.symbol,
timeframe: session.timeframe,
totalTrades: totalTradesCount, // Use actual total count
totalTrades: completedTrades.length,
successfulTrades: successfulTrades.length,
winRate: Math.round(winRate * 10) / 10, // Round to 1 decimal
totalPnL: Math.round(totalPnL * 100) / 100, // Round to 2 decimals