mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-06 20:41:14 +08:00
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:
@@ -281,6 +281,19 @@ export interface BacktestRunsResponse {
|
||||
items: BacktestRunMetadata[];
|
||||
}
|
||||
|
||||
// Position status for real-time display during backtest
|
||||
export interface BacktestPositionStatus {
|
||||
symbol: string;
|
||||
side: string;
|
||||
quantity: number;
|
||||
entry_price: number;
|
||||
mark_price: number;
|
||||
leverage: number;
|
||||
unrealized_pnl: number;
|
||||
unrealized_pnl_pct: number;
|
||||
margin_used: number;
|
||||
}
|
||||
|
||||
export interface BacktestStatusPayload {
|
||||
run_id: string;
|
||||
state: string;
|
||||
@@ -291,6 +304,7 @@ export interface BacktestStatusPayload {
|
||||
equity: number;
|
||||
unrealized_pnl: number;
|
||||
realized_pnl: number;
|
||||
positions?: BacktestPositionStatus[];
|
||||
note?: string;
|
||||
last_error?: string;
|
||||
last_updated_iso: string;
|
||||
@@ -352,6 +366,7 @@ export interface BacktestMetrics {
|
||||
export interface BacktestStartConfig {
|
||||
run_id?: string;
|
||||
ai_model_id?: string;
|
||||
strategy_id?: string; // Optional: use saved strategy from Strategy Studio
|
||||
symbols: string[];
|
||||
timeframes: string[];
|
||||
decision_timeframe: string;
|
||||
@@ -385,6 +400,26 @@ export interface BacktestStartConfig {
|
||||
};
|
||||
}
|
||||
|
||||
// Kline data for backtest chart
|
||||
export interface BacktestKline {
|
||||
time: number;
|
||||
open: number;
|
||||
high: number;
|
||||
low: number;
|
||||
close: number;
|
||||
volume: number;
|
||||
}
|
||||
|
||||
export interface BacktestKlinesResponse {
|
||||
symbol: string;
|
||||
timeframe: string;
|
||||
start_ts: number;
|
||||
end_ts: number;
|
||||
count: number;
|
||||
klines: BacktestKline[];
|
||||
run_id: string;
|
||||
}
|
||||
|
||||
// Strategy Studio Types
|
||||
export interface Strategy {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user