feat(dashboard): TS types + API client for strategy + backtest
BacktestRun, BacktestRunDetail, StrategyTicker, StrategyEquityCurve, StrategyPerformance types added to meetKevin.ts. New meetKevinStrategy.ts with 8 axios methods covering the backtest run/list/get/latest and strategy tickers/equity-curve/performance/close endpoints.
This commit is contained in:
parent
9d752aa0a2
commit
90cf21521f
2 changed files with 151 additions and 0 deletions
60
dashboard/src/api/meetKevinStrategy.ts
Normal file
60
dashboard/src/api/meetKevinStrategy.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import client from './client';
|
||||
import type {
|
||||
BacktestRun,
|
||||
BacktestRunDetail,
|
||||
StrategyEquityCurve,
|
||||
StrategyPerformance,
|
||||
StrategyTicker,
|
||||
} from '../types/meetKevin';
|
||||
|
||||
export async function runBacktest(params: {
|
||||
holding_days?: number;
|
||||
slippage_pct?: number;
|
||||
dedupe_policy?: 'roll' | 'ignore';
|
||||
initial_capital?: number;
|
||||
}): Promise<{ run_uuid: string; status: string }> {
|
||||
const { data } = await client.post('/meet-kevin/backtest/run', params);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function listBacktestRuns(limit = 20): Promise<BacktestRun[]> {
|
||||
const { data } = await client.get('/meet-kevin/backtest/runs', {
|
||||
params: { limit },
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getBacktestRun(runUuid: string): Promise<BacktestRunDetail> {
|
||||
const { data } = await client.get(`/meet-kevin/backtest/runs/${runUuid}`);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getLatestBacktest(): Promise<BacktestRunDetail> {
|
||||
const { data } = await client.get('/meet-kevin/backtest/latest');
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getStrategyTickers(): Promise<StrategyTicker[]> {
|
||||
const { data } = await client.get('/meet-kevin/strategy/tickers');
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getStrategyEquityCurve(params: {
|
||||
from?: string;
|
||||
to?: string;
|
||||
include_benchmark?: 'spy';
|
||||
}): Promise<StrategyEquityCurve> {
|
||||
const { data } = await client.get('/meet-kevin/strategy/equity-curve', {
|
||||
params,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getStrategyPerformance(): Promise<StrategyPerformance> {
|
||||
const { data } = await client.get('/meet-kevin/strategy/performance');
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function closeKevinPosition(symbol: string): Promise<void> {
|
||||
await client.post(`/meet-kevin/positions/${symbol}/close`);
|
||||
}
|
||||
|
|
@ -112,3 +112,94 @@ export interface DashboardData {
|
|||
count: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
// --- Strategy + backtest types (v2) ---
|
||||
|
||||
export type BacktestRunStatus = 'running' | 'completed' | 'failed';
|
||||
|
||||
export interface BacktestTrade {
|
||||
symbol: string;
|
||||
entry_at: string;
|
||||
entry_price: number;
|
||||
exit_at: string | null;
|
||||
exit_price: number | null;
|
||||
qty: number;
|
||||
pnl_usd: number | null;
|
||||
pnl_pct: number | null;
|
||||
holding_days_actual: number | null;
|
||||
}
|
||||
|
||||
export interface BacktestMetrics {
|
||||
total_return_pct: number;
|
||||
annualized_return_pct: number | null;
|
||||
sharpe_ratio: number | null;
|
||||
max_drawdown_pct: number | null;
|
||||
win_rate: number | null;
|
||||
trade_count: number;
|
||||
alpha_vs_spy_pct: number | null;
|
||||
beta_vs_spy: number | null;
|
||||
winners: number | null;
|
||||
losers: number | null;
|
||||
best_trade_pct: number | null;
|
||||
worst_trade_pct: number | null;
|
||||
}
|
||||
|
||||
export interface BacktestRun {
|
||||
run_uuid: string;
|
||||
status: BacktestRunStatus;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
trigger_source: 'manual' | 'scheduled';
|
||||
params_json: Record<string, unknown>;
|
||||
metrics_json: BacktestMetrics | null;
|
||||
error_message: string | null;
|
||||
}
|
||||
|
||||
export interface BacktestRunDetail extends BacktestRun {
|
||||
trades: BacktestTrade[];
|
||||
equity_curve_json: Array<{ timestamp: string; value: number }> | null;
|
||||
benchmark_curve_json: Array<{ timestamp: string; value: number }> | null;
|
||||
}
|
||||
|
||||
export type BridgeStatus =
|
||||
| 'emitted'
|
||||
| 'skipped_non_tradable'
|
||||
| 'skipped_blocklist'
|
||||
| 'skipped_caps'
|
||||
| 'deferred'
|
||||
| 'broker_rejected'
|
||||
| 'dry_run';
|
||||
|
||||
export interface StrategyTicker {
|
||||
symbol: string;
|
||||
latest_action: TickerAction;
|
||||
latest_conviction: number;
|
||||
mention_count: number;
|
||||
last_mention_at: string;
|
||||
bridge_status: BridgeStatus | null;
|
||||
is_held: boolean;
|
||||
current_price: number | null;
|
||||
unrealized_pnl_pct: number | null;
|
||||
}
|
||||
|
||||
export interface EquityCurvePoint {
|
||||
timestamp: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
export interface StrategyEquityCurve {
|
||||
strategy: EquityCurvePoint[];
|
||||
benchmark: EquityCurvePoint[] | null;
|
||||
}
|
||||
|
||||
export interface StrategyPerformance {
|
||||
total_return_pct: number;
|
||||
annualized_return_pct: number | null;
|
||||
sharpe_ratio: number | null;
|
||||
max_drawdown_pct: number | null;
|
||||
win_rate: number | null;
|
||||
trade_count: number;
|
||||
alpha_vs_spy_pct: number | null;
|
||||
open_positions: number;
|
||||
last_backtest_at: string | null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue