initial backtests

This commit is contained in:
Boki 2025-07-03 09:07:45 -04:00
parent fa70ada2bb
commit 5a3a23a2ba
6 changed files with 400 additions and 129 deletions

View file

@ -82,15 +82,22 @@ export class BacktestService {
const result = await response.json();
// Store result when available
if (result.performance) {
// Backtest completed immediately
// Store result directly without transformation
if (result.status === 'completed') {
backtest.status = 'completed';
backtest.updatedAt = new Date();
backtestStore.set(backtestId, backtest);
backtestResults.set(backtestId, result);
logger.info('Backtest completed', {
backtestId,
trades: result.metrics?.totalTrades,
return: result.metrics?.totalReturn
});
} else {
// Update status to running if not completed
backtest.status = 'running';
backtest.updatedAt = new Date();
backtestStore.set(backtestId, backtest);
}
@ -109,35 +116,8 @@ export class BacktestService {
}
async getBacktestResults(id: string): Promise<any> {
const results = backtestResults.get(id);
if (!results) return null;
// Transform orchestrator response to frontend expected format
return {
backtestId: results.id || id,
metrics: {
totalReturn: results.performance?.totalReturn || 0,
sharpeRatio: results.performance?.sharpeRatio || 0,
maxDrawdown: results.performance?.maxDrawdown || 0,
winRate: results.performance?.winRate || 0,
totalTrades: results.performance?.totalTrades || 0,
profitFactor: results.performance?.profitFactor
},
equity: results.equityCurve?.map((point: any) => ({
date: new Date(point.timestamp).toISOString(),
value: point.value
})) || [],
trades: results.trades?.map((trade: any) => ({
symbol: trade.symbol,
entryDate: new Date(trade.entryTime).toISOString(),
exitDate: new Date(trade.exitTime).toISOString(),
entryPrice: trade.entryPrice,
exitPrice: trade.exitPrice,
quantity: trade.quantity,
pnl: trade.pnl
})) || [],
ohlcData: results.ohlcData || {}
};
// Return results directly without any transformation
return backtestResults.get(id) || null;
}
async listBacktests(params: { limit: number; offset: number }): Promise<BacktestJob[]> {