Add last trade details to analytics dashboard

- Add getLastTrade() function to database service
- Create /api/analytics/last-trade endpoint
- Display last trade with full details on analytics page
- Show entry/exit prices, P&L, position size, targets
- Visual indicators for trade direction and exit reason
- Helps quickly diagnose where trades went (TP1, TP2, or SL)
This commit is contained in:
mindesbunister
2025-10-31 10:47:19 +01:00
parent 8a17c2cf90
commit aecdc108f6
3 changed files with 193 additions and 1 deletions

View File

@@ -272,6 +272,24 @@ export async function getLastTradeTime(): Promise<Date | null> {
}
}
/**
* Get the most recent trade with full details
*/
export async function getLastTrade() {
const prisma = getPrismaClient()
try {
const lastTrade = await prisma.trade.findFirst({
orderBy: { createdAt: 'desc' },
})
return lastTrade
} catch (error) {
console.error('❌ Failed to get last trade:', error)
return null
}
}
/**
* Get count of trades in the last hour
*/