Skip to content

Commit 09fcabc

Browse files
committed
MOD: Rename STypes across bento (python+multidocs)
1 parent 22a4b99 commit 09fcabc

18 files changed

+169
-142
lines changed

databento/common/data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
4040
("length", np.uint8),
4141
("rtype", np.uint8),
4242
("publisher_id", np.uint16),
43-
("product_id", np.uint32),
43+
("instrument_id", np.uint32),
4444
("ts_event", np.uint64),
4545
]
4646

@@ -271,7 +271,7 @@ def get_deriv_ba_fields(level: int) -> List[str]:
271271
"ts_event",
272272
"ts_in_delta",
273273
"publisher_id",
274-
"product_id",
274+
"instrument_id",
275275
"action",
276276
"side",
277277
"depth",
@@ -283,7 +283,7 @@ def get_deriv_ba_fields(level: int) -> List[str]:
283283

284284
OHLCV_HEADER_COLUMNS = [
285285
"publisher_id",
286-
"product_id",
286+
"instrument_id",
287287
"open",
288288
"high",
289289
"low",
@@ -330,7 +330,7 @@ def get_deriv_ba_fields(level: int) -> List[str]:
330330
"ts_in_delta",
331331
"publisher_id",
332332
"channel_id",
333-
"product_id",
333+
"instrument_id",
334334
"order_id",
335335
"action",
336336
"side",

databento/common/dbnstore.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from databento.common.enums import Compression, Schema, SType
3333
from databento.common.error import BentoError
3434
from databento.common.metadata import MetadataDecoder
35-
from databento.common.symbology import ProductIdMappingInterval
35+
from databento.common.symbology import InstrumentIdMappingInterval
3636

3737

3838
logger = logging.getLogger(__name__)
@@ -339,7 +339,7 @@ def __init__(self, data_source: DataSource) -> None:
339339
)
340340

