diff --git a/app/api/automation/start/route.js b/app/api/automation/start/route.js index 45b3271..230ed3e 100644 --- a/app/api/automation/start/route.js +++ b/app/api/automation/start/route.js @@ -17,7 +17,6 @@ export async function POST(request) { // Map tradeSize to tradingAmount tradingAmount: config.tradeSize || config.tradingAmount, // Set defaults for missing fields - maxLeverage: config.maxLeverage || 2, maxDailyTrades: config.maxDailyTrades || 5, dexProvider: config.dexProvider || 'DRIFT', selectedTimeframes: config.selectedTimeframes || [config.timeframe || '1h'] diff --git a/app/api/drift/balance/route.js b/app/api/drift/balance/route.js index 98cedd3..1141f57 100644 --- a/app/api/drift/balance/route.js +++ b/app/api/drift/balance/route.js @@ -87,16 +87,19 @@ export async function GET() { unrealizedPnl = 0 // Default to 0 if we can't calculate } + let freeCollateralFromDrift = 0 try { - // Calculate margin requirement using Drift's method - marginRequirement = await driftClient.getUser().getTotalPerpPositionValue() / 1e6 * 0.1 // 10% margin + // Calculate margin requirement using proper Drift SDK methods + freeCollateralFromDrift = await driftClient.getUser().getFreeCollateral() / 1e6 // Convert to USDC + marginRequirement = Math.max(0, totalCollateral - freeCollateralFromDrift) // Used collateral } catch (marginError) { console.warn('⚠️ Could not get margin requirement, calculating manually:', marginError.message) marginRequirement = 0 // Default to 0 if we can't calculate } // Calculate free collateral and other derived values - const freeCollateral = totalCollateral - marginRequirement + unrealizedPnl + // Use Drift's free collateral if available, otherwise calculate manually + const freeCollateral = freeCollateralFromDrift > 0 ? freeCollateralFromDrift : Math.max(0, totalCollateral - marginRequirement + unrealizedPnl) const accountValue = totalCollateral + unrealizedPnl const leverage = marginRequirement > 0 ? (marginRequirement / accountValue) : 0 const availableBalance = Math.max(0, freeCollateral) diff --git a/app/automation-v2/page.js b/app/automation-v2/page.js index be1333f..63001c6 100644 --- a/app/automation-v2/page.js +++ b/app/automation-v2/page.js @@ -21,7 +21,6 @@ export default function AutomationPageV2() { selectedTimeframes: ['60'], // Multi-timeframe support tradingAmount: 100, balancePercentage: 50, // Default to 50% of available balance - maxLeverage: 5 // stopLossPercent and takeProfitPercent removed - AI calculates these automatically }) @@ -268,22 +267,6 @@ export default function AutomationPageV2() { -
- With {config.maxLeverage}x leverage: ${(config.tradingAmount * config.maxLeverage).toFixed(2)} position exposure -
- )} @@ -524,10 +502,6 @@ export default function AutomationPageV2() { {config.selectedTimeframes.map(tf => timeframes.find(t => t.value === tf)?.label).filter(Boolean).join(', ')} -Loading bot status...
@@ -653,7 +627,33 @@ export default function AutomationPageV2() { >