Commit Graph

5 Commits

Author SHA1 Message Date
mindesbunister
451a8248d8 feat: implement strategy-aware analysis intervals and remove manual leverage controls
- Remove manual leverage field from automation v2 page since AI now handles leverage automatically
- Fix scalping strategy analysis intervals from 60 minutes to 2 minutes for proper high-frequency trading
- Implement intelligent interval detection based on selected timeframes:
  * Scalping: 2 minutes (5m, 3m, or multiple short timeframes)
  * Day trading: 5 minutes (1h, 2h timeframes)
  * Swing trading: 15 minutes (4h, daily timeframes)
- Fix Drift SDK API calls: replace getTotalPerpPositionValue() with getFreeCollateral()
- Clean up UI by removing manual controls since AI systems handle optimization
- Fix syntax errors in automation service and balance API
- Ensure proper margin calculations using correct Drift Protocol methods

Tested: Scalping strategy now correctly analyzes every 2 minutes instead of 60 minutes
2025-07-24 13:25:41 +02:00
mindesbunister
186cf7db28 fix: accurate account balance calculation using Drift SDK methods
- Fixed unrealized P&L calculation using Drift's built-in methods
- Replaced manual price calculations with official SDK functions
- Total collateral now accurately matches Drift interface (8.04)
- Unrealized P&L shows realistic values instead of inflated amounts
- Color coding already working: green for profits, red for losses
- Account values now sync properly with actual Drift account data
2025-07-24 12:08:21 +02:00
mindesbunister
0828647e80 Fix Drift trading execution: leverage, stop loss, and take profit
- Fix leverage application in trade execution (was not being applied)
- Fix stop loss orders with proper OrderTriggerCondition.BELOW/ABOVE
- Fix take profit orders with TRIGGER_LIMIT order type
- Add OrderTriggerCondition import from Drift SDK
- Increase minimum stop loss from 0.5% to 3% to prevent cancellation
- Improve error logging for stop loss placement failures
- Add comprehensive risk management parameter validation
- Update order placement logic with proper trigger conditions

All trading functionality now working:
 Leverage application (2x, 5x, etc)
 Stop loss orders (minimum 3% for stability)
 Take profit orders (minimum 1%)
 Account balance calculations
 Progress tracking and UI enhancements
2025-07-23 15:26:14 +02:00
mindesbunister
461230d2bc Fix Drift balance calculation and implement multi-RPC failover system
- Fixed balance calculation: corrected precision factor for Drift scaledBalance (5.69 vs wrong 0,678.76)
- Implemented multi-RPC failover system with 4 endpoints (Helius, Solana official, Alchemy, Ankr)
- Updated automation page with balance sync, leverage-based position sizing, and removed daily trade limits
- Added RPC status monitoring endpoint
- Updated balance and positions APIs to use failover system
- All Drift APIs now working correctly with accurate balance data
2025-07-22 17:00:46 +02:00
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