Skip to content

Commit 76f6749

Browse files
committed
MOD: Upgrade client to databento-dbn 0.7.1
1 parent e9e9c11 commit 76f6749

30 files changed

+169
-198
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
## 0.15.0 - TBD
44

5-
### Enhancements
5+
#### Enhancements
66
- Added `symbology_map` property to `Live` client
77
- Changed `Live.add_callback` and `Live.add_stream` to accept an exception callback
8-
- Changed `Live.add_callback` and `Live.add_stream` `func` parameter to `record_callback`
8+
- Upgraded `databento-dbn` to 0.7.1
9+
- Removed `Encoding`, `Compression`, `Schema`, and `SType` enums as they are now exposed by `databento-dbn`
10+
11+
#### Breaking changes
12+
- Renamed `func` parameter to `record_callback` for `Live.add_callback` and `Live.add_stream`
913

1014
## 0.14.1 - 2023-06-16
1115

databento/__init__.py

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

4+
from databento_dbn import Compression
5+
from databento_dbn import Encoding
46
from databento_dbn import ErrorMsg
57
from databento_dbn import ImbalanceMsg
68
from databento_dbn import InstrumentDefMsg
@@ -9,25 +11,23 @@
911
from databento_dbn import MBP10Msg
1012
from databento_dbn import Metadata
1113
from databento_dbn import OHLCVMsg
14+
from databento_dbn import Schema
1215
from databento_dbn import StatMsg
16+
from databento_dbn import SType
1317
from databento_dbn import SymbolMappingMsg
1418
from databento_dbn import SystemMsg
1519
from databento_dbn import TradeMsg
1620

1721
from databento.common import bentologging
1822
from databento.common.dbnstore import DBNStore
19-
from databento.common.enums import Compression
2023
from databento.common.enums import Dataset
2124
from databento.common.enums import Delivery
22-
from databento.common.enums import Encoding
2325
from databento.common.enums import FeedMode
2426
from databento.common.enums import HistoricalGateway
2527
from databento.common.enums import Packaging
2628
from databento.common.enums import RecordFlags
2729
from databento.common.enums import RollRule
28-
from databento.common.enums import Schema
2930
from databento.common.enums import SplitDuration
30-
from databento.common.enums import SType
3131
from databento.common.enums import SymbologyResolution
3232
from databento.common.error import BentoClientError
3333
from databento.common.error import BentoError

databento/common/data.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
from __future__ import annotations
22

33
import numpy as np
4-
5-
from databento.common.enums import Schema
6-
4+
from databento_dbn import ImbalanceMsg
5+
from databento_dbn import InstrumentDefMsg
6+
from databento_dbn import MBOMsg
7+
from databento_dbn import MBP1Msg
8+
from databento_dbn import MBP10Msg
9+
from databento_dbn import OHLCVMsg
10+
from databento_dbn import Schema
11+
from databento_dbn import StatMsg
12+
from databento_dbn import TradeMsg
13+
14+
from databento.live import DBNRecord
15+
16+
17+
SCHEMA_STRUCT_MAP: dict[Schema, type[DBNRecord]] = {
18+
Schema.DEFINITION: InstrumentDefMsg,
19+
Schema.IMBALANCE: ImbalanceMsg,
20+
Schema.MBO: MBOMsg,
21+
Schema.MBP_1: MBP1Msg,
22+
Schema.MBP_10: MBP10Msg,
23+
Schema.OHLCV_1S: OHLCVMsg,
24+
Schema.OHLCV_1M: OHLCVMsg,
25+
Schema.OHLCV_1H: OHLCVMsg,
26+
Schema.OHLCV_1D: OHLCVMsg,
27+
Schema.STATISTICS: StatMsg,
28+
Schema.TBBO: MBP1Msg,
29+
Schema.TRADES: TradeMsg,
30+
}
731

832
################################################################################
933
# DBN struct schema

databento/common/dbnstore.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
import numpy as np
2020
import pandas as pd
2121
import zstandard
22+
from databento_dbn import Compression
2223
from databento_dbn import DBNDecoder
2324
from databento_dbn import ErrorMsg
2425
from databento_dbn import Metadata
26+
from databento_dbn import Schema
27+
from databento_dbn import SType
2528
from databento_dbn import SymbolMappingMsg
2629
from databento_dbn import SystemMsg
2730

