Files
trading_bot_v4/app/api/analytics/last-trade/route.ts
mindesbunister 3c79ecbe55 Display signal quality score on analytics dashboard
- Add signalQualityScore to LastTrade interface
- Display quality score badge in last trade section (0-100)
- Color-coded: green (80+), yellow (70-79), orange (60-69)
- Shows 'Excellent', 'Good', or 'Marginal' label
- Gracefully handles null values (old trades without scores)
- Better layout when quality score is present
2025-10-31 11:34:46 +01:00

52 lines
1.4 KiB
TypeScript

/**
* Last Trade API Endpoint
*
* Returns details of the most recent trade
*/
import { NextResponse } from 'next/server'
import { getLastTrade } from '@/lib/database/trades'
export async function GET() {
try {
const trade = await getLastTrade()
if (!trade) {
return NextResponse.json({
trade: null,
})
}
// Format the trade data for the frontend
const formattedTrade = {
id: trade.id,
symbol: trade.symbol,
direction: trade.direction,
entryPrice: trade.entryPrice,
entryTime: trade.entryTime.toISOString(),
exitPrice: trade.exitPrice || undefined,
exitTime: trade.exitTime?.toISOString() || undefined,
exitReason: trade.exitReason || undefined,
realizedPnL: trade.realizedPnL || undefined,
realizedPnLPercent: trade.realizedPnLPercent || undefined,
positionSizeUSD: trade.positionSizeUSD,
leverage: trade.leverage,
stopLossPrice: trade.stopLossPrice,
takeProfit1Price: trade.takeProfit1Price,
takeProfit2Price: trade.takeProfit2Price,
isTestTrade: trade.isTestTrade || false,
signalQualityScore: trade.signalQualityScore || undefined,
}
return NextResponse.json({
trade: formattedTrade,
})
} catch (error) {
console.error('Failed to fetch last trade:', error)
return NextResponse.json(
{ error: 'Failed to fetch last trade' },
{ status: 500 }
)
}
}