import { Order, OrderResult, OrderStatus } from '@stock-bot/types'; export interface BrokerInterface { /** * Execute an order with the broker */ executeOrder(order: Order): Promise; /** * Get order status from broker */ getOrderStatus(orderId: string): Promise; /** * Cancel an order */ cancelOrder(orderId: string): Promise; /** * Get current positions */ getPositions(): Promise; /** * Get account balance */ getAccountBalance(): Promise; } export interface Position { symbol: string; quantity: number; averagePrice: number; currentPrice: number; unrealizedPnL: number; side: 'long' | 'short'; } export interface AccountBalance { totalValue: number; availableCash: number; buyingPower: number; marginUsed: number; } export class MockBroker implements BrokerInterface { private orders: Map = new Map(); private positions: Position[] = []; async executeOrder(order: Order): Promise { const orderId = `mock_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; const result: OrderResult = { orderId, symbol: order.symbol, quantity: order.quantity, side: order.side, status: 'filled', executedPrice: order.price || 100, // Mock price executedAt: new Date(), commission: 1.0, }; this.orders.set(orderId, result); return result; } async getOrderStatus(orderId: string): Promise { const order = this.orders.get(orderId); return order?.status || 'unknown'; } async cancelOrder(orderId: string): Promise { const order = this.orders.get(orderId); if (order && order.status === 'pending') { order.status = 'cancelled'; return true; } return false; } async getPositions(): Promise { return this.positions; } async getAccountBalance(): Promise { return { totalValue: 100000, availableCash: 50000, buyingPower: 200000, marginUsed: 0, }; } }