@@ -30,10 +33,8 @@
3033
from databento.common.data import DEFINITION_PRICE_COLUMNS
3134
from databento.common.data import DEFINITION_TYPE_MAX_MAP
3235
from databento.common.data import DERIV_SCHEMAS
36+
from databento.common.data import SCHEMA_STRUCT_MAP
3337
from databento.common.data import STRUCT_MAP
34-
from databento.common.enums import Compression
35-
from databento.common.enums import Schema
36-
from databento.common.enums import SType
3738
from databento.common.error import BentoError
3839
from databento.common.symbology import InstrumentIdMappingInterval
3940
from databento.common.validation import validate_maybe_enum
@@ -1059,7 +1060,7 @@ def to_ndarray(
10591060
schema = self.schema
10601061

10611062
schema_records = filter(
1062-
lambda r: isinstance(r, schema.get_record_type()), # type: ignore
1063+
lambda r: isinstance(r, SCHEMA_STRUCT_MAP[schema]), # type: ignore
10631064
self,
10641065
)
10651066

databento/common/enums.py

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
from enum import unique
77
from typing import Callable, TypeVar
88

9-
from databento_dbn import ImbalanceMsg
10-
from databento_dbn import InstrumentDefMsg
11-
from databento_dbn import MBOMsg
12-
from databento_dbn import MBP1Msg
13-
from databento_dbn import MBP10Msg
14-
from databento_dbn import OHLCVMsg
15-
from databento_dbn import StatMsg
16-
from databento_dbn import TradeMsg
17-
18-
from databento.live import DBNRecord
19-
209

2110
M = TypeVar("M", bound=Enum)
2211

@@ -71,7 +60,7 @@ def _cast_str(value: object) -> str:
7160

7261
def coerced_new(enum: type[M], value: object) -> M:
7362
if value is None:
74-
raise TypeError(
63+
raise ValueError(
7564
f"value `{value}` is not coercible to {enum_type.__name__}.",
7665
)
7766
try:
@@ -111,7 +100,6 @@ def __str__(self) -> str:
111100
return getattr(self, "name").lower()
112101
return getattr(self, "value")
113102

114-
115103
@unique
116104
@coercible
117105
class HistoricalGateway(StringyMixin, str, Enum):
@@ -145,77 +133,6 @@ class Dataset(StringyMixin, str, Enum):
145133
XNAS_ITCH = "XNAS.ITCH"
146134

147135

148-
@unique
149-
@coercible
150-
class Schema(StringyMixin, str, Enum):
151-
"""
152-
Represents a data record schema.
153-
"""
154-
155-
MBO = "mbo"
156-
MBP_1 = "mbp-1"
157-
MBP_10 = "mbp-10"
158-
TBBO = "tbbo"
159-
TRADES = "trades"
160-
OHLCV_1S = "ohlcv-1s"
161-
OHLCV_1M = "ohlcv-1m"
162-
OHLCV_1H = "ohlcv-1h"
163-
OHLCV_1D = "ohlcv-1d"
164-
DEFINITION = "definition"
165-
IMBALANCE = "imbalance"
166-
STATISTICS = "statistics"
167-
168-
def get_record_type(self) -> type[DBNRecord]:
169-
if self == Schema.MBO:
170-
return MBOMsg
171-
if self == Schema.MBP_1:
172-
return MBP1Msg
173-
if self == Schema.MBP_10:
174-
return MBP10Msg
175-
if self == Schema.TBBO:
176-
return MBP1Msg
177-
if self == Schema.TRADES:
178-
return TradeMsg
179-
if self == Schema.OHLCV_1S:
180-
return OHLCVMsg
181-
if self == Schema.OHLCV_1M:
182-
return OHLCVMsg
183-
if self == Schema.OHLCV_1H:
184-
return OHLCVMsg
185-
if self == Schema.OHLCV_1D:
186-
return OHLCVMsg
187-
if self == Schema.DEFINITION:
188-
return InstrumentDefMsg
189-
if self == Schema.IMBALANCE:
190-
return ImbalanceMsg
191-
if self == Schema.STATISTICS:
192-
return StatMsg
193-
raise NotImplementedError(f"No message type for {self}")
194-
195-
196-
@unique
197-
@coercible
198-
class Encoding(StringyMixin, str, Enum):
199-
"""
200-
Represents a data output encoding.
201-
"""
202-
203-
DBN = "dbn"
204-
CSV = "csv"
205-
JSON = "json"
206-
207-
208-
@unique
209-
@coercible
210-
class Compression(StringyMixin, str, Enum):
211-
"""
212-
Represents a data compression format (if any).
213-
"""
214-
215-
NONE = "none"
216-
ZSTD = "zstd"
217-
218-
219136
@unique
220137
@coercible
221138
class SplitDuration(StringyMixin, str, Enum):
@@ -253,19 +170,6 @@ class Delivery(StringyMixin, str, Enum):
253170
DISK = "disk"
254171

255172

256-
@unique
257-
@coercible
258-
class SType(StringyMixin, str, Enum):
259-
"""
260-
Represents a symbology type.
261-
"""
262-
263-
INSTRUMENT_ID = "instrument_id"
264-
RAW_SYMBOL = "raw_symbol"
265-
PARENT = "parent"
266-
CONTINUOUS = "continuous"
267-
268-
269173
@unique
270174
@coercible
271175
class RollRule(StringyMixin, str, Enum):

databento/common/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from numbers import Number
88

99
import pandas as pd
10+
from databento_dbn import SType
1011

11-
from databento.common.enums import SType
1212
from databento.common.symbology import ALL_SYMBOLS
1313
from databento.common.validation import validate_smart_symbol
1414

databento/common/validation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ def validate_enum(
6969
try:
7070
return enum(value)
7171
except ValueError as e:
72-
valid = list(map(str, enum))
72+
if hasattr(enum, "variants"):
73+
valid = list(map(str, enum.variants())) # type: ignore [attr-defined]
74+
else:
75+
valid = list(map(str, enum))
76+
7377
raise ValueError(
7478
f"The `{param}` was not a valid value of {enum}, was '{value}'. "
7579
f"Use any of {valid}.",

databento/historical/api/batch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
import aiohttp
1111
import pandas as pd
1212
import requests
13+
from databento_dbn import Compression
14+
from databento_dbn import Encoding
15+
from databento_dbn import Schema
16+
from databento_dbn import SType
1317
from requests.auth import HTTPBasicAuth
1418

15-
from databento.common.enums import Compression
1619
from databento.common.enums import Dataset
1720
from databento.common.enums import Delivery
18-
from databento.common.enums import Encoding
1921
from databento.common.enums import Packaging
20-
from databento.common.enums import Schema
2122
from databento.common.enums import SplitDuration
22-
from databento.common.enums import SType
2323
from databento.common.parsing import datetime_to_string
2424
from databento.common.parsing import optional_datetime_to_string
2525
from databento.common.parsing import optional_symbols_list_to_string

databento/historical/api/metadata.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from typing import Any
55

66
import pandas as pd
7+
from databento_dbn import Encoding
8+
from databento_dbn import Schema
9+
from databento_dbn import SType
710
from requests import Response
811

912
from databento.common.enums import Dataset
10-
from databento.common.enums import Encoding
1113
from databento.common.enums import FeedMode
12-
from databento.common.enums import Schema
13-
from databento.common.enums import SType
1414
from databento.common.parsing import datetime_to_string
1515
from databento.common.parsing import optional_date_to_string
1616
from databento.common.parsing import optional_datetime_to_string
@@ -145,15 +145,15 @@ def list_fields(
145145
A mapping of dataset to encoding to schema to field to data type.
146146
147147
"""
148-
params: list[tuple[str, str | None]] = [
148+
params: list[tuple[str, Dataset | Schema | Encoding | str | None]] = [
149149
("dataset", validate_semantic_string(dataset, "dataset")),
150150
("schema", validate_maybe_enum(schema, Schema, "schema")),
151151
("encoding", validate_maybe_enum(encoding, Encoding, "encoding")),
152152
]
153153

154154
response: Response = self._get(
155155
url=self._base_url + ".list_fields",
156-
params=params,
156+
params=params, # type: ignore [arg-type]
157157
basic_auth=True,
158158
)
159159
return response.json()
@@ -185,15 +185,15 @@ def list_unit_prices(
185185
Otherwise, return a map of feed mode to schema to unit price.
186186
187187
"""
188-
params: list[tuple[str, str | None]] = [
188+
params: list[tuple[str, Dataset | FeedMode | Schema | str | None]] = [
189189
("dataset", validate_semantic_string(dataset, "dataset")),
190190
("mode", validate_maybe_enum(mode, FeedMode, "mode")),
191191
("schema", validate_maybe_enum(schema, Schema, "schema")),
192192
]
193193

194194
response: Response = self._get(
195195
url=self._base_url + ".list_unit_prices",
196-
params=params,
196+
params=params, # type: ignore [arg-type]
197197
basic_auth=True,
198198
)
199199
return response.json()

databento/historical/api/symbology.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from datetime import date
44
from typing import Any
55

6+
from databento_dbn import SType
67
from requests import Response
78

89
from databento.common.enums import Dataset
9-
from databento.common.enums import SType
1010
from databento.common.parsing import datetime_to_date_string
1111
from databento.common.parsing import optional_date_to_string
1212
from databento.common.parsing import optional_symbols_list_to_string

0 commit comments

Comments
 (0)