Implement options snapshot tape table

This commit is contained in:
dirtydishes 2026-05-04 01:14:52 -04:00
parent 6abfff30d3
commit e78387130a
15 changed files with 904 additions and 128 deletions

View file

@ -512,7 +512,23 @@ const normalizeOptionRow = (row: unknown): unknown => {
"ts",
"price",
"size",
"notional"
"notional",
"execution_nbbo_bid",
"execution_nbbo_ask",
"execution_nbbo_mid",
"execution_nbbo_spread",
"execution_nbbo_bid_size",
"execution_nbbo_ask_size",
"execution_nbbo_ts",
"execution_nbbo_age_ms",
"execution_underlying_spot",
"execution_underlying_bid",
"execution_underlying_ask",
"execution_underlying_mid",
"execution_underlying_spread",
"execution_underlying_ts",
"execution_underlying_age_ms",
"execution_iv"
]);
if ("is_etf" in record) {

View file

@ -19,6 +19,25 @@ CREATE TABLE IF NOT EXISTS ${OPTION_PRINTS_TABLE} (
option_type Nullable(String),
notional Nullable(Float64),
nbbo_side Nullable(String),
execution_nbbo_bid Nullable(Float64),
execution_nbbo_ask Nullable(Float64),
execution_nbbo_mid Nullable(Float64),
execution_nbbo_spread Nullable(Float64),
execution_nbbo_bid_size Nullable(UInt32),
execution_nbbo_ask_size Nullable(UInt32),
execution_nbbo_ts Nullable(UInt64),
execution_nbbo_age_ms Nullable(Float64),
execution_nbbo_side Nullable(String),
execution_underlying_spot Nullable(Float64),
execution_underlying_bid Nullable(Float64),
execution_underlying_ask Nullable(Float64),
execution_underlying_mid Nullable(Float64),
execution_underlying_spread Nullable(Float64),
execution_underlying_ts Nullable(UInt64),
execution_underlying_age_ms Nullable(Float64),
execution_underlying_source Nullable(String),
execution_iv Nullable(Float64),
execution_iv_source Nullable(String),
is_etf Nullable(Bool),
signal_pass Nullable(Bool),
signal_reasons Array(String) DEFAULT [],
@ -35,6 +54,25 @@ export const optionPrintsTableMigrations = (): string[] => {
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS option_type Nullable(String)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS notional Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS nbbo_side Nullable(String)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_bid Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_ask Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_mid Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_spread Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_bid_size Nullable(UInt32)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_ask_size Nullable(UInt32)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_ts Nullable(UInt64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_age_ms Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_nbbo_side Nullable(String)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_spot Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_bid Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_ask Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_mid Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_spread Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_ts Nullable(UInt64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_age_ms Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_underlying_source Nullable(String)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_iv Nullable(Float64)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS execution_iv_source Nullable(String)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS is_etf Nullable(Bool)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS signal_pass Nullable(Bool)`,
`ALTER TABLE ${OPTION_PRINTS_TABLE} ADD COLUMN IF NOT EXISTS signal_reasons Array(String) DEFAULT []`,

View file

@ -25,10 +25,20 @@ describe("option-prints storage helpers", () => {
expect(normalized.conditions).toEqual([]);
});
it("normalizes legacy rows with missing execution context", () => {
const normalized = normalizeOptionPrint(basePrint);
expect(normalized.execution_nbbo_bid).toBeUndefined();
expect(normalized.execution_underlying_spot).toBeUndefined();
expect(normalized.execution_iv).toBeUndefined();
});
it("includes the correct table name in the DDL", () => {
const ddl = optionPrintsTableDDL();
expect(ddl).toContain(OPTION_PRINTS_TABLE);
expect(ddl).toContain("CREATE TABLE IF NOT EXISTS");
expect(ddl).toContain("execution_nbbo_bid Nullable(Float64)");
expect(ddl).toContain("execution_underlying_spot Nullable(Float64)");
expect(ddl).toContain("execution_iv Nullable(Float64)");
});
it("builds before/history and trace lookup queries", async () => {