This commit is contained in:
Boki 2026-10-22 09:46:29 -04:00
parent e4925ecdfe
commit b7aeca4888
20 changed files with 490 additions and 248 deletions

View file

@ -5,12 +5,13 @@ import { ModeManager } from '../../apps/stock/orchestrator/src/core/ModeManager'
import { ExecutionConflictError } from '../../apps/stock/orchestrator/src/execution/repository';
import type { ExecutionService } from '../../apps/stock/orchestrator/src/services/ExecutionService';
import { MarketDataService } from '../../apps/stock/orchestrator/src/services/MarketDataService';
import { StorageService } from '../../apps/stock/orchestrator/src/services/StorageService';
import {
BaseStrategy,
type Signal,
} from '../../apps/stock/orchestrator/src/strategies/BaseStrategy';
import { StrategyManager } from '../../apps/stock/orchestrator/src/strategies/StrategyManager';
import type { MarketData, OrchestratorServices } from '../../apps/stock/orchestrator/src/types';
import type { MarketData } from '../../apps/stock/orchestrator/src/types';
import { config, logger, makeExecution, order, quote, start } from '../fixtures/execution';
const cleanup: (() => Promise<void>)[] = [];
@ -173,7 +174,14 @@ describe('one simulation execution gateway', () => {
};
await expect(execution.initialize(live, engine)).rejects.toThrow('Live trading is disabled');
expect((await execution.getAccount()).cash).toBe(10000);
const mode = new ModeManager({ logger }, {} as never, execution, {} as never);
const lifecycle = { initialize: async () => {}, shutdown: async () => {} };
const mode = new ModeManager({
logger,
marketData: lifecycle,
execution,
storage: lifecycle,
strategies: { restoreStrategies: async () => {}, shutdown: async () => {} },
});
await expect(mode.initializeMode(live)).rejects.toThrow('Live trading is disabled');
expect(() => new TradingEngine('live', { broker: 'none', accountId: 'none' })).toThrow(
'Live trading is disabled'
@ -197,11 +205,17 @@ describe('one simulation execution gateway', () => {
protected async onStop() {}
protected onConfigUpdate() {}
}
const services: OrchestratorServices = { logger, custom: { ExecutionService: execution } };
const market = new MarketDataService(services);
services.custom!.MarketDataService = market;
const manager = new StrategyManager(services);
services.custom!.StrategyManager = manager;
const market: MarketDataService = new MarketDataService({
logger,
storage: new StorageService({ logger }, null, null, null),
drainStrategies: () => manager.drain(),
});
const manager: StrategyManager = new StrategyManager({
logger,
execution,
marketData: market,
createStrategy: config => new Strategy(config, {} as ModeManager, execution),
});
manager.setupEventListeners();
manager.setupEventListeners();
const strategy = new Strategy(