Skip to content

Commit 38dc9c9

Browse files
committed
ADD: Add Python Live Client
1 parent 40e776f commit 38dc9c9

27 files changed

+4132
-392
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
# Changelog
22

33
## 0.12.0 - TBD
4+
- Added `Live` client for connecting to Databento's live service
45
- Upgraded `databento-dbn` to 0.5.0
6+
- Upgraded `DBNStore` to support mixed schema types to support live data
7+
- Changed iteration `DBNStore` to return record types from `databento-dbn` instead of numpy arrays
8+
- Removed `dtype` property from `DBNStore`
9+
- Removed `record_size` property from `DBNStore`
510
- Renamed the `cost` field to `cost_usd` for `batch.submit_job` and `batch.list_jobs` (value now expressed as US dollars)
611
- Removed `bad` condition variant from `batch.get_dataset_condition`
712
- Added `degraded`, `pending` and `missing` condition variants for `batch.get_dataset_condition`
813
- Added `last_modified_date` field to `batch.get_dataset_condition` response
14+
- Deprecated `SType.PRODUCT_ID` to `SType.INSTRUMENT_ID`
15+
- Deprecated `SType.NATIVE` to `SType.RAW_SYMBOL`
16+
- Deprecated `SType.SMART` to `SType.PARENT` and `SType.CONTINUOUS`
17+
- Removed unused `LiveGateway` enum
18+
- Removed `STATSTICS` from `Schema` enum
19+
- Removed `STATUS` from `Schema` enum
20+
- Removed `GATEWAY_ERROR` from `Schema` enum
21+
- Removed `SYMBOL_MAPPING` from `Schema` enum
922

1023
## 0.11.0 - 2023-04-13
1124
- Changed `end` and `end_date` to optional to support new forward-fill behaviour

databento/__init__.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import warnings
33

4-
from databento.common import utility
4+
from databento.common import bentologging
55
from databento.common.dbnstore import DBNStore
66
from databento.common.enums import (
77
Compression,
@@ -10,7 +10,6 @@
1010
Encoding,
1111
FeedMode,
1212
HistoricalGateway,
13-
LiveGateway,
1413
Packaging,
1514
RecordFlags,
1615
RollRule,
@@ -27,12 +26,28 @@
2726
)
2827
from databento.historical.api import API_VERSION
2928
from databento.historical.client import Historical
29+
from databento.live.client import Live
30+
from databento.live.dbn import DBNRecord
3031
from databento.version import __version__ # noqa
32+
from databento_dbn import (
33+
ErrorMsg,
34+
ImbalanceMsg,
35+
InstrumentDefMsg,
36+
MBOMsg,
37+
MBP1Msg,
38+
MBP10Msg,
39+
Metadata,
40+
OHLCVMsg,
41+
SymbolMappingMsg,
42+
SystemMsg,
43+
TradeMsg,
44+
)
3145

3246

3347
__all__ = [
3448
"API_VERSION",
3549
"DBNStore",
50+
"DBNRecord",
3651
"BentoClientError",
3752
"BentoError",
3853
"BentoHttpError",
@@ -45,13 +60,25 @@
4560
"RecordFlags",
4661
"Historical",
4762
"HistoricalGateway",
48-
"LiveGateway",
63+
"Live",
4964
"Packaging",
5065
"RollRule",
5166
"Schema",
5267
"SplitDuration",
5368
"SType",
5469
"SymbologyResolution",
70+
# DBN Record Types
71+
"Metadata",
72+
"MBOMsg",
73+
"MBP1Msg",
74+
"MBP10Msg",
75+
"TradeMsg",
76+
"OHLCVMsg",
77+
"InstrumentDefMsg",
78+
"ImbalanceMsg",
79+
"ErrorMsg",
80+
"SystemMsg",
81+
"SymbolMappingMsg",
5582
]
5683

5784
# Setup logging
@@ -61,5 +88,5 @@
6188
warnings.simplefilter("always", DeprecationWarning)
6289

6390
# Convenience imports
64-
enable_logging = utility.enable_logging
91+
enable_logging = bentologging.enable_logging
6592
from_dbn = DBNStore.from_file

