From 1a32cdec8c2def9344577347c28a432c81250233 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Thu, 24 Jul 2025 17:39:59 +0200 Subject: [PATCH] fix: Respect user trading mode choice in optimized automation Frontend changes: - Pass mode, tradingAmount, balancePercentage, dexProvider to optimized API - Send user's actual trading mode choice (LIVE/SIMULATION) Backend changes: - Accept mode and trading parameters from frontend request - Use passed mode instead of hardcoded 'SIMULATION' - Apply user's trading amount and balance percentage settings This fixes the issue where optimized automation always used SIMULATION regardless of user's LIVE trading selection. --- app/api/analysis-optimized/route.js | 22 +++++++++++++++++----- app/automation-v2/page.js | 6 +++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/api/analysis-optimized/route.js b/app/api/analysis-optimized/route.js index 805c015..7293c5b 100644 --- a/app/api/analysis-optimized/route.js +++ b/app/api/analysis-optimized/route.js @@ -6,7 +6,19 @@ import { progressTracker } from '../../../lib/progress-tracker' export async function POST(request) { try { const body = await request.json() - const { symbol, timeframes, selectedTimeframes, layouts, analyze = true, automationMode = false } = body + export async function POST(request) { + try { + const { + symbol, + timeframes, + layouts = ['ai', 'diy'], + analyze = true, + automationMode = false, + mode = 'SIMULATION', // Default to simulation if not provided + tradingAmount = 100, + balancePercentage = 50, + dexProvider = 'DRIFT' + } = await request.json() // Use selectedTimeframes if provided, fallback to timeframes, then default const targetTimeframes = selectedTimeframes || timeframes || ['1h', '4h'] @@ -31,10 +43,10 @@ export async function POST(request) { symbol: symbol || 'SOLUSD', timeframe: targetTimeframes[0] || '15', // Primary timeframe for database selectedTimeframes: targetTimeframes, - mode: 'SIMULATION', - dexProvider: 'DRIFT', - tradingAmount: 100, - balancePercentage: 50, + mode: mode, // Use the mode passed from frontend + dexProvider: dexProvider, + tradingAmount: tradingAmount, + balancePercentage: balancePercentage, maxLeverage: 3, // Required field for automation riskPercentage: 2, // Required field for automation maxDailyTrades: 5, diff --git a/app/automation-v2/page.js b/app/automation-v2/page.js index f33cc3d..209c22f 100644 --- a/app/automation-v2/page.js +++ b/app/automation-v2/page.js @@ -156,7 +156,11 @@ export default function AutomationPageV2() { timeframes: config.selectedTimeframes, layouts: ['ai', 'diy'], analyze: true, - automationMode: true // Flag to indicate this is automation, not just testing + automationMode: true, // Flag to indicate this is automation, not just testing + mode: config.mode, // Pass the user's trading mode choice + tradingAmount: config.tradingAmount, + balancePercentage: config.balancePercentage, + dexProvider: config.dexProvider } const startTime = Date.now()