more stuff

This commit is contained in:
Boki 2026-10-20 20:11:40 -04:00
parent c3cb36c8d6
commit 7dec0be3b4
26 changed files with 1394 additions and 275 deletions

View file

@ -2,7 +2,6 @@ import { Hono } from 'hono';
import type { IServiceContainer } from '@stock-bot/handlers';
import { getLogger } from '@stock-bot/logger';
import { BacktestServiceV2 } from '../services/backtest-v2.service';
import { getWebSocketHandler } from '../websocket/run-updates';
const logger = getLogger('backtests-v2-routes');
@ -90,7 +89,8 @@ export function createBacktestV2Routes(container: IServiceContainer) {
backtestId: c.req.param('backtestId'),
speedMultiplier: body.speedMultiplier,
});
return c.json(run, 201);
c.header('Location', `/api/v2/runs/${run.id}`);
return c.json(run, 202);
} catch (error) {
logger.error('Failed to create run', error);
return c.json({ error: 'Failed to create run' }, 500);
@ -146,7 +146,7 @@ export function createBacktestV2Routes(container: IServiceContainer) {
app.post('/api/v2/runs/:id/cancel', async c => {
try {
await backtestService.cancelRun(c.req.param('id'));
return c.json({ message: 'Run cancelled' });
return c.json({ message: 'Cancellation requested' }, 202);
} catch (error) {
logger.error('Failed to cancel run', error);
return c.json({ error: 'Failed to cancel run' }, 500);
@ -169,20 +169,18 @@ export function createBacktestV2Routes(container: IServiceContainer) {
try {
const runId = c.req.param('id');
const body = await c.req.json();
const { progress, currentDate } = body;
const { progress, currentDate, attemptId } = body;
if (typeof attemptId !== 'string') {
return c.json({ error: 'Execution attempt ID required' }, 400);
}
// Update run progress in database
await backtestService.updateRunProgress(runId, {
progress,
currentDate,
attemptId,
});
// Broadcast via WebSocket if handler is available
const wsHandler = getWebSocketHandler();
if (wsHandler) {
wsHandler.sendProgressUpdate(runId, progress, currentDate);
}
return c.json({ message: 'Progress updated' });
} catch (error) {
logger.error('Failed to update run progress', error);