04-adaptive-collector/tools/import-calibration.mjs Repository market-data-intelligence-lab Original path 04-adaptive-collector/tools/import-calibration.mjsRole SOURCE Size 1490 bytes Lines 35 SHA-256 426967d6fcdf8ade3436d72ed8a00b995eddf1faffeb3eb785d501b15476b65bDisplayed range 1–35 Previous file/page · Project index · Next file/page
import path from "node:path";
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
import { CONFIG } from "../config.mjs";
import { validateCalibration } from "../lib/adaptive-sampler.mjs";
const source = process.argv[2];
if (!source) throw new Error("Usage: node tools/import-calibration.mjs /path/to/research/calibration.json");
const raw = JSON.parse(await readFile(path.resolve(source), "utf8"));
const cal = validateCalibration(raw);
if (!cal) throw new Error("Plik nie ma poprawnych baselines/event_thresholds");
const wrapped = {
...cal,
schema: "adaptive-ob-calibration-v1",
algorithm: "adaptive-ob-v0.4-winner",
calibrationId: cal.calibrationId || `research-${new Date().toISOString().replace(/[:.]/g, "-")}`,
source: "research_import",
primaryMarket: "spot",
primarySymbol: CONFIG.SPOT_SYMBOL,
sensorUniverse: {
spotSymbol: CONFIG.SPOT_SYMBOL,
perpSymbol: CONFIG.PERP_SYMBOL,
orderbookDepth: CONFIG.ORDERBOOK_DEPTH,
fastWindowMs: CONFIG.ADAPTIVE_FAST_WINDOW_MS,
tickMs: CONFIG.ADAPTIVE_TICK_MS,
topLevels: CONFIG.ADAPTIVE_TOP_LEVELS,
},
importedAt: new Date().toISOString(),
};
const dest = CONFIG.ADAPTIVE_CALIBRATION_FILE;
await mkdir(path.dirname(dest), { recursive: true });
const tmp = `${dest}.tmp`;
await writeFile(tmp, JSON.stringify(wrapped, null, 2) + "\n", "utf8");
await rename(tmp, dest);
console.log(`OK: ${dest}`);
console.log(`primary: spot ${CONFIG.SPOT_SYMBOL}`);