stock-bot/scripts/import-research-dataset.ts
Boki 4cd6038063 refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack
- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched)
- Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations()
- Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation
- Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims
- Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution
- Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
2026-11-27 00:11:50 -05:00

42 lines
1.8 KiB
TypeScript

/** Explicit offline custody of an existing v2 dataset. No provider/calendar inference. */
import { readFile } from 'node:fs/promises';
import { Pool } from 'pg';
import { validateDatasetV2 } from '../apps/stock/orchestrator/src/data/historical-dataset-v2';
import { retainResearchDataset } from '@stock-bot/trading-runtime/retained-dataset';
export { retainResearchDataset } from '@stock-bot/trading-runtime/retained-dataset';
if (import.meta.main) {
let database: Pool | undefined;
try {
const args = process.argv.slice(2);
if (args.length !== 2 || args[0] !== '--file' || !args[1]) {
throw new Error(
'Usage: RESEARCH_DATASET_DATABASE_URL=<database> bun run scripts/import-research-dataset.ts --file <v2-dataset.json>'
);
}
const connectionString = process.env.RESEARCH_DATASET_DATABASE_URL;
if (
!connectionString ||
!['postgres:', 'postgresql:'].includes(new URL(connectionString).protocol)
) {
throw new Error(
'Set RESEARCH_DATASET_DATABASE_URL explicitly; this command retains research data'
);
}
const input: unknown = JSON.parse(await readFile(args[1], 'utf8'));
// Validate before opening a database connection. Existing startup migrations
// own the schema; import never updates/deletes retained data or migrates tables.
validateDatasetV2(input);
database = new Pool({ connectionString, connectionTimeoutMillis: 5000 });
const manifest = await retainResearchDataset(database, input);
process.stdout.write(
`${JSON.stringify({ hash: manifest.hash, barCount: manifest.barCount, eligibility: manifest.eligibility, limitations: manifest.limitations }, null, 2)}\n`
);
} catch (error) {
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
process.exitCode = 1;
} finally {
await database?.end();
}
}