341341
# This is populated when _map_symbols is called
342-
self._product_id_index: Dict[
342+
self._instrument_id_index: Dict[
343343
dt.date,
344344
Dict[int, str],
345345
] = {}
@@ -392,19 +392,19 @@ def _apply_pretty_px(self, df: pd.DataFrame) -> pd.DataFrame:
392392

393393
return df
394394

395-
def _build_product_id_index(self) -> Dict[dt.date, Dict[int, str]]:
396-
intervals: List[ProductIdMappingInterval] = []
397-
for native, i in self.mappings.items():
395+
def _build_instrument_id_index(self) -> Dict[dt.date, Dict[int, str]]:
396+
intervals: List[InstrumentIdMappingInterval] = []
397+
for raw_symbol, i in self.mappings.items():
398398
for row in i:
399399
symbol = row["symbol"]
400400
if symbol == "":
401401
continue
402402
intervals.append(
403-
ProductIdMappingInterval(
403+
InstrumentIdMappingInterval(
404404
start_date=row["start_date"],
405405
end_date=row["end_date"],
406-
native=native,
407-
product_id=int(row["symbol"]),
406+
raw_symbol=raw_symbol,
407+
instrument_id=int(row["symbol"]),
408408
),
409409
)
410410

@@ -420,7 +420,7 @@ def _build_product_id_index(self) -> Dict[dt.date, Dict[int, str]]:
420420
date_map: Dict[int, str] = product_id_index.get(d, {})
421421
if not date_map:
422422
product_id_index[d] = date_map
423-
date_map[interval.product_id] = interval.native
423+
date_map[interval.instrument_id] = interval.raw_symbol
424424

425425
return product_id_index
426426

@@ -457,17 +457,17 @@ def _get_index_column(self) -> str:
457457
)
458458

459459
def _map_symbols(self, df: pd.DataFrame, pretty_ts: bool) -> pd.DataFrame:
460-
# Build product ID index
461-
if not self._product_id_index:
462-
self._product_id_index = self._build_product_id_index()
460+
# Build instrument ID index
461+
if not self._instrument_id_index:
462+
self._instrument_id_index = self._build_instrument_id_index()
463463

464-
# Map product IDs to native symbols
465-
if self._product_id_index:
464+
# Map instrument IDs to raw symbols
465+
if self._instrument_id_index:
466466
df_index = df.index if pretty_ts else pd.to_datetime(df.index, utc=True)
467467
dates = [ts.date() for ts in df_index]
468468
df["symbol"] = [
469-
self._product_id_index[dates[i]][p]
470-
for i, p in enumerate(df["product_id"])
469+
self._instrument_id_index[dates[i]][p]
470+
for i, p in enumerate(df["instrument_id"])
471471
]
472472

473473
return df
@@ -864,7 +864,7 @@ def to_csv(
864864
the correct scale (using the fixed precision scalar 1e-9).
865865
map_symbols : bool, default True
866866
If symbology mappings from the metadata should be used to create
867-
a 'symbol' column, mapping the product ID to its native symbol for
867+
a 'symbol' column, mapping the instrument ID to its native symbol for
868868
every record.
869869
870870
Notes
@@ -897,7 +897,7 @@ def to_df(
897897
the correct scale (using the fixed precision scalar 1e-9).
898898
map_symbols : bool, default True
899899
If symbology mappings from the metadata should be used to create
900-
a 'symbol' column, mapping the product ID to its native symbol for
900+
a 'symbol' column, mapping the instrument ID to its native symbol for
901901
every record.
902902
903903
Returns
@@ -955,7 +955,7 @@ def to_json(
955955
the correct scale (using the fixed precision scalar 1e-9).
956956
map_symbols : bool, default True
957957
If symbology mappings from the metadata should be used to create
958-
a 'symbol' column, mapping the product ID to its native symbol for
958+
a 'symbol' column, mapping the instrument ID to its native symbol for
959959
every record.
960960
961961
Notes

databento/common/enums.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,13 @@ class Delivery(StringyMixin, str, Enum):
211211
class SType(StringyMixin, str, Enum):
212212
"""Represents a symbology type."""
213213

214-
PRODUCT_ID = "product_id"
215-
NATIVE = "native"
216-
SMART = "smart"
214+
PRODUCT_ID = "product_id" # Deprecated for `instrument_id`
215+
NATIVE = "native" # Deprecated for `raw_symbol`
216+
SMART = "smart" # Deprecated for `parent` and `continuous`
217+
INSTRUMENT_ID = "instrument_id"
218+
RAW_SYMBOL = "raw_symbol"
219+
PARENT = "parent"
220+
CONTINUOUS = "continuous"
217221

218222

219223
@unique

databento/common/metadata.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Dict
22

3+
from databento.common.enums import SType
34
from databento_dbn import decode_metadata
45

56

@@ -38,4 +39,25 @@ def decode_to_json(raw_metadata: bytes) -> Dict[str, object]:
3839
value = conversion_mapping[field](value)
3940
metadata_dict[field] = value
4041

42+
# TODO(cs): Temporary mappings until new DBN released
43+
stype_in = metadata_dict["stype_in"]
44+
stype_out = metadata_dict["stype_out"]
45+
46+
if stype_in == SType.NATIVE.value:
47+
stype_in = SType.RAW_SYMBOL.value
48+
elif stype_in == SType.PRODUCT_ID.value:
49+
stype_in = SType.INSTRUMENT_ID.value
50+
else:
51+
stype_in = SType.SMART.value
52+
53+
if stype_out == SType.NATIVE.value:
54+
stype_out = SType.INSTRUMENT_ID.value
55+
elif stype_out == SType.PRODUCT_ID.value:
56+
stype_out = SType.INSTRUMENT_ID.value
57+
else:
58+
stype_out = SType.SMART.value
59+
60+
metadata_dict["stype_in"] = stype_in
61+
metadata_dict["stype_out"] = stype_out
62+
4163
return metadata_dict

databento/common/parsing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def _(symbols: int, stype_in: SType) -> str:
109109
optional_symbols_list_to_string
110110
111111
"""
112-
if stype_in == SType.PRODUCT_ID:
112+
if stype_in == SType.INSTRUMENT_ID:
113113
return str(symbols)
114114
raise ValueError(
115115
f"value `{symbols}` is not a valid symbol for stype {stype_in}; "
116-
"did you mean to use `product_id`?",
116+
"did you mean to use `instrument_id`?",
117117
)
118118

119119

@@ -142,7 +142,8 @@ def _(symbols: str, stype_in: SType) -> str:
142142
symbol_list = symbols.strip().strip(",").split(",")
143143
return ",".join(map(symbol_to_string, symbol_list))
144144

145-
if stype_in == SType.SMART:
145+
# TODO(cs): Temporary mapping until new DBN released
146+
if stype_in in (SType.SMART, SType.CONTINUOUS):
146147
return validate_smart_symbol(symbols)
147148
return symbols.strip().upper()
148149

databento/common/symbology.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77

88
@dataclass(frozen=True)
9-
class ProductIdMappingInterval:
9+
class InstrumentIdMappingInterval:
1010
"""
11-
Represents a product ID to native symbol mapping over a start and end date
11+
Represents an instrument ID to raw symbol mapping over a start and end date
1212
range interval.
1313
1414
Parameters
@@ -17,13 +17,13 @@ class ProductIdMappingInterval:
1717
The start of the mapping period.
1818
end_date : dt.date
1919
The end of the mapping period.
20-
native : str
20+
raw_symbol : str
2121
The native symbol value.
22-
product_id : int
23-
The product ID value.
22+
instrument_id : int
23+
The instrument ID value.
2424
"""
2525

2626
start_date: dt.date
2727
end_date: dt.date
28-
native: str
29-
product_id: int
28+
raw_symbol: str
29+
instrument_id: int

databento/historical/api/batch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def submit_job(
6565
split_size: Optional[int] = None,
6666
packaging: Optional[Union[Packaging, str]] = None,
6767
delivery: Union[Delivery, str] = "download",
68-
stype_in: Union[SType, str] = "native",
69-
stype_out: Union[SType, str] = "product_id",
68+
stype_in: Union[SType, str] = "raw_symbol",
69+
stype_out: Union[SType, str] = "instrument_id",
7070
limit: Optional[int] = None,
7171
) -> Dict[str, Any]:
7272
"""
@@ -107,9 +107,9 @@ def submit_job(
107107
The archive type to package all batched data files in.
108108
delivery : Delivery or str {'download', 's3', 'disk'}, default 'download'
109109
The delivery mechanism for the processed batched data files.
110-
stype_in : SType or str, default 'native'
110+
stype_in : SType or str, default 'raw_symbol'
111111
The input symbology type to resolve from.
112-
stype_out : SType or str, default 'product_id'
112+
stype_out : SType or str, default 'instrument_id'
113113
The output symbology type to resolve to.
114114
limit : int, optional
115115
The maximum number of records to return. If `None` then no limit.

databento/historical/api/metadata.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def get_record_count(
276276
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
277277
symbols: Optional[Union[List[str], str]] = None,
278278
schema: Union[Schema, str] = "trades",
279-
stype_in: Optional[Union[SType, str]] = "native",
279+
stype_in: Optional[Union[SType, str]] = "raw_symbol",
280280
limit: Optional[int] = None,
281281
) -> int:
282282
"""
@@ -303,7 +303,7 @@ def get_record_count(
303303
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.
304304
schema : Schema or str {'mbo', 'mbp-1', 'mbp-10', 'trades', 'tbbo', 'ohlcv-1s', 'ohlcv-1m', 'ohlcv-1h', 'ohlcv-1d', 'definition', 'statistics', 'status'}, default 'trades' # noqa
305305
The data record schema for the request.
306-
stype_in : SType or str, default 'native'
306+
stype_in : SType or str, default 'raw_symbol'
307307
The input symbology type to resolve from.
308308
limit : int, optional
309309
The maximum number of records to return. If `None` then no limit.
@@ -344,7 +344,7 @@ def get_billable_size(
344344
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
345345
symbols: Optional[Union[List[str], str]] = None,
346346
schema: Union[Schema, str] = "trades",
347-
stype_in: Optional[Union[SType, str]] = "native",
347+
stype_in: Optional[Union[SType, str]] = "raw_symbol",
348348
limit: Optional[int] = None,
349349
) -> int:
350350
"""
@@ -372,7 +372,7 @@ def get_billable_size(
372372
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.
373373
schema : Schema or str {'mbo', 'mbp-1', 'mbp-10', 'trades', 'tbbo', 'ohlcv-1s', 'ohlcv-1m', 'ohlcv-1h', 'ohlcv-1d', 'definition', 'statistics', 'status'}, default 'trades' # noqa
374374
The data record schema for the request.
375-
stype_in : SType or str, default 'native'
375+
stype_in : SType or str, default 'raw_symbol'
376376
The input symbology type to resolve from.
377377
limit : int, optional
378378
The maximum number of records to return. If `None` then no limit.
@@ -392,7 +392,7 @@ def get_billable_size(
392392
("symbols", symbols_list),
393393
("schema", str(validate_enum(schema, Schema, "schema"))),
394394
("stype_in", str(stype_in_valid)),
395-
("stype_out", str(SType.PRODUCT_ID)),
395+
("stype_out", str(SType.INSTRUMENT_ID)),
396396
]
397397

398398
if limit is not None:
@@ -414,7 +414,7 @@ def get_cost(
414414
mode: Union[FeedMode, str] = "historical-streaming",
415415
symbols: Optional[Union[List[str], str]] = None,
416416
schema: Union[Schema, str] = "trades",
417-
stype_in: Optional[Union[SType, str]] = "native",
417+
stype_in: Optional[Union[SType, str]] = "raw_symbol",
418418
limit: Optional[int] = None,
419419
) -> float:
420420
"""
@@ -444,7 +444,7 @@ def get_cost(
444444
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.
445445
schema : Schema or str {'mbo', 'mbp-1', 'mbp-10', 'trades', 'tbbo', 'ohlcv-1s', 'ohlcv-1m', 'ohlcv-1h', 'ohlcv-1d', 'definition', 'statistics', 'status'}, default 'trades' # noqa
446446
The data record schema for the request.
447-
stype_in : SType or str, default 'native'
447+
stype_in : SType or str, default 'raw_symbol'
448448
The input symbology type to resolve from.
449449
limit : int, optional
450450
The maximum number of records to return. If `None` then no limit.
@@ -464,7 +464,7 @@ def get_cost(
464464
("symbols", symbols_list),
465465
("schema", str(validate_enum(schema, Schema, "schema"))),
466466
("stype_in", str(stype_in_valid)),
467-
("stype_out", str(SType.PRODUCT_ID)),
467+
("stype_out", str(SType.INSTRUMENT_ID)),
468468
("mode", validate_enum(mode, FeedMode, "mode")),
469469
]
470470

databento/historical/api/symbology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def resolve(
4343
The dataset code (string identifier) for the request.
4444
symbols : List[Union[str, int]] or str, optional
4545
The symbols to resolve. Takes up to 2,000 symbols per request.
46-
stype_in : SType or str, default 'native'
46+
stype_in : SType or str, default 'raw_symbol'
4747
The input symbology type to resolve from.
48-
stype_out : SType or str, default 'product_id'
48+
stype_out : SType or str, default 'instrument_id'
4949
The output symbology type to resolve to.
5050
start_date : date or str
5151
The start date (UTC) of the request time range (inclusive).

0 commit comments

Comments
 (0)