databento/common/cram.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""Functions for handling challenge-response authentication"""
2+
import argparse
3+
import hashlib
4+
import os
5+
import sys
6+
7+
8+
BUCKET_ID_LENGTH = 5
9+
10+
11+
def get_challenge_response(challenge: str, key: str) -> str:
12+
"""
13+
Return the response for a given challenge-response
14+
authentication mechanism (CRAM) code provided by
15+
a Databento service.
16+
17+
A valid API key is hashed with the challenge string.
18+
19+
Parameters
20+
----------
21+
challenge : str
22+
The CRAM challenge string.
23+
key : str
24+
The user API key for authentication.
25+
26+
Returns
27+
-------
28+
str
29+
30+
"""
31+
bucket_id = key[-BUCKET_ID_LENGTH:]
32+
sha = hashlib.sha256(f"{challenge}|{key}".encode("utf-8")).hexdigest()
33+
return f"{sha}-{bucket_id}"
34+
35+
36+
if __name__ == "__main__":
37+
parser = argparse.ArgumentParser(
38+
description="Script for computing a CRAM response.",
39+
)
40+
parser.add_argument(
41+
"challenge",
42+
help="The CRAM challenge string",
43+
)
44+
parser.add_argument(
45+
"key",
46+
nargs="?",
47+
default=os.environ.get("DATABENTO_API_KEY"),
48+
help="An API key; defaults to the value of DATABENTO_API_KEY if set",
49+
)
50+
arguments = parser.parse_args(sys.argv[1:])
51+
52+
if arguments.key is None:
53+
parser.print_usage()
54+
exit(1)
55+
56+
print(
57+
get_challenge_response(
58+
challenge=arguments.challenge,
59+
key=arguments.key,
60+
),
61+
)

databento/common/data.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
7878
("volume", np.int64),
7979
]
8080

81-
STATUS_MSG: List[Tuple[str, Union[type, str]]] = RECORD_HEADER + [
82-
("ts_recv", np.uint64),
83-
("group", "S1"), # 1 byte chararray
84-
("trading_status", np.uint8),
85-
("halt_reason", np.uint8),
86-
("trading_event", np.uint8),
87-
]
88-
8981
DEFINITION_MSG: List[Tuple[str, Union[type, str]]] = RECORD_HEADER + [
9082
("ts_recv", np.uint64),
9183
("min_price_increment", np.int64),
@@ -199,23 +191,11 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
199191
Schema.OHLCV_1M: OHLCV_MSG,
200192
Schema.OHLCV_1H: OHLCV_MSG,
201193
Schema.OHLCV_1D: OHLCV_MSG,
202-
Schema.STATUS: STATUS_MSG,
203194
Schema.DEFINITION: DEFINITION_MSG,
204195
Schema.IMBALANCE: IMBALANCE_MSG,
205-
Schema.GATEWAY_ERROR: RECORD_HEADER
206-
+ [
207-
("error", "S64"),
208-
],
209-
Schema.SYMBOL_MAPPING: RECORD_HEADER
210-
+ [
211-
("stype_in_symbol", "S22"),
212-
("stype_out_symbol", "S22"),
213-
("dummy", "S4"),
214-
("start_ts", np.uint64),
215-
("end_ts", np.uint64),
216-
],
217196
}
218197

198+
219199
DEFINITION_CHARARRAY_COLUMNS = [
220200
"currency",
221201
"settl_currency",
@@ -291,7 +271,6 @@ def get_deriv_ba_fields(level: int) -> List[str]:
291271
"volume",
292272
]
293273

294-
STATUS_DROP_COLUMNS = ["ts_recv"]
295274
DEFINITION_DROP_COLUMNS = [
296275
"ts_recv",
297276
"length",
@@ -309,10 +288,6 @@ def get_deriv_ba_fields(level: int) -> List[str]:
309288
"dummy",
310289
]
311290

312-
STATUS_COLUMNS = [
313-
x for x in (np.dtype(STATUS_MSG).names or ()) if x not in STATUS_DROP_COLUMNS
314-
]
315-
316291
DEFINITION_COLUMNS = [
317292
x
318293
for x in (np.dtype(DEFINITION_MSG).names or ())
@@ -323,7 +298,6 @@ def get_deriv_ba_fields(level: int) -> List[str]:
323298
x for x in (np.dtype(IMBALANCE_MSG).names or ()) if x not in IMBALANCE_DROP_COLUMNS
324299
]
325300

326-
327301
COLUMNS = {
328302
Schema.MBO: [
329303
"ts_event",
@@ -357,7 +331,6 @@ def get_deriv_ba_fields(level: int) -> List[str]:
357331
Schema.OHLCV_1M: OHLCV_HEADER_COLUMNS,
358332
Schema.OHLCV_1H: OHLCV_HEADER_COLUMNS,
359333
Schema.OHLCV_1D: OHLCV_HEADER_COLUMNS,
360-
Schema.STATUS: STATUS_COLUMNS,
361334
Schema.DEFINITION: DEFINITION_COLUMNS,
362335
Schema.IMBALANCE: IMBALANCE_COLUMNS,
363336
}

0 commit comments

Comments
 (0)