feat: pre-implementation backup - current ai-analysis system state
- Current basic analysis system with technical indicators - About to implement professional trading desk features - Backup before major analysis prompt enhancements
This commit is contained in:
@@ -147,42 +147,18 @@ export default function SafePaperTradingPage() {
|
||||
if (savedContinuousLearning === 'true') {
|
||||
console.log('🔄 Restoring continuous learning state...')
|
||||
setContinuousLearning(true)
|
||||
// Force restart continuous learning immediately
|
||||
setTimeout(() => {
|
||||
console.log('🎓 Starting continuous learning from restored state')
|
||||
startContinuousLearning()
|
||||
}, 1000) // Reduced delay
|
||||
} else {
|
||||
console.log('💡 No continuous learning state found - user needs to start manually')
|
||||
}, 2000)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('⚠️ Error checking continuous learning state:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// Force enable learning for testing - DEBUG FUNCTION
|
||||
const forceEnableLearning = () => {
|
||||
console.log('🔧 FORCE ENABLING CONTINUOUS LEARNING...')
|
||||
localStorage.setItem('safePaperTrading_continuousLearning', 'true')
|
||||
setContinuousLearning(true)
|
||||
setTimeout(() => {
|
||||
console.log('🎓 Force starting continuous learning')
|
||||
startContinuousLearning()
|
||||
}, 500)
|
||||
console.log('✅ Continuous learning forcefully enabled')
|
||||
}
|
||||
|
||||
// Check state immediately
|
||||
checkContinuousLearningState()
|
||||
|
||||
// Expose force enable function to browser console for debugging
|
||||
if (typeof window !== 'undefined') {
|
||||
window.forceEnableLearning = forceEnableLearning
|
||||
console.log('🔧 Debug function exposed: window.forceEnableLearning()')
|
||||
}
|
||||
|
||||
// Also check after a short delay to ensure everything is loaded
|
||||
setTimeout(checkContinuousLearningState, 2000)
|
||||
// Check state after a short delay to ensure everything is loaded
|
||||
setTimeout(checkContinuousLearningState, 1000)
|
||||
}, [])
|
||||
|
||||
// Persist analysis data whenever it changes
|
||||
@@ -426,82 +402,17 @@ export default function SafePaperTradingPage() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// Load paper trading data from localStorage using consistent keys
|
||||
// Check both old and new key patterns for backward compatibility
|
||||
const savedTrades = localStorage.getItem('safePaperTrading_paperTrades') || localStorage.getItem('safePaperTrades')
|
||||
const savedBalance = localStorage.getItem('safePaperTrading_paperBalance') || localStorage.getItem('safePaperBalance')
|
||||
// Load paper trading data from localStorage
|
||||
const savedTrades = localStorage.getItem('safePaperTrades')
|
||||
const savedBalance = localStorage.getItem('safePaperBalance')
|
||||
|
||||
if (savedTrades) {
|
||||
setPaperTrades(JSON.parse(savedTrades))
|
||||
console.log('📂 Restored paper trades from localStorage')
|
||||
}
|
||||
if (savedBalance) {
|
||||
setPaperBalance(parseFloat(savedBalance))
|
||||
console.log('📂 Restored paper balance from localStorage')
|
||||
}
|
||||
|
||||
// Sync with API trades (from automation)
|
||||
const syncApiTrades = async () => {
|
||||
try {
|
||||
console.log('🔄 Syncing trades from API...')
|
||||
const response = await fetch('/api/safe-paper-trading/trades')
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
if (data.success && data.trades.length > 0) {
|
||||
console.log(`📈 Found ${data.trades.length} API trades, syncing with localStorage...`)
|
||||
|
||||
// Get existing localStorage trades
|
||||
const existingTrades = JSON.parse(localStorage.getItem('safePaperTrading_paperTrades') || '[]')
|
||||
|
||||
// Convert API trades to frontend format and filter out existing ones
|
||||
const existingIds = new Set(existingTrades.map(t => t.id))
|
||||
const newTrades = data.trades
|
||||
.filter(t => !existingIds.has(t.id))
|
||||
.map(apiTrade => ({
|
||||
id: apiTrade.id,
|
||||
symbol: apiTrade.symbol,
|
||||
side: apiTrade.side,
|
||||
positionSize: apiTrade.amount, // Map amount to positionSize
|
||||
entryPrice: apiTrade.entry, // Map entry to entryPrice
|
||||
confidence: apiTrade.confidence,
|
||||
reasoning: apiTrade.reasoning,
|
||||
source: apiTrade.source,
|
||||
status: apiTrade.status,
|
||||
timestamp: apiTrade.createdAt, // Map createdAt to timestamp
|
||||
pnl: apiTrade.pnl || 0,
|
||||
fees: apiTrade.fees || 0
|
||||
}))
|
||||
|
||||
if (newTrades.length > 0) {
|
||||
const combinedTrades = [...existingTrades, ...newTrades]
|
||||
setPaperTrades(combinedTrades)
|
||||
localStorage.setItem('safePaperTrading_paperTrades', JSON.stringify(combinedTrades))
|
||||
|
||||
// Update balance based on new trades
|
||||
const additionalValue = newTrades.reduce((sum, trade) => {
|
||||
return sum + (trade.side === 'BUY' ? -trade.positionSize : trade.positionSize)
|
||||
}, 0)
|
||||
|
||||
const newBalance = paperBalance + additionalValue
|
||||
setPaperBalance(newBalance)
|
||||
localStorage.setItem('safePaperTrading_paperBalance', newBalance.toString())
|
||||
|
||||
console.log(`✅ Synced ${newTrades.length} new trades from API`)
|
||||
} else {
|
||||
console.log('📊 All API trades already in localStorage')
|
||||
}
|
||||
} else {
|
||||
console.log('📊 No API trades found')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('❌ Failed to sync API trades:', error.message)
|
||||
}
|
||||
}
|
||||
|
||||
// Sync API trades after loading localStorage
|
||||
syncApiTrades()
|
||||
|
||||
// Fetch AI learning status
|
||||
fetchLearningStatus()
|
||||
|
||||
@@ -521,12 +432,8 @@ export default function SafePaperTradingPage() {
|
||||
}
|
||||
}, [selectedTimeframes])
|
||||
|
||||
// Save to localStorage whenever data changes - use consistent prefixed keys
|
||||
// Save to localStorage whenever data changes
|
||||
useEffect(() => {
|
||||
localStorage.setItem('safePaperTrading_paperTrades', JSON.stringify(paperTrades))
|
||||
localStorage.setItem('safePaperTrading_paperBalance', paperBalance.toString())
|
||||
|
||||
// Also save to old keys for backward compatibility (temporarily)
|
||||
localStorage.setItem('safePaperTrades', JSON.stringify(paperTrades))
|
||||
localStorage.setItem('safePaperBalance', paperBalance.toString())
|
||||
}, [paperTrades, paperBalance])
|
||||
@@ -872,15 +779,8 @@ export default function SafePaperTradingPage() {
|
||||
setPaperBalance(1000)
|
||||
setPaperTrades([])
|
||||
setCurrentAnalysis(null)
|
||||
|
||||
// Clear both key patterns to ensure complete reset
|
||||
localStorage.removeItem('safePaperTrades')
|
||||
localStorage.removeItem('safePaperBalance')
|
||||
localStorage.removeItem('safePaperTrading_paperTrades')
|
||||
localStorage.removeItem('safePaperTrading_paperBalance')
|
||||
localStorage.removeItem('safePaperTrading_currentAnalysis')
|
||||
|
||||
console.log('🗑️ All safe paper trading data reset')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -910,6 +810,51 @@ export default function SafePaperTradingPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* AI LEARNING SETUP NOTICE */}
|
||||
{!continuousLearning || !autoExecuteTrades ? (
|
||||
<div className="bg-blue-900/30 border border-blue-600 rounded-lg p-4">
|
||||
<h3 className="text-blue-400 font-bold text-lg mb-2">🤖 Enable AI Learning from Virtual Trading</h3>
|
||||
<div className="text-sm text-blue-300 mb-3">
|
||||
<strong>Current Issue:</strong> AI is analyzing but not learning from outcomes because virtual trading is not enabled.
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div className="bg-blue-800/30 rounded p-3">
|
||||
<h4 className="text-blue-300 font-medium mb-1">Step 1: Enable Continuous Learning</h4>
|
||||
<p className="text-xs text-blue-200">
|
||||
{continuousLearning ? '✅ Enabled' : '❌ Click "🎓 Start Learning" button below'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-blue-800/30 rounded p-3">
|
||||
<h4 className="text-blue-300 font-medium mb-1">Step 2: Enable Auto-Execute</h4>
|
||||
<p className="text-xs text-blue-200">
|
||||
{autoExecuteTrades ? '✅ Enabled' : continuousLearning ? '❌ Enable "Auto-Execute Trades" below' : '⏸️ Waiting for Step 1'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 text-xs text-blue-300 bg-blue-800/20 px-3 py-2 rounded">
|
||||
<strong>Result:</strong> AI will automatically execute virtual trades → track outcomes → learn patterns → improve over time
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-green-900/30 border border-green-600 rounded-lg p-4">
|
||||
<h3 className="text-green-400 font-bold text-lg mb-2">✅ AI Learning System Active</h3>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm">
|
||||
<div className="text-green-300">
|
||||
<span className="font-medium">🎓 Continuous Learning:</span> ON
|
||||
</div>
|
||||
<div className="text-green-300">
|
||||
<span className="font-medium">🤖 Auto-Execute:</span> ON
|
||||
</div>
|
||||
<div className="text-green-300">
|
||||
<span className="font-medium">📈 Virtual Trading:</span> Active
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-2 text-xs text-green-300">
|
||||
🧠 AI will automatically execute virtual trades based on analysis and learn from outcomes to improve performance
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Header with Balance */}
|
||||
<div className="bg-gray-800/50 rounded-lg p-6 border border-gray-700">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
@@ -1050,32 +995,49 @@ export default function SafePaperTradingPage() {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Auto-Execute Toggle - Only show when continuous learning is active */}
|
||||
{continuousLearning && (
|
||||
<div className="mt-4 p-3 bg-gray-800 rounded-lg border border-gray-700">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-gray-300">Auto-Execute Trades</span>
|
||||
<span className="text-xs text-gray-400">Automatically execute paper trades based on AI recommendations (≥60% confidence)</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setAutoExecuteTrades(!autoExecuteTrades)}
|
||||
className={`ml-4 px-4 py-2 rounded-lg font-medium transition-all duration-200 ${
|
||||
autoExecuteTrades
|
||||
? 'bg-green-600 hover:bg-green-700 text-white'
|
||||
: 'bg-gray-600 hover:bg-gray-700 text-white'
|
||||
}`}
|
||||
>
|
||||
{autoExecuteTrades ? '🤖 ON' : '📄 Manual'}
|
||||
</button>
|
||||
{/* Auto-Execute Toggle - Show always, but disabled until continuous learning is active */}
|
||||
<div className="mt-4 p-3 bg-gray-800 rounded-lg border border-gray-700">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-gray-300">Auto-Execute Trades</span>
|
||||
<span className="text-xs text-gray-400">
|
||||
{continuousLearning
|
||||
? "Automatically execute paper trades based on AI recommendations (≥60% confidence)"
|
||||
: "⚠️ Enable Continuous Learning first to activate auto-execute virtual trading"
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
{autoExecuteTrades && (
|
||||
<div className="mt-2 text-xs text-yellow-400">
|
||||
⚡ Paper trades will be executed automatically when AI recommends BUY/SELL with ≥60% confidence
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
onClick={() => {
|
||||
if (!continuousLearning) {
|
||||
alert('Please enable Continuous Learning first to activate auto-execute virtual trading!')
|
||||
return
|
||||
}
|
||||
setAutoExecuteTrades(!autoExecuteTrades)
|
||||
}}
|
||||
disabled={!continuousLearning}
|
||||
className={`ml-4 px-4 py-2 rounded-lg font-medium transition-all duration-200 ${
|
||||
!continuousLearning
|
||||
? 'bg-gray-500 text-gray-400 cursor-not-allowed opacity-50'
|
||||
: autoExecuteTrades
|
||||
? 'bg-green-600 hover:bg-green-700 text-white'
|
||||
: 'bg-gray-600 hover:bg-gray-700 text-white'
|
||||
}`}
|
||||
>
|
||||
{!continuousLearning ? '🔒 Locked' : autoExecuteTrades ? '🤖 ON' : '📄 Manual'}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{autoExecuteTrades && continuousLearning && (
|
||||
<div className="mt-2 text-xs text-yellow-400">
|
||||
⚡ Paper trades will be executed automatically when AI recommends BUY/SELL with ≥60% confidence
|
||||
</div>
|
||||
)}
|
||||
{!continuousLearning && (
|
||||
<div className="mt-2 text-xs text-blue-400 bg-blue-900/20 px-2 py-1 rounded">
|
||||
💡 <strong>For AI Learning:</strong> Enable "Continuous Learning" + "Auto-Execute" so the AI can learn from virtual trade outcomes
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1274,11 +1236,6 @@ export default function SafePaperTradingPage() {
|
||||
<div className="bg-gray-700/50 rounded p-3">
|
||||
<p className="text-gray-400 text-sm">Confidence</p>
|
||||
<p className="font-bold text-lg text-blue-400">{currentAnalysis.confidence}%</p>
|
||||
{currentAnalysis.originalConfidence && currentAnalysis.originalConfidence !== currentAnalysis.confidence && (
|
||||
<p className="text-xs text-gray-500">
|
||||
(Original: {currentAnalysis.originalConfidence}%, Macro: {currentAnalysis.macroAdjustment?.netAdjustment > 0 ? '+' : ''}{currentAnalysis.macroAdjustment?.netAdjustment}%)
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="bg-gray-700/50 rounded p-3">
|
||||
<p className="text-gray-400 text-sm">Timeframes</p>
|
||||
@@ -1351,78 +1308,6 @@ export default function SafePaperTradingPage() {
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
{/* Macro Sentiment Panel */}
|
||||
{currentAnalysis.macroSentiment && (
|
||||
<div className="bg-gradient-to-r from-purple-900/30 to-blue-900/30 rounded p-4 mt-4 border border-purple-500/30">
|
||||
<h4 className="text-white font-medium mb-3 flex items-center">
|
||||
💰 Macro Sentiment Analysis
|
||||
{currentAnalysis.macroAdjustment?.applied && (
|
||||
<span className="ml-2 text-xs bg-purple-600 px-2 py-1 rounded">
|
||||
{currentAnalysis.macroAdjustment.netAdjustment > 0 ? '+' : ''}{currentAnalysis.macroAdjustment.netAdjustment}%
|
||||
</span>
|
||||
)}
|
||||
</h4>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{/* Fear & Greed Index */}
|
||||
<div className="bg-gray-800/50 rounded p-3">
|
||||
<p className="text-gray-400 text-xs">Fear & Greed Index</p>
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className={`text-lg font-bold ${
|
||||
currentAnalysis.macroSentiment.fearAndGreed?.value <= 25 ? 'text-red-400' :
|
||||
currentAnalysis.macroSentiment.fearAndGreed?.value <= 45 ? 'text-orange-400' :
|
||||
currentAnalysis.macroSentiment.fearAndGreed?.value >= 75 ? 'text-green-400' :
|
||||
currentAnalysis.macroSentiment.fearAndGreed?.value >= 55 ? 'text-yellow-400' :
|
||||
'text-gray-400'
|
||||
}`}>
|
||||
{currentAnalysis.macroSentiment.fearAndGreed?.value || 'N/A'}
|
||||
</span>
|
||||
<span className="text-xs text-gray-400">
|
||||
{currentAnalysis.macroSentiment.fearAndGreed?.classification || 'unknown'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* M2 Money Supply */}
|
||||
<div className="bg-gray-800/50 rounded p-3">
|
||||
<p className="text-gray-400 text-xs">M2 Money Supply</p>
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className={`text-sm font-bold ${
|
||||
currentAnalysis.macroSentiment.m2MoneySupply?.cryptoSignal?.signal === 'BULLISH' ? 'text-green-400' :
|
||||
currentAnalysis.macroSentiment.m2MoneySupply?.cryptoSignal?.signal === 'BEARISH' ? 'text-red-400' :
|
||||
'text-gray-400'
|
||||
}`}>
|
||||
{currentAnalysis.macroSentiment.m2MoneySupply?.cryptoSignal?.signal || 'N/A'}
|
||||
</span>
|
||||
<span className="text-xs text-gray-400">
|
||||
({currentAnalysis.macroSentiment.m2MoneySupply?.cryptoSignal?.confidence || 0}%)
|
||||
</span>
|
||||
</div>
|
||||
{currentAnalysis.macroSentiment.m2MoneySupply?.cryptoSignal?.timeframe && (
|
||||
<p className="text-xs text-purple-400 mt-1">
|
||||
{currentAnalysis.macroSentiment.m2MoneySupply.cryptoSignal.timeframe}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Macro Adjustments Applied */}
|
||||
{currentAnalysis.macroAdjustment?.applied && (
|
||||
<div className="mt-3 bg-gray-800/30 rounded p-2">
|
||||
<p className="text-xs text-gray-400 mb-1">Macro Adjustments Applied:</p>
|
||||
<ul className="text-xs text-gray-300 space-y-1">
|
||||
{currentAnalysis.macroAdjustment.adjustments.map((adjustment, index) => (
|
||||
<li key={index} className="flex items-start">
|
||||
<span className="text-purple-400 mr-1">•</span>
|
||||
{adjustment}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Toggle Detailed Analysis */}
|
||||
<button
|
||||
onClick={() => setShowDetailedAnalysis(!showDetailedAnalysis)}
|
||||
|
||||
Reference in New Issue
Block a user