cleanup
This commit is contained in:
parent
e4925ecdfe
commit
b7aeca4888
20 changed files with 490 additions and 248 deletions
|
|
@ -143,15 +143,7 @@ async function fixture() {
|
|||
});
|
||||
},
|
||||
} as unknown as StorageService;
|
||||
const engine = new RustBacktestAdapter(
|
||||
{
|
||||
logger,
|
||||
custom: {
|
||||
StorageService: storage,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 5_000 }
|
||||
);
|
||||
const engine = new RustBacktestAdapter({ logger, storage }, { timeoutMs: 5_000 });
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
|
|
|
|||
|
|
@ -11,10 +11,16 @@ import type { ExecutionRepository } from '../../apps/stock/orchestrator/src/exec
|
|||
import { 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 { createBuiltinStrategyRegistry } from '../../apps/stock/orchestrator/src/strategies/builtin-strategies';
|
||||
import { StrategyManager } from '../../apps/stock/orchestrator/src/strategies/StrategyManager';
|
||||
import type { OrchestratorServices } from '../../apps/stock/orchestrator/src/types';
|
||||
import { logger, makeExecution, quote, start } from '../fixtures/execution';
|
||||
import { attachCounter, CounterStrategy, recoveryConfig } from '../fixtures/strategy-recovery';
|
||||
import {
|
||||
attachCounter,
|
||||
CounterStrategy,
|
||||
makeStrategyManager,
|
||||
recoveryConfig,
|
||||
} from '../fixtures/strategy-recovery';
|
||||
|
||||
const url = process.env.PIPELINE_TEST_DATABASE_URL;
|
||||
const cleanup: (() => Promise<void>)[] = [];
|
||||
|
|
@ -89,18 +95,15 @@ describe.skipIf(!url)('strategy recovery on real PostgreSQL', () => {
|
|||
name: 'sma-crossover',
|
||||
parameters: { initialCapital: 10000 },
|
||||
};
|
||||
const prior = new StrategyManager({
|
||||
logger,
|
||||
custom: {
|
||||
ExecutionService: original.execution,
|
||||
ModeManager: { getTradingEngine: () => original.engine } as ModeManager,
|
||||
},
|
||||
const prior = makeStrategyManager({
|
||||
execution: original.execution,
|
||||
modeManager: { getTradingEngine: () => original.engine } as ModeManager,
|
||||
});
|
||||
await prior.initializeStrategies([config]);
|
||||
await prior.onMarketData(quote('one'));
|
||||
await prior.shutdown();
|
||||
await original.execution.enqueueMarketData(quote('two', 100, 100, start + 1));
|
||||
const services: OrchestratorServices = { logger, postgres: f.postgres, custom: {} };
|
||||
const services: OrchestratorServices = { logger, postgres: f.postgres };
|
||||
const storage = new StorageService(services, null, f.postgres, null);
|
||||
const execution = new ExecutionService(services, storage, { clock: f.getTime });
|
||||
let feedStarted = false;
|
||||
|
|
@ -111,15 +114,24 @@ describe.skipIf(!url)('strategy recovery on real PostgreSQL', () => {
|
|||
expect((await execution.getRecoveryStatus()).strategies[0]?.lag).toBe(0);
|
||||
}
|
||||
}
|
||||
const market = new OfflineMarket(services);
|
||||
const manager = new StrategyManager(services),
|
||||
mode = new ModeManager(services, market, execution, storage);
|
||||
Object.assign(services.custom!, {
|
||||
StorageService: storage,
|
||||
ExecutionService: execution,
|
||||
MarketDataService: market,
|
||||
StrategyManager: manager,
|
||||
ModeManager: mode,
|
||||
const market: MarketDataService = new OfflineMarket({
|
||||
logger,
|
||||
storage,
|
||||
drainStrategies: () => manager.drain(),
|
||||
});
|
||||
const registry = createBuiltinStrategyRegistry();
|
||||
const manager: StrategyManager = new StrategyManager({
|
||||
logger,
|
||||
execution,
|
||||
marketData: market,
|
||||
createStrategy: config => registry.create(config, { execution, modeManager: mode }),
|
||||
});
|
||||
const mode: ModeManager = new ModeManager({
|
||||
logger,
|
||||
marketData: market,
|
||||
execution,
|
||||
storage,
|
||||
strategies: manager,
|
||||
});
|
||||
cleanup.push(() => mode.shutdown());
|
||||
await mode.initializeMode({
|
||||
|
|
@ -274,14 +286,10 @@ describe.skipIf(!url)('strategy recovery on real PostgreSQL', () => {
|
|||
};
|
||||
const makeManager = async (account: string) => {
|
||||
const runtime = await f.make(account);
|
||||
const services = {
|
||||
logger,
|
||||
custom: {
|
||||
ExecutionService: runtime.execution,
|
||||
ModeManager: { getTradingEngine: () => runtime.engine } as ModeManager,
|
||||
},
|
||||
};
|
||||
const manager = new StrategyManager(services);
|
||||
const manager = makeStrategyManager({
|
||||
execution: runtime.execution,
|
||||
modeManager: { getTradingEngine: () => runtime.engine } as ModeManager,
|
||||
});
|
||||
await manager.initializeStrategies([smaConfig]);
|
||||
cleanup.push(() => manager.shutdown());
|
||||
return { ...runtime, manager };
|
||||
|
|
@ -340,12 +348,9 @@ describe.skipIf(!url)('strategy recovery on real PostgreSQL', () => {
|
|||
test('uncheckpointed ML paper strategies fail before model startup and migration replay preserves history', async () => {
|
||||
const f = await fixture();
|
||||
const { execution, engine } = await f.make();
|
||||
const manager = new StrategyManager({
|
||||
logger,
|
||||
custom: {
|
||||
ExecutionService: execution,
|
||||
ModeManager: { getTradingEngine: () => engine } as ModeManager,
|
||||
},
|
||||
const manager = makeStrategyManager({
|
||||
execution,
|
||||
modeManager: { getTradingEngine: () => engine } as ModeManager,
|
||||
});
|
||||
cleanup.push(() => manager.shutdown());
|
||||
await expect(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue