mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-09 22:10:57 +08:00
fix: calculate pnl_pct in frontend when backend doesn't return it
Frontend now calculates total_pnl_pct from equity values if the backend doesn't return this field. This ensures the performance chart displays correctly regardless of backend version.
This commit is contained in:
@@ -38,7 +38,19 @@ export function ComparisonChart({ traders }: ComparisonChartProps) {
|
||||
const traderIds = traders.map((trader) => trader.trader_id)
|
||||
const batchData = await api.getEquityHistoryBatch(traderIds)
|
||||
return traders.map((trader) => {
|
||||
return batchData.histories[trader.trader_id] || []
|
||||
const history = batchData.histories?.[trader.trader_id] || []
|
||||
|
||||
// If backend doesn't return total_pnl_pct, calculate it from equity
|
||||
if (history.length > 0 && history[0].total_pnl_pct === undefined) {
|
||||
const initialEquity = history[0].total_equity
|
||||
history.forEach((point: any) => {
|
||||
point.total_pnl_pct = initialEquity > 0
|
||||
? ((point.total_equity - initialEquity) / initialEquity) * 100
|
||||
: 0
|
||||
})
|
||||
}
|
||||
|
||||
return history
|
||||
})
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user