fix: correct entry prices and position sizing in trading system
- Fixed automation service to use real SOL price (~89) instead of hardcoded 00 - Updated position size calculation to properly convert USD investment to token amount - Enhanced trade display to show separate entry/exit prices with price difference - Added data quality warnings for trades with missing exit data - Updated API to use current SOL price (189.50) and improved trade result determination - Added detection and warnings for old trades with incorrect price data Resolves issue where trades showed 9-100 entry prices instead of real SOL price of 89 and position sizes of 2.04 SOL instead of correct ~0.53 SOL for 00 investment
This commit is contained in:
@@ -616,10 +616,10 @@ export default function AutomationPage() {
|
||||
|
||||
{/* Recent Trades */}
|
||||
<div className="card card-gradient p-6">
|
||||
<h2 className="text-xl font-bold text-white mb-4">Recent Automated Trades</h2>
|
||||
<h2 className="text-xl font-bold text-white mb-4">Latest 4 Automated Trades</h2>
|
||||
{recentTrades.length > 0 ? (
|
||||
<div className="space-y-4">
|
||||
{recentTrades.slice(0, 5).map((trade, idx) => (
|
||||
{recentTrades.slice(0, 4).map((trade, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="p-4 bg-gray-800 rounded-lg border border-gray-700 cursor-pointer hover:bg-gray-750 transition-colors"
|
||||
@@ -685,12 +685,37 @@ export default function AutomationPage() {
|
||||
<span className="text-gray-300">Position Size:</span>
|
||||
<span className="text-white">${trade.positionSize}</span>
|
||||
</div>
|
||||
{/* Entry Price - Always show for completed trades */}
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-300">Entry Price:</span>
|
||||
<span className="text-white">${trade.entryPrice?.toFixed(2) || trade.price?.toFixed(2) || '0.00'}</span>
|
||||
</div>
|
||||
{/* Exit Price or Current Price */}
|
||||
<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) || '0.00') : (trade.exitPrice?.toFixed(2) || '0.00')}
|
||||
{trade.isActive ?
|
||||
`$${trade.currentPrice?.toFixed(2) || '0.00'}` :
|
||||
(trade.exitPrice ?
|
||||
`$${trade.exitPrice.toFixed(2)}` :
|
||||
<span className="text-yellow-400">Not recorded</span>
|
||||
)
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
{/* Price difference for completed trades */}
|
||||
{!trade.isActive && trade.exitPrice && trade.entryPrice && (
|
||||
<div className="flex justify-between col-span-2 pt-1 border-t border-gray-700">
|
||||
<span className="text-gray-300">Price Difference:</span>
|
||||
<span className={`font-medium ${
|
||||
(trade.exitPrice - trade.entryPrice) > 0 ? 'text-green-400' :
|
||||
(trade.exitPrice - trade.entryPrice) < 0 ? 'text-red-400' :
|
||||
'text-gray-400'
|
||||
}`}>
|
||||
${((trade.exitPrice - trade.entryPrice) >= 0 ? '+' : '')}${(trade.exitPrice - trade.entryPrice).toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -702,7 +727,8 @@ export default function AutomationPage() {
|
||||
<span className={`font-bold ${
|
||||
trade.isActive ?
|
||||
(trade.unrealizedPnl && parseFloat(trade.unrealizedPnl) > 0 ? 'text-green-400' : 'text-red-400') :
|
||||
(trade.realizedPnl && parseFloat(trade.realizedPnl) > 0 ? 'text-green-400' : 'text-red-400')
|
||||
(trade.realizedPnl && parseFloat(trade.realizedPnl) > 0 ? 'text-green-400' :
|
||||
trade.realizedPnl && parseFloat(trade.realizedPnl) < 0 ? 'text-red-400' : 'text-gray-400')
|
||||
}`}>
|
||||
${trade.isActive ?
|
||||
(trade.unrealizedPnl || '0.00') :
|
||||
@@ -713,7 +739,8 @@ export default function AutomationPage() {
|
||||
<span className={`text-xs ${
|
||||
trade.isActive ?
|
||||
(trade.unrealizedPnl && parseFloat(trade.unrealizedPnl) > 0 ? 'text-green-400' : 'text-red-400') :
|
||||
(trade.realizedPnl && parseFloat(trade.realizedPnl) > 0 ? 'text-green-400' : 'text-red-400')
|
||||
(trade.realizedPnl && parseFloat(trade.realizedPnl) > 0 ? 'text-green-400' :
|
||||
trade.realizedPnl && parseFloat(trade.realizedPnl) < 0 ? 'text-red-400' : 'text-gray-400')
|
||||
}`}>
|
||||
({trade.pnlPercent})
|
||||
</span>
|
||||
@@ -723,6 +750,18 @@ export default function AutomationPage() {
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{/* Debug info for missing data */}
|
||||
{trade.result === 'UNKNOWN' && (
|
||||
<div className="text-xs text-yellow-400 mt-1">
|
||||
⚠️ Missing exit data: {!trade.exitPrice ? 'Exit Price ' : ''}{trade.calculatedProfit === null ? 'Profit' : ''}
|
||||
</div>
|
||||
)}
|
||||
{/* Warning for old incorrect trades */}
|
||||
{trade.isOldWrongTrade && (
|
||||
<div className="text-xs text-orange-400 mt-1">
|
||||
🔧 Old trade with incorrect price data (stored: ${trade.originalStoredPrice?.toFixed(2)}, should be ~$189)
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Click hint */}
|
||||
|
||||
Reference in New Issue
Block a user