refactor; backtest using lmdbx
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
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";
|
||||
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";
|
||||
import { nextDate } from "../lib/utils/nextDate.js";
|
||||
import { retry, retryOnTimeout } from "../lib/utils/retry.js";
|
||||
import type { OptionContractKey } from "../optiondb/interfaces.js";
|
||||
import type { StockKey } from "../stockdb/interfaces.js";
|
||||
|
||||
async function syncAggregates<T>({
|
||||
fromDatabase,
|
||||
@@ -24,7 +26,10 @@ async function syncAggregates<T>({
|
||||
}
|
||||
|
||||
const symbols = ["AMD", "AAPL", "MSFT", "GOOGL", "NFLX", "NVDA"];
|
||||
async function run() {
|
||||
async function run<T extends StockKey | OptionContractKey>({
|
||||
fromDatabase,
|
||||
toDatabase,
|
||||
}: { fromDatabase: AggregateDatabase<T>; toDatabase: AggregateDatabase<T> }) {
|
||||
const startDate = process.argv[2];
|
||||
const endDate = process.argv[3];
|
||||
|
||||
@@ -39,8 +44,8 @@ async function run() {
|
||||
console.log(date, symbol);
|
||||
const keys = await retry(
|
||||
() =>
|
||||
optionContractDatabaseClickhouse.getKeys({
|
||||
key: { symbol },
|
||||
fromDatabase.getKeys({
|
||||
key: { symbol } as T,
|
||||
date,
|
||||
}),
|
||||
{ shouldRetry: retryOnTimeout },
|
||||
@@ -51,8 +56,8 @@ async function run() {
|
||||
await retry(
|
||||
() =>
|
||||
syncAggregates({
|
||||
fromDatabase: optionContractDatabaseClickhouse,
|
||||
toDatabase: optionContractDatabaseLmdbx,
|
||||
fromDatabase,
|
||||
toDatabase,
|
||||
key,
|
||||
date,
|
||||
}),
|
||||
@@ -63,4 +68,7 @@ async function run() {
|
||||
}
|
||||
}
|
||||
|
||||
await run();
|
||||
await run({
|
||||
fromDatabase: stockDatabaseClickhouse,
|
||||
toDatabase: stockDatabaseLmdbx,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user