well-interfaced pluggable databases

This commit is contained in:
2024-07-30 03:46:41 +00:00
parent 9e1a5906e4
commit 3e5e728d92
21 changed files with 1426 additions and 271 deletions
+51
View File
@@ -0,0 +1,51 @@
import type { AggregateDatabase } from "../interfaces.js";
// import { stockDatabase as stockDatabaseClickhouse } from "../stockdb.clickhouse.js";
// import { stockDatabase as stockDatabaseLmdbx } from "../stockdb.lmdbx.js";
import { optionContractDatabase as optionContractDatabaseClickhouse } from "../optiondb.clickhouse.js";
import { optionContractDatabase as optionContractDatabaseLmdbx } from "../optiondb.lmdbx.js";
function nextDate(date: string) {
const dateObject = new Date(date);
dateObject.setDate(dateObject.getDate() + 1);
return dateObject.toISOString().substring(0, 10);
}
async function syncAggregates<T>({
from,
to,
key,
date,
}: {
from: AggregateDatabase<T>;
to: AggregateDatabase<T>;
key: T;
date: string;
}) {
const aggregatesFrom = (await from.getAggregates({ key, date })).map(
(aggregateWithoutKey) => ({ ...aggregateWithoutKey, key }),
);
await to.insertAggregates(aggregatesFrom);
}
const symbols = ["AMD", "AAPL", "MSFT", "GOOGL", "NFLX", "NVDA"];
async function run() {
const startDate = "2022-02-01";
const endDate = "2024-07-15";
for (let date = startDate; date <= endDate; date = nextDate(date)) {
// const symbols = await stockDatabaseClickhouse.getSymbols({ date });
for (const symbol of symbols) {
console.log(date, symbol);
const keys = await optionContractDatabaseClickhouse.getKeys({key: {symbol}, date});
for(const key of keys){
await syncAggregates({
from: optionContractDatabaseClickhouse,
to: optionContractDatabaseLmdbx,
key,
date,
});
}
}
}
}
await run();