Skip to content

Commit 1eb7dfb

Browse files
committed
ADD: Support for imbalance schema
1 parent fc63f9d commit 1eb7dfb

17 files changed

+47
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Removed `related` and `related_security_id` from definition schema
99
- Added `instrument_class`, `strike_price`, and `strike_price_currency` to definition
1010
schema
11+
- Added support for `imbalance` schema
1112

1213
## 0.9.0 - 2023-03-10
1314
- Removed `record_count` property from Bento class

databento/common/data.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,30 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
154154
("dummy", "S3"), # 3 byte chararray (Adjustment filler for 8-bytes alignment)
155155
]
156156

157+
IMBALANCE_MSG: List[Tuple[str, Union[type, str]]] = RECORD_HEADER + [
158+
("ts_recv", np.uint64),
159+
("ref_price", np.int64),
160+
("auction_time", np.uint64),
161+
("cont_book_clr_price", np.int64),
162+
("auct_interest_clr_price", np.int64),
163+
("ssr_filling_price", np.int64),
164+
("ind_match_price", np.int64),
165+
("upper_collar", np.int64),
166+
("lower_collar", np.int64),
167+
("paired_qty", np.uint32),
168+
("total_imbalance_qty", np.uint32),
169+
("market_imbalance_qty", np.uint32),
170+
("unpaired_qty", np.uint32),
171+
("auction_type", "S1"),
172+
("side", "S1"),
173+
("auction_status", np.uint8),
174+
("freeze_status", np.uint8),
175+
("num_extensions", np.uint8),
176+
("unpaired_side", "S1"),
177+
("significant_imbalance", "S1"),
178+
("dummy", "S1"),
179+
]
180+
157181

158182
STRUCT_MAP: Dict[Schema, List[Tuple[str, Union[type, str]]]] = {
159183
Schema.MBO: MBO_MSG,
@@ -177,6 +201,7 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
177201
Schema.OHLCV_1D: OHLCV_MSG,
178202
Schema.STATUS: STATUS_MSG,
179203
Schema.DEFINITION: DEFINITION_MSG,
204+
Schema.IMBALANCE: IMBALANCE_MSG,
180205
Schema.GATEWAY_ERROR: RECORD_HEADER
181206
+ [
182207
("error", "S64"),
@@ -277,6 +302,13 @@ def get_deriv_ba_fields(level: int) -> List[str]:
277302
"dummy",
278303
]
279304

305+
IMBALANCE_DROP_COLUMNS = [
306+
"ts_recv",
307+
"length",
308+
"rtype",
309+
"dummy",
310+
]
311+
280312
STATUS_COLUMNS = [
281313
x for x in (np.dtype(STATUS_MSG).names or ()) if x not in STATUS_DROP_COLUMNS
282314
]
@@ -287,6 +319,10 @@ def get_deriv_ba_fields(level: int) -> List[str]:
287319
if x not in DEFINITION_DROP_COLUMNS
288320
]
289321

322+
IMBALANCE_COLUMNS = [
323+
x for x in (np.dtype(IMBALANCE_MSG).names or ()) if x not in IMBALANCE_DROP_COLUMNS
324+
]
325+
290326

291327
COLUMNS = {
292328
Schema.MBO: [
@@ -323,4 +359,5 @@ def get_deriv_ba_fields(level: int) -> List[str]:
323359
Schema.OHLCV_1D: OHLCV_HEADER_COLUMNS,
324360
Schema.STATUS: STATUS_COLUMNS,
325361
Schema.DEFINITION: DEFINITION_COLUMNS,
362+
Schema.IMBALANCE: IMBALANCE_COLUMNS,
326363
}

databento/common/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class Schema(StringyMixin, str, Enum):
149149
OHLCV_1H = "ohlcv-1h"
150150
OHLCV_1D = "ohlcv-1d"
151151
DEFINITION = "definition"
152+
IMBALANCE = "imbalance"
152153
STATISTICS = "statistics"
153154
STATUS = "status"
154155
GATEWAY_ERROR = "gateway_error"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
aiohttp>=3.7.2,<4.0.0
2-
databento-dbn==0.3.2
2+
databento-dbn==0.4.0
33
numpy>=1.17.0
44
pandas>=1.1.3
55
requests>=2.24.0
23 Bytes
Binary file not shown.
209 Bytes
Binary file not shown.

tests/data/test_data.mbo.dbn.zst

10 Bytes
Binary file not shown.

tests/data/test_data.mbp-1.dbn.zst

9 Bytes
Binary file not shown.
23 Bytes
Binary file not shown.
-1 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)