onesecondtrader 0.43.0__py3-none-any.whl → 0.45.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. onesecondtrader/__init__.py +0 -60
  2. onesecondtrader/events/__init__.py +7 -0
  3. onesecondtrader/events/base.py +19 -0
  4. onesecondtrader/models/__init__.py +10 -0
  5. onesecondtrader/models/bar_fields.py +23 -0
  6. onesecondtrader/models/bar_period.py +21 -0
  7. onesecondtrader/models/order_types.py +21 -0
  8. onesecondtrader/models/trade_sides.py +20 -0
  9. {onesecondtrader-0.43.0.dist-info → onesecondtrader-0.45.0.dist-info}/METADATA +2 -2
  10. onesecondtrader-0.45.0.dist-info/RECORD +12 -0
  11. onesecondtrader/connectors/__init__.py +0 -3
  12. onesecondtrader/connectors/brokers/__init__.py +0 -4
  13. onesecondtrader/connectors/brokers/ib.py +0 -418
  14. onesecondtrader/connectors/brokers/simulated.py +0 -349
  15. onesecondtrader/connectors/datafeeds/__init__.py +0 -4
  16. onesecondtrader/connectors/datafeeds/ib.py +0 -286
  17. onesecondtrader/connectors/datafeeds/simulated.py +0 -198
  18. onesecondtrader/connectors/gateways/__init__.py +0 -3
  19. onesecondtrader/connectors/gateways/ib.py +0 -314
  20. onesecondtrader/core/__init__.py +0 -7
  21. onesecondtrader/core/brokers/__init__.py +0 -3
  22. onesecondtrader/core/brokers/base.py +0 -46
  23. onesecondtrader/core/datafeeds/__init__.py +0 -3
  24. onesecondtrader/core/datafeeds/base.py +0 -32
  25. onesecondtrader/core/events/__init__.py +0 -33
  26. onesecondtrader/core/events/bases.py +0 -29
  27. onesecondtrader/core/events/market.py +0 -22
  28. onesecondtrader/core/events/requests.py +0 -33
  29. onesecondtrader/core/events/responses.py +0 -54
  30. onesecondtrader/core/indicators/__init__.py +0 -13
  31. onesecondtrader/core/indicators/averages.py +0 -56
  32. onesecondtrader/core/indicators/bar.py +0 -47
  33. onesecondtrader/core/indicators/base.py +0 -60
  34. onesecondtrader/core/messaging/__init__.py +0 -7
  35. onesecondtrader/core/messaging/eventbus.py +0 -47
  36. onesecondtrader/core/messaging/subscriber.py +0 -69
  37. onesecondtrader/core/models/__init__.py +0 -15
  38. onesecondtrader/core/models/data.py +0 -18
  39. onesecondtrader/core/models/orders.py +0 -27
  40. onesecondtrader/core/models/params.py +0 -21
  41. onesecondtrader/core/models/records.py +0 -34
  42. onesecondtrader/core/strategies/__init__.py +0 -7
  43. onesecondtrader/core/strategies/base.py +0 -331
  44. onesecondtrader/core/strategies/examples.py +0 -47
  45. onesecondtrader/dashboard/__init__.py +0 -3
  46. onesecondtrader/dashboard/app.py +0 -2972
  47. onesecondtrader/dashboard/registry.py +0 -100
  48. onesecondtrader/orchestrator/__init__.py +0 -7
  49. onesecondtrader/orchestrator/orchestrator.py +0 -105
  50. onesecondtrader/orchestrator/recorder.py +0 -199
  51. onesecondtrader/orchestrator/schema.sql +0 -212
  52. onesecondtrader/secmaster/__init__.py +0 -6
  53. onesecondtrader/secmaster/schema.sql +0 -740
  54. onesecondtrader/secmaster/utils.py +0 -737
  55. onesecondtrader-0.43.0.dist-info/RECORD +0 -49
  56. {onesecondtrader-0.43.0.dist-info → onesecondtrader-0.45.0.dist-info}/WHEEL +0 -0
  57. {onesecondtrader-0.43.0.dist-info → onesecondtrader-0.45.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,740 +0,0 @@
1
- -- Security Master Database Schema
2
- --
3
- -- Stores instrument metadata and market data using Databento's schema and terminology.
4
- --
5
- -- [:material-link-variant: View DataBento's Schemas and Data Formats Documentation](https://databento.com/docs/schemas-and-data-formats?historical=python&live=python&reference=python)
6
- --
7
- -- [:material-link-variant: View DataBento's Standards and Conventions Documentation](https://databento.com/docs/standards-and-conventions?historical=python&live=python&reference=python)
8
- --
9
- -- The security master database schema follows a normalized one-to-many relationship structure: each publisher
10
- -- can have many instruments, and each instrument can have many records in each of the
11
- -- market data tables.
12
- --
13
- -- Metadata Tables:
14
- --
15
- -- | Table | Databento Schema | Description |
16
- -- |-------|------------------|-------------|
17
- -- | `publishers` | - | Registry of data vendors and market data sources that provide instrument definitions and price data. Each publisher represents a distinct data feed with its own instrument identifiers. |
18
- -- | `instruments` | `definition` | Comprehensive security master containing static reference data for all tradeable instruments including contract specifications, pricing parameters, expiration dates, and hierarchical relationships between derivatives and their underlyings. |
19
- --
20
- -- Market Data Tables:
21
- --
22
- -- | Table | Databento Schema | Description |
23
- -- |-------|------------------|-------------|
24
- -- | `ohlcv` | `ohlcv-1s`, `ohlcv-1m`, etc. | Aggregated Open-High-Low-Close-Volume bar/candlestick data at various time intervals (1-second, 1-minute, hourly, daily). Foundation for technical analysis and strategy backtesting. |
25
- -- | `trades` | `trades` / `mbp-0` | Individual trade executions (prints) with price, size, and exchange-assigned trade conditions. Captures every matched order for tick-level analysis. |
26
- -- | `quotes` | `mbp-1` | Top-of-book bid/ask quotes with the most recent trade information. Each record represents an order book event that changed the best bid or offer. |
27
- -- | `bbo` | `bbo-1s`, `bbo-1m` | Periodically sampled best bid/offer snapshots at regular intervals. Provides compressed spread data without full tick granularity. |
28
- -- | `mbo` | `mbo` | Full market-by-order data capturing every order book event including additions, modifications, cancellations, and executions with individual order IDs. |
29
- -- | `mbp10` | `mbp-10` | 10-level market depth snapshots showing the top 10 price levels on both bid and ask sides. Balances depth visibility with storage efficiency. |
30
- -- | `imbalance` | `imbalance` | Auction imbalance messages published during opening, closing, and intraday auctions showing paired and unpaired share quantities. |
31
- -- | `statistics` | `statistics` | Exchange-published statistics including settlement prices, open interest, trading volume, and reference prices for mark-to-market calculations. |
32
- -- | `status` | `status` | Trading status updates indicating instrument state changes such as trading halts, pre-open periods, auction states, and session boundaries. |
33
-
34
-
35
- -- Data providers and market data vendors that supply instrument definitions and market data.
36
- --
37
- -- This table serves as the authoritative registry of all data sources in the system.
38
- -- It is intentionally separated from the instruments table because the same trading
39
- -- symbol (e.g., `ESH5` for the March 2025 E-mini S&P 500 future) may exist across
40
- -- multiple vendors, each assigning their own unique `instrument_id`. This design
41
- -- allows the system to track and reconcile data from multiple sources while
42
- -- maintaining clear provenance for each instrument.
43
- --
44
- -- The `dataset` field uses Databento's dataset naming convention, which combines
45
- -- the venue and feed identifier (e.g., `GLBX.MDP3` for CME Globex MDP 3.0 feed).
46
- --
47
- -- | Field | Type | Constraints | Description |
48
- -- |-------|------|-------------|-------------|
49
- -- | `publisher_id` | INTEGER | PRIMARY KEY | Auto-incrementing unique identifier that serves as the primary key for this publisher record |
50
- -- | `name` | TEXT | NOT NULL, UNIQUE | Human-readable name of the data provider or vendor (e.g., `Databento`, `Bloomberg`). Must be unique across all publishers |
51
- -- | `dataset` | TEXT | NOT NULL | Databento dataset identifier that specifies the venue and feed combination (e.g., `GLBX.MDP3` for CME Globex Market Data Platform 3.0) |
52
- -- | `venue` | TEXT | | ISO 10383 Market Identifier Code (MIC) for the trading venue (e.g., `XCME` for Chicago Mercantile Exchange). May be NULL if the publisher covers multiple venues |
53
- CREATE TABLE publishers (
54
- publisher_id INTEGER PRIMARY KEY,
55
- name TEXT NOT NULL UNIQUE,
56
- dataset TEXT NOT NULL,
57
- venue TEXT
58
- );
59
-
60
- -- Security and instrument metadata sourced from Databento's `InstrumentDefMsg`.
61
- --
62
- -- This table serves as the central repository for all tradeable instruments in the system.
63
- -- It stores static reference data that defines each instrument's characteristics, including
64
- -- contract specifications, pricing parameters, and temporal validity. The schema is designed
65
- -- to accommodate a wide variety of instrument types including equities, futures, options,
66
- -- spreads, and FX products.
67
- --
68
- -- Each instrument is uniquely identified within the system by `instrument_id`, but the same
69
- -- logical instrument (e.g., ESH5) may appear multiple times if sourced from different
70
- -- publishers. The unique constraint on (`publisher_id`, `raw_symbol`) ensures data integrity
71
- -- while allowing multi-source reconciliation.
72
- --
73
- -- For derivatives, the `underlying_id` field creates a self-referential relationship that
74
- -- links options and futures to their underlying instruments, enabling hierarchical queries
75
- -- across the derivatives chain.
76
- --
77
- -- Instrument Class Codes (used in `instrument_class`):
78
- --
79
- -- | Code | Description |
80
- -- |------|-------------|
81
- -- | B | Bond |
82
- -- | C | Call option |
83
- -- | F | Future |
84
- -- | K | Stock |
85
- -- | M | Mixed spread |
86
- -- | P | Put option |
87
- -- | S | Future spread |
88
- -- | T | Option spread |
89
- -- | X | FX spot |
90
- -- | Y | Commodity spot |
91
- --
92
- -- | Field | Type | Constraints | Description |
93
- -- |-------|------|-------------|-------------|
94
- -- | `instrument_id` | INTEGER | PRIMARY KEY | Auto-incrementing unique identifier that serves as the primary key for this instrument record within the security master |
95
- -- | `publisher_id` | INTEGER | NOT NULL, FK | Foreign key reference to `publishers.publisher_id` identifying which data vendor provided this instrument definition |
96
- -- | `raw_instrument_id` | INTEGER | | The native instrument identifier assigned by the publisher/exchange (e.g., Databento's internal ID). May be NULL if not provided |
97
- -- | `raw_symbol` | TEXT | NOT NULL | The trading symbol exactly as provided by the publisher without any normalization (e.g., `ESH5` for March 2025 E-mini S&P 500) |
98
- -- | `instrument_class` | TEXT | NOT NULL, DEFAULT 'K' | Single-character classification code indicating the instrument type. See the Instrument Class Codes table above for the complete mapping |
99
- -- | `security_type` | TEXT | | Descriptive security type string used by the exchange (e.g., `FUT` for futures, `OPT` for options, `STK` for stocks, `MLEG` for multi-leg) |
100
- -- | `asset` | TEXT | | The underlying asset or product code that this instrument is based on (e.g., `ES` for E-mini S&P 500, `CL` for Crude Oil, `AAPL` for Apple stock) |
101
- -- | `cfi` | TEXT | | ISO 10962 Classification of Financial Instruments code providing standardized instrument categorization (e.g., `FXXXXX` for futures) |
102
- -- | `exchange` | TEXT | | ISO 10383 Market Identifier Code (MIC) for the primary exchange where this instrument trades (e.g., `XCME` for CME, `XNYS` for NYSE) |
103
- -- | `currency` | TEXT | DEFAULT 'USD' | ISO 4217 currency code for the currency in which the instrument is quoted and traded. Defaults to USD if not specified |
104
- -- | `strike_price` | INTEGER | | For options: the strike price at which the option can be exercised. Stored as fixed-point integer with $10^9$ scale factor. NULL for non-option instruments |
105
- -- | `strike_price_currency` | TEXT | | ISO 4217 currency code for the strike price, which may differ from the trading currency in quanto or cross-currency options |
106
- -- | `expiration` | INTEGER | | The timestamp when the instrument expires and ceases trading, stored as nanoseconds since Unix epoch. NULL for perpetual instruments |
107
- -- | `activation` | INTEGER | | The timestamp when the instrument becomes available for trading, stored as nanoseconds since Unix epoch. Useful for newly listed contracts |
108
- -- | `maturity_year` | INTEGER | | The calendar year component embedded in the instrument symbol (e.g., 2025 for ESH5). Used for futures and options contract identification |
109
- -- | `maturity_month` | INTEGER | | The calendar month component (1-12) embedded in the instrument symbol (e.g., 3 for March in ESH5). Used for contract roll calculations |
110
- -- | `maturity_day` | INTEGER | | The calendar day component embedded in the instrument symbol, if applicable. NULL for monthly contracts, populated for weekly options |
111
- -- | `contract_multiplier` | INTEGER | | The multiplier applied to the quoted price to determine the contract's notional value (e.g., 50 for ES futures means $50 per index point) |
112
- -- | `unit_of_measure` | TEXT | | The unit in which the underlying commodity or asset is measured (e.g., `USD` for financial futures, `LBS` for cattle, `BBL` for oil) |
113
- -- | `unit_of_measure_qty` | INTEGER | | The quantity of the unit of measure per contract, stored as fixed-point integer with $10^9$ scale factor (e.g., 1000 barrels for CL) |
114
- -- | `underlying_id` | INTEGER | FK | Self-referential foreign key to `instruments.instrument_id` linking derivatives to their underlying instrument. NULL for non-derivatives |
115
- -- | `underlying` | TEXT | | The symbol of the underlying instrument as a string. Provides a denormalized reference when the underlying may not exist in the database |
116
- -- | `display_factor` | INTEGER | | Multiplier for converting internal prices to display prices, stored as fixed-point integer with $10^9$ scale factor. Used for price formatting |
117
- -- | `high_limit_price` | INTEGER | | The maximum price at which the instrument can trade during the session (circuit breaker), stored as fixed-point integer with $10^9$ scale factor |
118
- -- | `low_limit_price` | INTEGER | | The minimum price at which the instrument can trade during the session (circuit breaker), stored as fixed-point integer with $10^9$ scale factor |
119
- -- | `min_price_increment` | INTEGER | | The minimum price movement (tick size) for the instrument, stored as fixed-point integer with $10^9$ scale factor (e.g., 0.25 for ES) |
120
- -- | `security_group` | TEXT | | Exchange-defined grouping code that categorizes related instruments (e.g., `ES` group contains all E-mini S&P 500 contracts) |
121
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when this instrument definition was received/captured by the data infrastructure, stored as nanoseconds since Unix epoch |
122
- CREATE TABLE instruments (
123
- instrument_id INTEGER PRIMARY KEY,
124
- publisher_id INTEGER NOT NULL,
125
- raw_instrument_id INTEGER,
126
- raw_symbol TEXT NOT NULL,
127
- instrument_class TEXT NOT NULL DEFAULT 'K' CHECK(instrument_class IN ('B', 'C', 'F', 'K', 'M', 'P', 'S', 'T', 'X', 'Y')),
128
- security_type TEXT,
129
- asset TEXT,
130
- cfi TEXT,
131
- exchange TEXT,
132
- currency TEXT DEFAULT 'USD',
133
- strike_price INTEGER,
134
- strike_price_currency TEXT,
135
- expiration INTEGER,
136
- activation INTEGER,
137
- maturity_year INTEGER,
138
- maturity_month INTEGER CHECK(maturity_month IS NULL OR (maturity_month >= 1 AND maturity_month <= 12)),
139
- maturity_day INTEGER CHECK(maturity_day IS NULL OR (maturity_day >= 1 AND maturity_day <= 31)),
140
- contract_multiplier INTEGER,
141
- unit_of_measure TEXT,
142
- unit_of_measure_qty INTEGER,
143
- underlying_id INTEGER,
144
- underlying TEXT,
145
- display_factor INTEGER,
146
- high_limit_price INTEGER,
147
- low_limit_price INTEGER,
148
- min_price_increment INTEGER,
149
- security_group TEXT,
150
- ts_recv INTEGER NOT NULL,
151
- FOREIGN KEY (publisher_id) REFERENCES publishers(publisher_id),
152
- FOREIGN KEY (underlying_id) REFERENCES instruments(instrument_id),
153
- UNIQUE(publisher_id, raw_symbol)
154
- );
155
-
156
- -- OHLCV (Open-High-Low-Close-Volume) bar/candlestick data sourced from Databento's `OhlcvMsg`.
157
- --
158
- -- This table stores aggregated price and volume data at various time intervals, providing
159
- -- the foundation for technical analysis, charting, and strategy backtesting. Each row
160
- -- represents a single bar/candle summarizing all trading activity within a specific time
161
- -- period for a given instrument.
162
- --
163
- -- The table supports multiple bar durations through the `rtype` field, allowing storage of
164
- -- 1-second, 1-minute, 1-hour, 1-day, and end-of-day bars in a single unified table. This
165
- -- design enables efficient cross-timeframe analysis without requiring separate tables for
166
- -- each granularity.
167
- --
168
- -- The composite primary key is ordered with `instrument_id` first to ensure that all bars
169
- -- for the same instrument are physically clustered together on disk, optimizing sequential
170
- -- reads for time-series queries and backtesting operations.
171
- --
172
- -- | Field | Type | Constraints | Description |
173
- -- |-------|------|-------------|-------------|
174
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this bar belongs to. Part of the composite primary key |
175
- -- | `rtype` | INTEGER | NOT NULL, PK | Databento record type code indicating the bar duration: 32=1-second, 33=1-minute, 34=1-hour, 35=1-day, 36=end-of-day. Part of the composite primary key |
176
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp marking the beginning of the bar interval, stored as nanoseconds since Unix epoch. Part of the composite primary key |
177
- -- | `open` | INTEGER | NOT NULL | The first traded price during the bar interval, stored as fixed-point integer with $10^9$ scale factor for nanosecond price precision |
178
- -- | `high` | INTEGER | NOT NULL | The highest traded price during the bar interval, stored as fixed-point integer with $10^9$ scale factor |
179
- -- | `low` | INTEGER | NOT NULL | The lowest traded price during the bar interval, stored as fixed-point integer with $10^9$ scale factor |
180
- -- | `close` | INTEGER | NOT NULL | The last traded price during the bar interval, stored as fixed-point integer with $10^9$ scale factor |
181
- -- | `volume` | INTEGER | NOT NULL | The total number of contracts or shares traded during the bar interval. Represents the sum of all trade sizes |
182
- --
183
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree,
184
- -- eliminating the overhead of rowid indirection and reducing storage requirements for this
185
- -- high-volume table.
186
- CREATE TABLE ohlcv (
187
- instrument_id INTEGER NOT NULL,
188
- rtype INTEGER NOT NULL CHECK(rtype IN (32, 33, 34, 35, 36)),
189
- ts_event INTEGER NOT NULL,
190
- open INTEGER NOT NULL,
191
- high INTEGER NOT NULL,
192
- low INTEGER NOT NULL CHECK(low <= high),
193
- close INTEGER NOT NULL,
194
- volume INTEGER NOT NULL CHECK(volume >= 0),
195
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
196
- PRIMARY KEY (instrument_id, rtype, ts_event)
197
- ) WITHOUT ROWID;
198
-
199
- -- Individual trade execution records sourced from Databento's `Mbp0Msg` (trades schema).
200
- --
201
- -- This table captures every individual trade that occurs on the exchange, providing the
202
- -- highest granularity of execution data available. Each row represents a single match
203
- -- between a buyer and seller, recording the exact price, quantity, and timing of the
204
- -- transaction.
205
- --
206
- -- Trade data is essential for transaction cost analysis (TCA), market microstructure
207
- -- research, VWAP/TWAP calculations, and high-frequency trading strategies. The `side`
208
- -- field indicates which side of the order book was the aggressor (the party that crossed
209
- -- the spread to execute immediately).
210
- --
211
- -- The composite primary key includes `sequence` in addition to timestamp because modern
212
- -- exchanges can execute multiple trades within the same nanosecond, particularly during
213
- -- periods of high volatility or when large orders are filled across multiple price levels.
214
- --
215
- -- | Field | Type | Constraints | Description |
216
- -- |-------|------|-------------|-------------|
217
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument was traded. Part of the composite primary key |
218
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp when the trade was executed by the exchange's matching engine, stored as nanoseconds since Unix epoch. Part of the composite primary key |
219
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the trade message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
220
- -- | `price` | INTEGER | NOT NULL | The execution price of the trade, stored as fixed-point integer with $10^9$ scale factor for nanosecond price precision |
221
- -- | `size` | INTEGER | NOT NULL | The number of contracts or shares that were traded in this execution |
222
- -- | `action` | TEXT | NOT NULL | The event action type. For trades, this is always 'T' indicating a trade execution |
223
- -- | `side` | TEXT | NOT NULL | Indicates which side was the aggressor (liquidity taker): 'A'=Ask (buyer lifted the offer), 'B'=Bid (seller hit the bid), 'N'=None/unknown |
224
- -- | `flags` | INTEGER | NOT NULL | Bit field containing message flags including packet boundary indicators and data quality markers. See Databento documentation for bit definitions |
225
- -- | `depth` | INTEGER | NOT NULL | The book depth level. For trades this is always 0 as trades occur at the top of book |
226
- -- | `ts_in_delta` | INTEGER | NOT NULL | The latency between exchange transmission and capture receipt, calculated as `ts_recv - ts_exchange_send` in nanoseconds. Useful for latency analysis |
227
- -- | `sequence` | INTEGER | NOT NULL, PK | The venue's message sequence number, used to detect gaps and ensure message ordering. Part of the composite primary key to disambiguate simultaneous trades |
228
- --
229
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree,
230
- -- critical for this high-volume tick data table where storage efficiency is paramount.
231
- CREATE TABLE trades (
232
- instrument_id INTEGER NOT NULL,
233
- ts_event INTEGER NOT NULL,
234
- ts_recv INTEGER NOT NULL,
235
- price INTEGER NOT NULL,
236
- size INTEGER NOT NULL CHECK(size > 0),
237
- action TEXT NOT NULL CHECK(action IN ('A', 'C', 'M', 'R', 'T', 'F', 'N')),
238
- side TEXT NOT NULL CHECK(side IN ('A', 'B', 'N')),
239
- flags INTEGER NOT NULL,
240
- depth INTEGER NOT NULL,
241
- ts_in_delta INTEGER NOT NULL,
242
- sequence INTEGER NOT NULL,
243
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
244
- PRIMARY KEY (instrument_id, ts_event, sequence)
245
- ) WITHOUT ROWID;
246
-
247
- -- Top-of-book quote updates with embedded trade information sourced from Databento's `Mbp1Msg` (mbp-1 schema).
248
- --
249
- -- This table captures every change to the best bid and offer (BBO) along with any associated
250
- -- trade information. It provides a complete tick-by-tick view of the top of the order book,
251
- -- enabling precise spread analysis, quote-to-trade ratio calculations, and market making
252
- -- strategy development.
253
- --
254
- -- Unlike the `trades` table which only contains executions, this table records all order book
255
- -- events at the top level including order additions, cancellations, and modifications. Each
256
- -- row includes a snapshot of the current best bid and ask after the event, making it easy to
257
- -- reconstruct the BBO at any point in time without maintaining order book state.
258
- --
259
- -- The `action` field distinguishes between different event types: new orders being added to
260
- -- the book, existing orders being cancelled or modified, book clears (typically at session
261
- -- boundaries), and trade executions.
262
- --
263
- -- | Field | Type | Constraints | Description |
264
- -- |-------|------|-------------|-------------|
265
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this quote update belongs to. Part of the composite primary key |
266
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp when the event occurred at the exchange's matching engine, stored as nanoseconds since Unix epoch. Part of the composite primary key |
267
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
268
- -- | `price` | INTEGER | NOT NULL | The price associated with the order book event (the order being added/cancelled/modified, or the trade price), stored as fixed-point integer with $10^9$ scale factor |
269
- -- | `size` | INTEGER | NOT NULL | The quantity associated with the order book event (the order size being added/cancelled/modified, or the trade size) |
270
- -- | `action` | TEXT | NOT NULL | The type of order book event: 'A'=Add (new order), 'C'=Cancel, 'M'=Modify, 'R'=Clear (book reset), 'T'=Trade execution |
271
- -- | `side` | TEXT | NOT NULL | The side of the order book affected: 'A'=Ask (sell side), 'B'=Bid (buy side), 'N'=None (for trades or unclear) |
272
- -- | `flags` | INTEGER | NOT NULL | Bit field containing message flags including packet boundary indicators and data quality markers. See Databento documentation for bit definitions |
273
- -- | `depth` | INTEGER | NOT NULL | The price level in the order book where this event occurred. For top-of-book data this is typically 0 (best price) |
274
- -- | `ts_in_delta` | INTEGER | NOT NULL | The latency between exchange transmission and capture receipt, calculated as `ts_recv - ts_exchange_send` in nanoseconds |
275
- -- | `sequence` | INTEGER | NOT NULL, PK | The venue's message sequence number for ordering and gap detection. Part of the composite primary key to disambiguate simultaneous events |
276
- -- | `bid_px` | INTEGER | NOT NULL | The best bid price after this event, stored as fixed-point integer with $10^9$ scale factor. Represents the highest price buyers are willing to pay |
277
- -- | `ask_px` | INTEGER | NOT NULL | The best ask price after this event, stored as fixed-point integer with $10^9$ scale factor. Represents the lowest price sellers are willing to accept |
278
- -- | `bid_sz` | INTEGER | NOT NULL | The total quantity available at the best bid price after this event |
279
- -- | `ask_sz` | INTEGER | NOT NULL | The total quantity available at the best ask price after this event |
280
- -- | `bid_ct` | INTEGER | NOT NULL | The number of individual orders resting at the best bid price, useful for understanding order book fragmentation |
281
- -- | `ask_ct` | INTEGER | NOT NULL | The number of individual orders resting at the best ask price, useful for understanding order book fragmentation |
282
- --
283
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree,
284
- -- critical for this high-volume tick data table.
285
- CREATE TABLE quotes (
286
- instrument_id INTEGER NOT NULL,
287
- ts_event INTEGER NOT NULL,
288
- ts_recv INTEGER NOT NULL,
289
- price INTEGER NOT NULL,
290
- size INTEGER NOT NULL,
291
- action TEXT NOT NULL CHECK(action IN ('A', 'C', 'M', 'R', 'T', 'F', 'N')),
292
- side TEXT NOT NULL CHECK(side IN ('A', 'B', 'N')),
293
- flags INTEGER NOT NULL,
294
- depth INTEGER NOT NULL,
295
- ts_in_delta INTEGER NOT NULL,
296
- sequence INTEGER NOT NULL,
297
- bid_px INTEGER NOT NULL,
298
- ask_px INTEGER NOT NULL,
299
- bid_sz INTEGER NOT NULL CHECK(bid_sz >= 0),
300
- ask_sz INTEGER NOT NULL CHECK(ask_sz >= 0),
301
- bid_ct INTEGER NOT NULL,
302
- ask_ct INTEGER NOT NULL,
303
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
304
- PRIMARY KEY (instrument_id, ts_event, sequence)
305
- ) WITHOUT ROWID;
306
-
307
-
308
- -- Subsampled best bid/offer (BBO) snapshots sourced from Databento's `BboMsg` (bbo-1s, bbo-1m schemas).
309
- --
310
- -- This table stores periodic snapshots of the best bid and offer at regular time intervals,
311
- -- providing a compressed view of top-of-book data that is more storage-efficient than full
312
- -- tick data while still capturing the essential spread dynamics.
313
- --
314
- -- Unlike the `quotes` table which records every individual order book event, this table
315
- -- contains only one record per time interval (1-second or 1-minute), representing the state
316
- -- of the BBO at the end of each interval. This makes it ideal for strategies that don't
317
- -- require tick-by-tick granularity but still need accurate spread information.
318
- --
319
- -- Each snapshot also includes information about the last trade that occurred during the
320
- -- interval (if any), providing a convenient way to correlate quote and trade data without
321
- -- joining multiple tables.
322
- --
323
- -- | Field | Type | Constraints | Description |
324
- -- |-------|------|-------------|-------------|
325
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this BBO snapshot belongs to. Part of the composite primary key |
326
- -- | `rtype` | INTEGER | NOT NULL, PK | Databento record type code indicating the snapshot interval: 195=1-second snapshots, 196=1-minute snapshots. Part of the composite primary key |
327
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp marking the end of the snapshot interval, stored as nanoseconds since Unix epoch. Part of the composite primary key |
328
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the snapshot message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
329
- -- | `price` | INTEGER | NOT NULL | The price of the last trade during the interval, stored as fixed-point integer with $10^9$ scale factor. Set to UNDEF_PRICE if no trade occurred |
330
- -- | `size` | INTEGER | NOT NULL | The size of the last trade during the interval. Set to 0 if no trade occurred during the interval |
331
- -- | `side` | TEXT | NOT NULL | The aggressor side of the last trade during the interval: 'A'=Ask (buyer lifted offer), 'B'=Bid (seller hit bid), 'N'=None (no trade or unknown) |
332
- -- | `flags` | INTEGER | NOT NULL | Bit field containing message flags including data quality markers. See Databento documentation for bit definitions |
333
- -- | `sequence` | INTEGER | NOT NULL | The venue's message sequence number of the last update that affected this snapshot, useful for synchronization |
334
- -- | `bid_px` | INTEGER | NOT NULL | The best bid price at the end of the interval, stored as fixed-point integer with $10^9$ scale factor |
335
- -- | `ask_px` | INTEGER | NOT NULL | The best ask price at the end of the interval, stored as fixed-point integer with $10^9$ scale factor |
336
- -- | `bid_sz` | INTEGER | NOT NULL | The total quantity available at the best bid price at the end of the interval |
337
- -- | `ask_sz` | INTEGER | NOT NULL | The total quantity available at the best ask price at the end of the interval |
338
- -- | `bid_ct` | INTEGER | NOT NULL | The number of individual orders resting at the best bid price at the end of the interval |
339
- -- | `ask_ct` | INTEGER | NOT NULL | The number of individual orders resting at the best ask price at the end of the interval |
340
- --
341
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree
342
- -- for efficient storage and retrieval of time-series data.
343
- CREATE TABLE bbo (
344
- instrument_id INTEGER NOT NULL,
345
- rtype INTEGER NOT NULL CHECK(rtype IN (195, 196)),
346
- ts_event INTEGER NOT NULL,
347
- ts_recv INTEGER NOT NULL,
348
- price INTEGER NOT NULL,
349
- size INTEGER NOT NULL,
350
- side TEXT NOT NULL CHECK(side IN ('A', 'B', 'N')),
351
- flags INTEGER NOT NULL,
352
- sequence INTEGER NOT NULL,
353
- bid_px INTEGER NOT NULL,
354
- ask_px INTEGER NOT NULL,
355
- bid_sz INTEGER NOT NULL CHECK(bid_sz >= 0),
356
- ask_sz INTEGER NOT NULL CHECK(ask_sz >= 0),
357
- bid_ct INTEGER NOT NULL,
358
- ask_ct INTEGER NOT NULL,
359
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
360
- PRIMARY KEY (instrument_id, rtype, ts_event)
361
- ) WITHOUT ROWID;
362
-
363
- -- Market-by-order (MBO) event data sourced from Databento's `MboMsg` (mbo schema).
364
- --
365
- -- This table contains the highest fidelity order book data available, tracking every
366
- -- individual order throughout its lifecycle from submission to completion. Each row
367
- -- represents a single event affecting a specific order, enabling complete reconstruction
368
- -- of the order book state at any point in time.
369
- --
370
- -- MBO data is essential for advanced market microstructure analysis, order flow toxicity
371
- -- measurement, and strategies that require understanding of individual order behavior
372
- -- rather than just aggregate price levels. It allows identification of specific trading
373
- -- patterns such as spoofing, layering, and iceberg order detection.
374
- --
375
- -- The composite primary key includes `order_id` because the same timestamp and sequence
376
- -- number can contain events for multiple orders (e.g., when a single aggressive order
377
- -- matches against multiple resting orders).
378
- --
379
- -- | Field | Type | Constraints | Description |
380
- -- |-------|------|-------------|-------------|
381
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this order event belongs to. Part of the composite primary key |
382
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp when the order event occurred at the exchange's matching engine, stored as nanoseconds since Unix epoch. Part of the composite primary key |
383
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
384
- -- | `order_id` | INTEGER | NOT NULL, PK | The unique order identifier assigned by the exchange, used to track the order across its entire lifecycle. Part of the composite primary key |
385
- -- | `price` | INTEGER | NOT NULL | The limit price of the order, stored as fixed-point integer with $10^9$ scale factor. For market orders, this may be set to a sentinel value |
386
- -- | `size` | INTEGER | NOT NULL | The quantity of the order. For modify events, this is the new size; for fill events, this is the filled quantity |
387
- -- | `flags` | INTEGER | NOT NULL | Bit field containing message flags including packet boundary indicators and data quality markers. See Databento documentation for bit definitions |
388
- -- | `channel_id` | INTEGER | NOT NULL | Databento's internal channel identifier used for data routing and synchronization across multiple feed handlers |
389
- -- | `action` | TEXT | NOT NULL | The type of order event: 'A'=Add (new order), 'C'=Cancel, 'M'=Modify, 'R'=Clear (book reset), 'T'=Trade, 'F'=Fill (partial or complete) |
390
- -- | `side` | TEXT | NOT NULL | The side of the order book: 'A'=Ask (sell order), 'B'=Bid (buy order), 'N'=None (for trades or unclear) |
391
- -- | `ts_in_delta` | INTEGER | NOT NULL | The latency between exchange transmission and capture receipt, calculated as `ts_recv - ts_exchange_send` in nanoseconds |
392
- -- | `sequence` | INTEGER | NOT NULL, PK | The venue's message sequence number for ordering and gap detection. Part of the composite primary key |
393
- --
394
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree,
395
- -- critical for this extremely high-volume order book data table.
396
- CREATE TABLE mbo (
397
- instrument_id INTEGER NOT NULL,
398
- ts_event INTEGER NOT NULL,
399
- ts_recv INTEGER NOT NULL,
400
- order_id INTEGER NOT NULL,
401
- price INTEGER NOT NULL,
402
- size INTEGER NOT NULL,
403
- flags INTEGER NOT NULL,
404
- channel_id INTEGER NOT NULL,
405
- action TEXT NOT NULL CHECK(action IN ('A', 'C', 'M', 'R', 'T', 'F', 'N')),
406
- side TEXT NOT NULL CHECK(side IN ('A', 'B', 'N')),
407
- ts_in_delta INTEGER NOT NULL,
408
- sequence INTEGER NOT NULL,
409
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
410
- PRIMARY KEY (instrument_id, ts_event, sequence, order_id)
411
- ) WITHOUT ROWID;
412
-
413
- -- 10-level market depth (MBP-10) snapshots sourced from Databento's `Mbp10Msg` (mbp-10 schema).
414
- --
415
- -- This table provides a complete view of the top 10 price levels on both the bid and ask
416
- -- sides of the order book at each update. It offers a balance between the full granularity
417
- -- of MBO data and the minimal footprint of top-of-book (MBP-1) data, capturing enough depth
418
- -- to understand market liquidity structure without the storage overhead of full order book
419
- -- reconstruction.
420
- --
421
- -- Each row contains both the triggering event (the order book change that caused this
422
- -- snapshot) and the resulting state of all 10 levels. This denormalized design eliminates
423
- -- the need for joins when analyzing depth data and ensures that each record is self-contained.
424
- --
425
- -- The depth data is essential for strategies that consider liquidity beyond the best price,
426
- -- such as iceberg detection, depth-weighted fair value calculations, and execution algorithms
427
- -- that need to estimate market impact across multiple price levels.
428
- --
429
- -- | Field | Type | Constraints | Description |
430
- -- |-------|------|-------------|-------------|
431
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this depth snapshot belongs to. Part of the composite primary key |
432
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp when the triggering event occurred at the exchange's matching engine, stored as nanoseconds since Unix epoch. Part of the composite primary key |
433
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
434
- -- | `price` | INTEGER | NOT NULL | The price associated with the triggering order book event, stored as fixed-point integer with $10^9$ scale factor |
435
- -- | `size` | INTEGER | NOT NULL | The quantity associated with the triggering order book event |
436
- -- | `action` | TEXT | NOT NULL | The type of event that triggered this snapshot: 'A'=Add, 'C'=Cancel, 'M'=Modify, 'R'=Clear, 'T'=Trade |
437
- -- | `side` | TEXT | NOT NULL | The side of the triggering event: 'A'=Ask, 'B'=Bid, 'N'=None |
438
- -- | `flags` | INTEGER | NOT NULL | Bit field containing message flags including packet boundary indicators and data quality markers |
439
- -- | `depth` | INTEGER | NOT NULL | The price level (0-9) where the triggering event occurred in the order book |
440
- -- | `ts_in_delta` | INTEGER | NOT NULL | The latency between exchange transmission and capture receipt, calculated as `ts_recv - ts_exchange_send` in nanoseconds |
441
- -- | `sequence` | INTEGER | NOT NULL, PK | The venue's message sequence number for ordering and gap detection. Part of the composite primary key |
442
- -- | `bid_px_00` - `bid_px_09` | INTEGER | NOT NULL | Bid prices at levels 0 (best) through 9 (10th best), stored as fixed-point integers with $10^9$ scale factor |
443
- -- | `ask_px_00` - `ask_px_09` | INTEGER | NOT NULL | Ask prices at levels 0 (best) through 9 (10th best), stored as fixed-point integers with $10^9$ scale factor |
444
- -- | `bid_sz_00` - `bid_sz_09` | INTEGER | NOT NULL | Total quantities available at each bid price level (0-9) |
445
- -- | `ask_sz_00` - `ask_sz_09` | INTEGER | NOT NULL | Total quantities available at each ask price level (0-9) |
446
- -- | `bid_ct_00` - `bid_ct_09` | INTEGER | NOT NULL | Number of individual orders at each bid price level (0-9), useful for fragmentation analysis |
447
- -- | `ask_ct_00` - `ask_ct_09` | INTEGER | NOT NULL | Number of individual orders at each ask price level (0-9), useful for fragmentation analysis |
448
- --
449
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree
450
- -- for efficient storage of this high-volume depth data.
451
- --
452
- -- Design Note: Price levels are stored as separate columns (denormalized) rather than
453
- -- in a separate table to avoid expensive joins and maintain query performance for time-series
454
- -- analysis.
455
- CREATE TABLE mbp10 (
456
- instrument_id INTEGER NOT NULL,
457
- ts_event INTEGER NOT NULL,
458
- ts_recv INTEGER NOT NULL,
459
- price INTEGER NOT NULL,
460
- size INTEGER NOT NULL,
461
- action TEXT NOT NULL CHECK(action IN ('A', 'C', 'M', 'R', 'T', 'F', 'N')),
462
- side TEXT NOT NULL CHECK(side IN ('A', 'B', 'N')),
463
- flags INTEGER NOT NULL,
464
- depth INTEGER NOT NULL CHECK(depth >= 0 AND depth <= 9),
465
- ts_in_delta INTEGER NOT NULL,
466
- sequence INTEGER NOT NULL,
467
- bid_px_00 INTEGER NOT NULL, bid_px_01 INTEGER NOT NULL, bid_px_02 INTEGER NOT NULL,
468
- bid_px_03 INTEGER NOT NULL, bid_px_04 INTEGER NOT NULL, bid_px_05 INTEGER NOT NULL,
469
- bid_px_06 INTEGER NOT NULL, bid_px_07 INTEGER NOT NULL, bid_px_08 INTEGER NOT NULL,
470
- bid_px_09 INTEGER NOT NULL,
471
- ask_px_00 INTEGER NOT NULL, ask_px_01 INTEGER NOT NULL, ask_px_02 INTEGER NOT NULL,
472
- ask_px_03 INTEGER NOT NULL, ask_px_04 INTEGER NOT NULL, ask_px_05 INTEGER NOT NULL,
473
- ask_px_06 INTEGER NOT NULL, ask_px_07 INTEGER NOT NULL, ask_px_08 INTEGER NOT NULL,
474
- ask_px_09 INTEGER NOT NULL,
475
- bid_sz_00 INTEGER NOT NULL, bid_sz_01 INTEGER NOT NULL, bid_sz_02 INTEGER NOT NULL,
476
- bid_sz_03 INTEGER NOT NULL, bid_sz_04 INTEGER NOT NULL, bid_sz_05 INTEGER NOT NULL,
477
- bid_sz_06 INTEGER NOT NULL, bid_sz_07 INTEGER NOT NULL, bid_sz_08 INTEGER NOT NULL,
478
- bid_sz_09 INTEGER NOT NULL,
479
- ask_sz_00 INTEGER NOT NULL, ask_sz_01 INTEGER NOT NULL, ask_sz_02 INTEGER NOT NULL,
480
- ask_sz_03 INTEGER NOT NULL, ask_sz_04 INTEGER NOT NULL, ask_sz_05 INTEGER NOT NULL,
481
- ask_sz_06 INTEGER NOT NULL, ask_sz_07 INTEGER NOT NULL, ask_sz_08 INTEGER NOT NULL,
482
- ask_sz_09 INTEGER NOT NULL,
483
- bid_ct_00 INTEGER NOT NULL, bid_ct_01 INTEGER NOT NULL, bid_ct_02 INTEGER NOT NULL,
484
- bid_ct_03 INTEGER NOT NULL, bid_ct_04 INTEGER NOT NULL, bid_ct_05 INTEGER NOT NULL,
485
- bid_ct_06 INTEGER NOT NULL, bid_ct_07 INTEGER NOT NULL, bid_ct_08 INTEGER NOT NULL,
486
- bid_ct_09 INTEGER NOT NULL,
487
- ask_ct_00 INTEGER NOT NULL, ask_ct_01 INTEGER NOT NULL, ask_ct_02 INTEGER NOT NULL,
488
- ask_ct_03 INTEGER NOT NULL, ask_ct_04 INTEGER NOT NULL, ask_ct_05 INTEGER NOT NULL,
489
- ask_ct_06 INTEGER NOT NULL, ask_ct_07 INTEGER NOT NULL, ask_ct_08 INTEGER NOT NULL,
490
- ask_ct_09 INTEGER NOT NULL,
491
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
492
- PRIMARY KEY (instrument_id, ts_event, sequence)
493
- ) WITHOUT ROWID;
494
-
495
- -- Auction imbalance data sourced from Databento's `ImbalanceMsg` (imbalance schema).
496
- --
497
- -- This table captures order imbalance information disseminated by exchanges during auction
498
- -- periods, including market open, market close, and intraday auctions (such as volatility
499
- -- interruptions). Imbalance data is critical for strategies that participate in or trade
500
- -- around auction events.
501
- --
502
- -- During an auction, the exchange periodically publishes indicative prices and the imbalance
503
- -- between buy and sell interest. This information helps market participants decide whether
504
- -- to add, modify, or cancel orders before the auction concludes. The `paired_qty` represents
505
- -- orders that would execute at the reference price, while `total_imbalance_qty` shows the
506
- -- excess on one side that would remain unfilled.
507
- --
508
- -- The hypothetical clearing prices (`cont_book_clr_price`, `auct_interest_clr_price`) provide
509
- -- estimates of where the auction might clear under different matching scenarios, helping
510
- -- traders anticipate the final auction price.
511
- --
512
- -- | Field | Type | Constraints | Description |
513
- -- |-------|------|-------------|-------------|
514
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this imbalance data belongs to. Part of the composite primary key |
515
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp when the imbalance message was generated by the exchange, stored as nanoseconds since Unix epoch. Part of the composite primary key |
516
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
517
- -- | `ref_price` | INTEGER | NOT NULL | The reference price used for calculating the imbalance, typically the last traded price or a calculated indicative price, stored as fixed-point integer with $10^9$ scale factor |
518
- -- | `auction_time` | INTEGER | NOT NULL | Reserved field for future use. May contain the scheduled auction time on some venues |
519
- -- | `cont_book_clr_price` | INTEGER | NOT NULL | The hypothetical clearing price if both auction orders and continuous book orders were matched together, stored as fixed-point integer with $10^9$ scale factor |
520
- -- | `auct_interest_clr_price` | INTEGER | NOT NULL | The hypothetical clearing price if only auction-specific orders were matched (excluding continuous book), stored as fixed-point integer with $10^9$ scale factor |
521
- -- | `ssr_filling_price` | INTEGER | NOT NULL | Reserved field for short sale restriction filling price. May be used on venues with SSR rules |
522
- -- | `ind_match_price` | INTEGER | NOT NULL | Reserved field for indicative match price. May contain venue-specific indicative pricing |
523
- -- | `upper_collar` | INTEGER | NOT NULL | Reserved field for upper price collar. May contain the maximum allowed auction price on some venues |
524
- -- | `lower_collar` | INTEGER | NOT NULL | Reserved field for lower price collar. May contain the minimum allowed auction price on some venues |
525
- -- | `paired_qty` | INTEGER | NOT NULL | The quantity of shares/contracts that would be matched (paired) at the reference price if the auction were to execute now |
526
- -- | `total_imbalance_qty` | INTEGER | NOT NULL | The total quantity that cannot be paired at the reference price, representing the excess on the imbalanced side |
527
- -- | `market_imbalance_qty` | INTEGER | NOT NULL | Reserved field for market order imbalance. May contain the portion of imbalance from market orders on some venues |
528
- -- | `unpaired_qty` | INTEGER | NOT NULL | Reserved field for unpaired quantity. May contain additional unpaired order information on some venues |
529
- -- | `auction_type` | TEXT | NOT NULL | Venue-specific code indicating the type of auction (e.g., opening, closing, volatility, IPO). Interpretation varies by exchange |
530
- -- | `side` | TEXT | NOT NULL | The side with excess quantity (the imbalanced side): 'A'=Ask (more sell interest), 'B'=Bid (more buy interest), 'N'=None (balanced) |
531
- -- | `auction_status` | INTEGER | NOT NULL | Venue-specific status code indicating the current phase or state of the auction process |
532
- -- | `freeze_status` | INTEGER | NOT NULL | Venue-specific code indicating whether the auction is frozen (no new orders accepted) or still accepting modifications |
533
- -- | `num_extensions` | INTEGER | NOT NULL | The number of times the auction period has been extended, typically due to price volatility or significant order changes |
534
- -- | `unpaired_side` | TEXT | NOT NULL | The side of any unpaired quantity. May differ from `side` on venues with complex auction mechanics |
535
- -- | `significant_imbalance` | TEXT | NOT NULL | Venue-specific indicator flagging whether the imbalance is considered significant and may trigger special handling |
536
- --
537
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree
538
- -- for efficient storage of auction event data.
539
- CREATE TABLE imbalance (
540
- instrument_id INTEGER NOT NULL,
541
- ts_event INTEGER NOT NULL,
542
- ts_recv INTEGER NOT NULL,
543
- ref_price INTEGER NOT NULL,
544
- auction_time INTEGER NOT NULL,
545
- cont_book_clr_price INTEGER NOT NULL,
546
- auct_interest_clr_price INTEGER NOT NULL,
547
- ssr_filling_price INTEGER NOT NULL,
548
- ind_match_price INTEGER NOT NULL,
549
- upper_collar INTEGER NOT NULL,
550
- lower_collar INTEGER NOT NULL,
551
- paired_qty INTEGER NOT NULL,
552
- total_imbalance_qty INTEGER NOT NULL,
553
- market_imbalance_qty INTEGER NOT NULL,
554
- unpaired_qty INTEGER NOT NULL,
555
- auction_type TEXT NOT NULL,
556
- side TEXT NOT NULL CHECK(side IN ('A', 'B', 'N')),
557
- auction_status INTEGER NOT NULL,
558
- freeze_status INTEGER NOT NULL,
559
- num_extensions INTEGER NOT NULL CHECK(num_extensions >= 0),
560
- unpaired_side TEXT NOT NULL CHECK(unpaired_side IN ('A', 'B', 'N')),
561
- significant_imbalance TEXT NOT NULL,
562
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
563
- PRIMARY KEY (instrument_id, ts_event)
564
- ) WITHOUT ROWID;
565
-
566
- -- Venue statistics and reference data sourced from Databento's `StatMsg` (statistics schema).
567
- --
568
- -- This table serves as a flexible container for various statistical values disseminated by
569
- -- exchanges and data vendors. It captures a wide range of reference data including settlement
570
- -- prices, open interest, trading volumes, price limits, and other venue-specific metrics that
571
- -- don't fit into the standard market data tables.
572
- --
573
- -- The schema uses a generic structure where the `stat_type` field identifies what kind of
574
- -- statistic is being recorded, and either `price` or `quantity` contains the actual value
575
- -- depending on whether the statistic is price-based or quantity-based. This design allows
576
- -- the table to accommodate new statistic types without schema changes.
577
- --
578
- -- Common use cases include tracking daily settlement prices for futures (critical for
579
- -- mark-to-market calculations), monitoring open interest changes, and capturing exchange-
580
- -- published reference prices used for margin calculations.
581
- --
582
- -- | Field | Type | Constraints | Description |
583
- -- |-------|------|-------------|-------------|
584
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this statistic belongs to. Part of the composite primary key |
585
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp when the statistic was generated or became effective, stored as nanoseconds since Unix epoch. Part of the composite primary key |
586
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
587
- -- | `ts_ref` | INTEGER | NOT NULL | The reference timestamp that the statistic applies to (e.g., the trading date for a settlement price), stored as nanoseconds since Unix epoch |
588
- -- | `price` | INTEGER | NOT NULL | The value for price-based statistics (e.g., settlement price, high/low limits), stored as fixed-point integer with $10^9$ scale factor. Set to UNDEF_PRICE for non-price statistics |
589
- -- | `quantity` | INTEGER | NOT NULL | The value for quantity-based statistics (e.g., open interest, volume), stored as an integer. Set to UNDEF_STAT_QUANTITY for price-based statistics |
590
- -- | `sequence` | INTEGER | NOT NULL, PK | The venue's message sequence number for ordering. Part of the composite primary key to handle multiple statistics at the same timestamp |
591
- -- | `ts_in_delta` | INTEGER | NOT NULL | The latency between exchange transmission and capture receipt, calculated as `ts_recv - ts_exchange_send` in nanoseconds |
592
- -- | `stat_type` | INTEGER | NOT NULL, PK | Databento's StatType enum value identifying the type of statistic (e.g., settlement, open interest, volume). Part of the composite primary key |
593
- -- | `channel_id` | INTEGER | NOT NULL | Databento's internal channel identifier used for data routing and synchronization |
594
- -- | `update_action` | INTEGER | NOT NULL | Indicates whether this is a new statistic (1=Added) or a correction/deletion of a previous value (2=Deleted) |
595
- -- | `stat_flags` | INTEGER | NOT NULL | Additional venue-specific flags that provide context for certain statistic types (e.g., preliminary vs. final settlement) |
596
- --
597
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree
598
- -- for efficient storage and retrieval of statistical data.
599
- CREATE TABLE statistics (
600
- instrument_id INTEGER NOT NULL,
601
- ts_event INTEGER NOT NULL,
602
- ts_recv INTEGER NOT NULL,
603
- ts_ref INTEGER NOT NULL,
604
- price INTEGER NOT NULL,
605
- quantity INTEGER NOT NULL,
606
- sequence INTEGER NOT NULL,
607
- ts_in_delta INTEGER NOT NULL,
608
- stat_type INTEGER NOT NULL,
609
- channel_id INTEGER NOT NULL,
610
- update_action INTEGER NOT NULL CHECK(update_action IN (1, 2)),
611
- stat_flags INTEGER NOT NULL,
612
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
613
- PRIMARY KEY (instrument_id, ts_event, stat_type, sequence)
614
- ) WITHOUT ROWID;
615
-
616
- -- Trading status updates sourced from Databento's `StatusMsg` (status schema).
617
- --
618
- -- This table tracks changes to the trading state of instruments, including market opens,
619
- -- closes, trading halts, and regulatory restrictions. Status information is critical for
620
- -- trading systems to know when they can submit orders and when trading is suspended.
621
- --
622
- -- Trading halts can occur for various reasons including scheduled market closures, circuit
623
- -- breakers triggered by price volatility, pending news announcements, or regulatory actions.
624
- -- The `reason` field provides context for why the status changed, while `action` describes
625
- -- what type of change occurred.
626
- --
627
- -- The boolean flags (`is_trading`, `is_quoting`, `is_short_sell_restricted`) provide a
628
- -- quick way to check the current trading permissions without needing to interpret the
629
- -- venue-specific action and reason codes.
630
- --
631
- -- | Field | Type | Constraints | Description |
632
- -- |-------|------|-------------|-------------|
633
- -- | `instrument_id` | INTEGER | NOT NULL, FK, PK | Foreign key reference to `instruments.instrument_id` identifying which instrument this status update applies to. Part of the composite primary key |
634
- -- | `ts_event` | INTEGER | NOT NULL, PK | The timestamp when the status change occurred or became effective, stored as nanoseconds since Unix epoch. Part of the composite primary key |
635
- -- | `ts_recv` | INTEGER | NOT NULL | The timestamp when the message was received by Databento's capture infrastructure, stored as nanoseconds since Unix epoch |
636
- -- | `action` | INTEGER | NOT NULL | Venue-specific code indicating the type of status change (e.g., halt, resume, open, close). Interpretation varies by exchange |
637
- -- | `reason` | INTEGER | NOT NULL | Venue-specific code explaining why the status changed (e.g., scheduled close, volatility halt, news pending). Interpretation varies by exchange |
638
- -- | `trading_event` | INTEGER | NOT NULL | Venue-specific code describing the effect on trading activity (e.g., no change, trading suspended, trading resumed) |
639
- -- | `is_trading` | TEXT | NOT NULL | TriState flag indicating whether continuous trading is currently active: 'Y'=trading allowed, 'N'=trading suspended, '~'=unknown/not applicable |
640
- -- | `is_quoting` | TEXT | NOT NULL | TriState flag indicating whether market makers can submit quotes: 'Y'=quoting allowed, 'N'=quoting suspended, '~'=unknown. May differ from `is_trading` during pre-open |
641
- -- | `is_short_sell_restricted` | TEXT | NOT NULL | TriState flag indicating whether short selling restrictions are in effect (e.g., SEC Rule 201 uptick rule): 'Y'=restricted, 'N'=unrestricted, '~'=unknown |
642
- --
643
- -- Optimization: Uses `WITHOUT ROWID` to store data directly in the primary key B-tree
644
- -- for efficient storage of status event data.
645
- CREATE TABLE status (
646
- instrument_id INTEGER NOT NULL,
647
- ts_event INTEGER NOT NULL,
648
- ts_recv INTEGER NOT NULL,
649
- action INTEGER NOT NULL,
650
- reason INTEGER NOT NULL,
651
- trading_event INTEGER NOT NULL,
652
- is_trading TEXT NOT NULL CHECK(is_trading IN ('Y', 'N', '~')),
653
- is_quoting TEXT NOT NULL CHECK(is_quoting IN ('Y', 'N', '~')),
654
- is_short_sell_restricted TEXT NOT NULL CHECK(is_short_sell_restricted IN ('Y', 'N', '~')),
655
- FOREIGN KEY (instrument_id) REFERENCES instruments(instrument_id),
656
- PRIMARY KEY (instrument_id, ts_event)
657
- ) WITHOUT ROWID;
658
-
659
- -- Ticker symbol to instrument ID mappings over time sourced from Databento's symbology.json.
660
- --
661
- -- This table maps human-readable ticker symbols (e.g., "AAPL", "MSFT") to the numeric
662
- -- instrument IDs used in market data records. The mapping is time-bounded because
663
- -- instrument IDs can change over time due to:
664
- --
665
- -- - Publisher remapping: Some venues reassign numeric IDs periodically (even daily)
666
- -- - Delistings and relistings: When a symbol is delisted and later relisted, it may
667
- -- receive a new instrument ID
668
- -- - Corporate actions: Mergers, spin-offs, and ticker changes can result in new IDs
669
- --
670
- -- Each row represents a single mapping that is valid for a specific date range. To look
671
- -- up the symbol for a given instrument_id at a specific point in time, query with:
672
- --
673
- -- SELECT symbol FROM symbology
674
- -- WHERE instrument_id = ? AND date(?, 'unixepoch') BETWEEN start_date AND end_date
675
- --
676
- -- Note: The instrument_id in this table corresponds to the raw_instrument_id in the
677
- -- instruments table (the publisher's native ID), not the auto-generated instrument_id
678
- -- primary key.
679
- --
680
- -- | Field | Type | Constraints | Description |
681
- -- |-------|------|-------------|-------------|
682
- -- | `symbol` | TEXT | NOT NULL, PK | The ticker symbol as provided by the publisher (e.g., "AAPL", "ESH5"). Part of the composite primary key |
683
- -- | `instrument_id` | INTEGER | NOT NULL, PK | The numeric instrument ID assigned by the publisher. Part of the composite primary key |
684
- -- | `start_date` | TEXT | NOT NULL, PK | The first date (inclusive) when this mapping is valid, in YYYY-MM-DD format. Part of the composite primary key |
685
- -- | `end_date` | TEXT | NOT NULL | The last date (inclusive) when this mapping is valid, in YYYY-MM-DD format |
686
- CREATE TABLE symbology (
687
- symbol TEXT NOT NULL,
688
- instrument_id INTEGER NOT NULL,
689
- start_date TEXT NOT NULL,
690
- end_date TEXT NOT NULL,
691
- PRIMARY KEY (symbol, instrument_id, start_date)
692
- );
693
-
694
- -- Precomputed database metadata for fast dashboard queries.
695
- --
696
- -- This table stores aggregate statistics about the database contents that would
697
- -- otherwise require expensive COUNT(*) queries on large tables. Stats are updated
698
- -- after each data ingestion operation.
699
- --
700
- -- | Field | Type | Constraints | Description |
701
- -- |-------|------|-------------|-------------|
702
- -- | `key` | TEXT | PRIMARY KEY | The name of the statistic (e.g., 'symbol_count', 'ohlcv_record_count') |
703
- -- | `value` | TEXT | NOT NULL | The value of the statistic, stored as text for flexibility |
704
- CREATE TABLE meta (
705
- key TEXT PRIMARY KEY,
706
- value TEXT NOT NULL
707
- );
708
-
709
- -- Precomputed per-symbol coverage statistics for fast search queries.
710
- --
711
- -- This table stores aggregate statistics for each symbol/rtype combination,
712
- -- eliminating the need for expensive JOIN and GROUP BY queries on the large
713
- -- ohlcv table during symbol search. Stats are updated after each data ingestion.
714
- --
715
- -- | Field | Type | Constraints | Description |
716
- -- |-------|------|-------------|-------------|
717
- -- | `symbol` | TEXT | NOT NULL, PK | The ticker symbol |
718
- -- | `rtype` | INTEGER | NOT NULL, PK | The bar duration type (32=1s, 33=1m, 34=1h, 35=1d) |
719
- -- | `min_ts` | INTEGER | NOT NULL | The earliest timestamp for this symbol/rtype |
720
- -- | `max_ts` | INTEGER | NOT NULL | The latest timestamp for this symbol/rtype |
721
- -- | `record_count` | INTEGER | NOT NULL | Total number of records for this symbol/rtype |
722
- CREATE TABLE symbol_coverage (
723
- symbol TEXT NOT NULL,
724
- rtype INTEGER NOT NULL,
725
- min_ts INTEGER NOT NULL,
726
- max_ts INTEGER NOT NULL,
727
- record_count INTEGER NOT NULL,
728
- PRIMARY KEY (symbol, rtype)
729
- );
730
-
731
- -- User-defined symbol presets for quick selection in the dashboard.
732
- --
733
- -- | Field | Type | Constraints | Description |
734
- -- |-------|------|-------------|-------------|
735
- -- | `name` | TEXT | PRIMARY KEY | Unique name for the preset (e.g., 'Tech Stocks', 'My Watchlist') |
736
- -- | `symbols` | TEXT | NOT NULL | JSON array of symbol strings (e.g., '["AAPL", "GOOGL", "MSFT"]') |
737
- CREATE TABLE symbol_presets (
738
- name TEXT PRIMARY KEY,
739
- symbols TEXT NOT NULL
740
- );