feat: enhance backtest with real-time positions, P&L fixes, and strategy integration

- Add real-time position display with unrealized P&L during backtest
- Fix P&L calculation by tracking accumulated opening fees
- Add strategy coin source resolution (AI500, OI Top, mixed)
- Infer AI provider from model name for better compatibility
- Cap position size to available margin to prevent insufficient cash errors
- Fix trade markers on K-line chart (long/short instead of buy/sell)
- Add QuantData and OI ranking to backtest decision context
This commit is contained in:
tinkle-community
2025-12-20 01:10:11 +08:00
parent 5534861fe5
commit e2d702c662
9 changed files with 1144 additions and 62 deletions

View File

@@ -20,6 +20,7 @@ import type {
BacktestTradeEvent,
BacktestMetrics,
BacktestRunMetadata,
BacktestKlinesResponse,
Strategy,
StrategyConfig,
DebateSession,
@@ -580,6 +581,19 @@ export const api = {
return handleJSONResponse<BacktestMetrics>(res)
},
async getBacktestKlines(
runId: string,
symbol: string,
timeframe?: string
): Promise<BacktestKlinesResponse> {
const query = new URLSearchParams({ run_id: runId, symbol })
if (timeframe) query.set('timeframe', timeframe)
const res = await fetch(`${API_BASE}/backtest/klines?${query}`, {
headers: getAuthHeaders(),
})
return handleJSONResponse<BacktestKlinesResponse>(res)
},
async getBacktestTrace(
runId: string,
cycle?: number