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,32 +1,31 @@
import { logger } from '@stock-bot/logger';
import { IServiceContainer } from '@stock-bot/di';
import { QuestDBClient } from '@stock-bot/questdb';
import { PostgresClient } from '@stock-bot/postgres';
import { MongoDBClient } from '@stock-bot/mongodb';
import { ModeConfig, MarketData, Position } from '../types';
export class StorageService {
private questdb: QuestDBClient | null = null;
private postgres: PostgresClient | null = null;
private mongodb: MongoDBClient | null = null;
private mode: 'backtest' | 'paper' | 'live' = 'paper';
private container: IServiceContainer;
constructor(
container: IServiceContainer,
mongoClient: MongoDBClient,
postgresClient: PostgresClient,
questdbClient: QuestDBClient | null
) {
this.container = container;
this.mongodb = mongoClient;
this.postgres = postgresClient;
this.questdb = questdbClient;
}
async initialize(config: ModeConfig): Promise<void> {
this.mode = config.mode;
// Initialize QuestDB for time-series data
this.questdb = new QuestDBClient({
host: process.env.QUESTDB_HOST || 'localhost',
port: parseInt(process.env.QUESTDB_PORT || '9000'),
database: process.env.QUESTDB_DATABASE || 'trading'
});
// Initialize PostgreSQL for relational data
this.postgres = new PostgresClient({
host: process.env.POSTGRES_HOST || 'localhost',
port: parseInt(process.env.POSTGRES_PORT || '5432'),
database: process.env.POSTGRES_DATABASE || 'trading',
user: process.env.POSTGRES_USER || 'postgres',
password: process.env.POSTGRES_PASSWORD || 'postgres'
});
// Clients are already injected via DI
await this.createTables();
}
@ -281,12 +280,12 @@ export class StorageService {
async shutdown(): Promise<void> {
if (this.questdb) {
await this.questdb.close();
await this.questdb.disconnect();
this.questdb = null;
}
if (this.postgres) {
await this.postgres.close();
await this.postgres.disconnect();
this.postgres = null;
}
}