Fix automated trading display calculations
Fixed position size calculation: 00 investment now shows 00 position (was 04.76) Fixed token amount display: Now shows correct tokens (~0.996) for 00 investment (was 2.04) Corrected API route: /api/automation/analysis-details now returns 200 instead of 405 Technical changes: - Updated route calculation logic: tradingAmount / trade.price for correct token amounts - Fixed displayPositionSize to show intended investment amount - Used Docker Compose v2 for container management - Resolved Next.js module export issues The API now correctly displays trade details matching user investment intentions.
This commit is contained in:
@@ -223,8 +223,8 @@ export default function AutomationPage() {
|
||||
const calculateTotalPnL = () => {
|
||||
if (!recentTrades.length) return 0
|
||||
return recentTrades
|
||||
.filter(t => t.status === 'COMPLETED' && t.realizedPnl)
|
||||
.reduce((total, trade) => total + parseFloat(trade.realizedPnl), 0)
|
||||
.filter(t => t.status === 'COMPLETED' && t.pnl)
|
||||
.reduce((total, trade) => total + parseFloat(trade.pnl), 0)
|
||||
.toFixed(2)
|
||||
}
|
||||
|
||||
@@ -645,8 +645,8 @@ export default function AutomationPage() {
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-white font-semibold">${trade.entryPrice.toFixed(2)}</div>
|
||||
<div className="text-sm text-gray-400">{trade.confidence}% confidence</div>
|
||||
<div className="text-white font-semibold">${trade.entryPrice?.toFixed(2) || trade.price?.toFixed(2) || '0.00'}</div>
|
||||
<div className="text-sm text-gray-400">{trade.confidence || 0}% confidence</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -688,7 +688,7 @@ export default function AutomationPage() {
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">{trade.isActive ? 'Current' : 'Exit'} Price:</span>
|
||||
<span className="text-white">
|
||||
${trade.isActive ? trade.currentPrice?.toFixed(2) : trade.exitPrice?.toFixed(2)}
|
||||
${trade.isActive ? (trade.currentPrice?.toFixed(2) || '0.00') : (trade.exitPrice?.toFixed(2) || '0.00')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -927,6 +927,106 @@ export default function AutomationPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Multi-Timeframe Analysis Results */}
|
||||
{analysisDetails?.analysis?.multiTimeframeResults && analysisDetails.analysis.multiTimeframeResults.length > 0 && (
|
||||
<div className="space-y-6">
|
||||
<h2 className="text-2xl font-bold text-white">📊 Multi-Timeframe Analysis</h2>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{analysisDetails.analysis.multiTimeframeResults.map((result, index) => (
|
||||
<div key={result.timeframe} className="card card-gradient p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-bold text-white flex items-center">
|
||||
{result.analysisComplete ? (
|
||||
<span className="text-green-400 mr-2">✅</span>
|
||||
) : (
|
||||
<span className="text-yellow-400 mr-2">⏳</span>
|
||||
)}
|
||||
{result.timeframe} Timeframe
|
||||
</h3>
|
||||
<span className={`text-xs px-2 py-1 rounded ${
|
||||
result.analysisComplete ? 'bg-green-600 text-white' : 'bg-yellow-600 text-white'
|
||||
}`}>
|
||||
{result.analysisComplete ? 'Complete' : 'In Progress'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Decision:</span>
|
||||
<span className={`font-bold px-2 py-1 rounded text-sm ${
|
||||
result.decision === 'BUY' ? 'bg-green-600 text-white' :
|
||||
result.decision === 'SELL' ? 'bg-red-600 text-white' :
|
||||
'bg-gray-600 text-white'
|
||||
}`}>
|
||||
{result.decision}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Confidence:</span>
|
||||
<span className={`font-semibold ${
|
||||
result.confidence > 80 ? 'text-green-400' :
|
||||
result.confidence > 60 ? 'text-yellow-400' :
|
||||
'text-red-400'
|
||||
}`}>
|
||||
{result.confidence}%
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Sentiment:</span>
|
||||
<span className={`font-semibold ${
|
||||
result.sentiment === 'BULLISH' ? 'text-green-400' :
|
||||
result.sentiment === 'BEARISH' ? 'text-red-400' :
|
||||
'text-gray-400'
|
||||
}`}>
|
||||
{result.sentiment}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{result.createdAt && (
|
||||
<div className="mt-4 pt-3 border-t border-gray-700">
|
||||
<div className="text-xs text-gray-500">
|
||||
Analyzed: {new Date(result.createdAt).toLocaleString()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Multi-Timeframe Summary */}
|
||||
<div className="card card-gradient p-6">
|
||||
<h3 className="text-lg font-bold text-white mb-4">📈 Cross-Timeframe Consensus</h3>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-blue-400">
|
||||
{analysisDetails.analysis.multiTimeframeResults.length}
|
||||
</div>
|
||||
<div className="text-sm text-gray-400">Timeframes Analyzed</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-green-400">
|
||||
{analysisDetails.analysis.multiTimeframeResults.filter(r => r.analysisComplete).length}
|
||||
</div>
|
||||
<div className="text-sm text-gray-400">Completed</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-yellow-400">
|
||||
{Math.round(
|
||||
analysisDetails.analysis.multiTimeframeResults.reduce((sum, r) => sum + r.confidence, 0) /
|
||||
analysisDetails.analysis.multiTimeframeResults.length
|
||||
)}%
|
||||
</div>
|
||||
<div className="text-sm text-gray-400">Avg Confidence</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* No Analysis Available */}
|
||||
{!analysisDetails?.analysis && status?.isActive && (
|
||||
<div className="card card-gradient p-6">
|
||||
@@ -950,13 +1050,13 @@ export default function AutomationPage() {
|
||||
<span className={`px-3 py-1 rounded text-sm font-semibold ${
|
||||
selectedTrade.side === 'BUY' ? 'bg-green-600 text-white' : 'bg-red-600 text-white'
|
||||
}`}>
|
||||
{selectedTrade.side} {selectedTrade.amount} @ ${selectedTrade.price.toFixed(2)}
|
||||
{selectedTrade.side} {selectedTrade.amount} @ ${selectedTrade.price?.toFixed(2) || '0.00'}
|
||||
</span>
|
||||
<span className={`px-2 py-1 rounded text-xs ${
|
||||
selectedTrade.status === 'OPEN' ? 'bg-blue-600 text-white' :
|
||||
selectedTrade.profit > 0 ? 'bg-green-600 text-white' : 'bg-red-600 text-white'
|
||||
(selectedTrade.profit || 0) > 0 ? 'bg-green-600 text-white' : 'bg-red-600 text-white'
|
||||
}`}>
|
||||
{selectedTrade.status} {selectedTrade.profit && `(${selectedTrade.profit > 0 ? '+' : ''}$${selectedTrade.profit.toFixed(2)})`}
|
||||
{selectedTrade.status} {selectedTrade.profit && `(${selectedTrade.profit > 0 ? '+' : ''}$${selectedTrade.profit?.toFixed(2) || '0.00'})`}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user