diff --git a/components/AIAnalysisPanel.tsx b/components/AIAnalysisPanel.tsx index b238fba..86afc5e 100644 --- a/components/AIAnalysisPanel.tsx +++ b/components/AIAnalysisPanel.tsx @@ -504,6 +504,72 @@ export default function AIAnalysisPanel({ onAnalysisComplete }: AIAnalysisPanelP setTradeModalOpen(true) } + // Manual trade marking for follow-up (when trading manually on external platforms) + const markAsTraded = async (analysisData: any) => { + try { + console.log('š Marking analysis as manually traded for follow-up:', analysisData) + + // Extract trade data from analysis + const analysis = analysisData.result?.analysis || analysisData.analysis + if (!analysis) { + alert('ā No analysis data found to mark as traded') + return + } + + // Create virtual position for follow-up tracking + const entryPrice = analysis.entry?.price || 0 + const stopLoss = analysis.stopLoss?.price || null + const takeProfit = analysis.takeProfits?.tp1?.price || null + const side = analysis.recommendation === 'BUY' ? 'LONG' : analysis.recommendation === 'SELL' ? 'SHORT' : 'LONG' + + if (!entryPrice) { + alert('ā No entry price found in analysis') + return + } + + // Prompt for trade details + const amount = prompt('Enter trade amount (size):') + if (!amount || parseFloat(amount) <= 0) return + + const actualEntryPrice = prompt(`Confirm entry price (from analysis: $${entryPrice}):`, entryPrice.toString()) + if (!actualEntryPrice) return + + const response = await fetch('/api/trading/positions', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + action: 'add', + symbol: symbol, + side: side, + amount: parseFloat(amount), + entryPrice: parseFloat(actualEntryPrice), + leverage: 1, + stopLoss: stopLoss, + takeProfit: takeProfit, + txId: `manual_${Date.now()}`, + notes: `Manual trade marked from AI analysis - ${analysis.summary?.substring(0, 100) || 'AI trading setup'}` + }) + }) + + const result = await response.json() + + if (result.success) { + alert(`ā Position marked as traded!\n\n⢠${side} ${amount} ${symbol}\n⢠Entry: $${actualEntryPrice}\n⢠Follow-up assistant now available`) + + // Optional: Show follow-up panel + if (confirm('Open Trade Follow-up Assistant now?')) { + setFollowUpPanelOpen(true) + } + } else { + throw new Error(result.error || 'Failed to mark trade') + } + + } catch (error) { + console.error('Error marking trade:', error) + alert(`ā Failed to mark trade: ${error instanceof Error ? error.message : 'Unknown error'}`) + } + } + // Trade execution API call const executeTrade = async (tradeData: any) => { try { @@ -1022,12 +1088,21 @@ export default function AIAnalysisPanel({ onAnalysisComplete }: AIAnalysisPanelP