messy work. backtests / mock-data

This commit is contained in:
Boki 2025-07-03 08:37:23 -04:00
parent 4e4a048988
commit fa70ada2bb
51 changed files with 2576 additions and 887 deletions

View file

@ -1,9 +1,10 @@
import { logger } from '@stock-bot/logger';
import { EventEmitter } from 'events';
import { v4 as uuidv4 } from 'uuid';
import { IServiceContainer } from '@stock-bot/di';
import { ModeConfig, OrderRequest, OrderRequestSchema } from '../types';
import { TradingEngine } from '../../core';
import { TradingEngine } from '@stock-bot/core';
import axios from 'axios';
import { StorageService } from './StorageService';
interface ExecutionReport {
orderId: string;
@ -29,9 +30,13 @@ export class ExecutionService extends EventEmitter {
private tradingEngine: TradingEngine | null = null;
private brokerClient: any = null; // Would be specific broker API client
private pendingOrders = new Map<string, OrderRequest>();
private container: IServiceContainer;
private storageService: StorageService;
constructor(private modeManager: any) {
constructor(container: IServiceContainer, storageService: StorageService) {
super();
this.container = container;
this.storageService = storageService;
}
async initialize(config: ModeConfig, tradingEngine: TradingEngine): Promise<void> {
@ -47,7 +52,7 @@ export class ExecutionService extends EventEmitter {
private async initializeBroker(broker: string, accountId: string): Promise<void> {
// In real implementation, would initialize specific broker API
// For example: Alpaca, Interactive Brokers, etc.
logger.info(`Initializing ${broker} broker connection for account ${accountId}`);
this.container.logger.info(`Initializing ${broker} broker connection for account ${accountId}`);
}
async submitOrder(orderRequest: OrderRequest): Promise<ExecutionReport> {
@ -97,7 +102,7 @@ export class ExecutionService extends EventEmitter {
return result;
} catch (error) {
logger.error('Error submitting order:', error);
this.container.logger.error('Error submitting order:', error);
return this.createRejectionReport(
orderId,
clientOrderId,
@ -171,7 +176,7 @@ export class ExecutionService extends EventEmitter {
): Promise<ExecutionReport> {
// In real implementation, would submit to actual broker
// This is a placeholder
logger.info(`Submitting order ${orderId} to broker`);
this.container.logger.info(`Submitting order ${orderId} to broker`);
// Simulate broker response
return {
@ -189,7 +194,7 @@ export class ExecutionService extends EventEmitter {
async cancelOrder(orderId: string): Promise<boolean> {
const order = this.pendingOrders.get(orderId);
if (!order) {
logger.warn(`Order ${orderId} not found`);
this.container.logger.warn(`Order ${orderId} not found`);
return false;
}
@ -222,7 +227,7 @@ export class ExecutionService extends EventEmitter {
return true;
} catch (error) {
logger.error(`Error cancelling order ${orderId}:`, error);
this.container.logger.error(`Error cancelling order ${orderId}:`, error);
return false;
}
}
@ -286,7 +291,7 @@ export class ExecutionService extends EventEmitter {
async routeOrderToExchange(order: OrderRequest, exchange: string): Promise<void> {
// This would route orders to specific exchanges in live mode
// For now, just a placeholder
logger.info(`Routing order to ${exchange}:`, order);
this.container.logger.info(`Routing order to ${exchange}:`, order);
}
async getOrderStatus(orderId: string): Promise<ExecutionReport | null> {