Skip to content

Commit e9c419d

Browse files
committed
MOD: Standardize ALL_SYMBOLS representation
1 parent 4470468 commit e9c419d

File tree

9 files changed

+60
-55
lines changed

9 files changed

+60
-55
lines changed

databento/common/parsing.py

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

55
import pandas as pd
66
from databento.common.enums import Compression, Encoding, Flags, Schema, SType
7+
from databento.common.symbology import ALL_SYMBOLS
78

89

910
def enum_or_str_lowercase(
@@ -39,7 +40,7 @@ def enum_or_str_lowercase(
3940
raise TypeError(f"invalid `{param}` type, was {type(value)}.")
4041

4142

42-
def maybe_enum_or_str_lowercase(
43+
def optional_enum_or_str_lowercase(
4344
value: Optional[Union[Enum, str]],
4445
param: str,
4546
) -> Optional[str]:
@@ -101,7 +102,7 @@ def enum_or_str_uppercase(
101102
raise TypeError(f"invalid `{param}` type, was {type(value)}.")
102103

103104

104-
def maybe_enum_or_str_uppercase(
105+
def optional_enum_or_str_uppercase(
105106
value: Optional[Union[Enum, str]],
106107
param: str,
107108
) -> Optional[str]:
@@ -154,7 +155,7 @@ def values_list_to_string(
154155
raise TypeError(f"invalid values type, was {type(values)}")
155156

156157

157-
def maybe_values_list_to_string(
158+
def optional_values_list_to_string(
158159
values: Optional[Union[Iterable[str], str]],
159160
) -> Optional[str]:
160161
"""
@@ -176,10 +177,10 @@ def maybe_values_list_to_string(
176177
return values_list_to_string(values)
177178

178179

179-
def maybe_symbols_list_to_string(
180+
def optional_symbols_list_to_string(
180181
symbols: Optional[Union[Iterable[str], str]],
181182
stype_in: SType,
182-
) -> Optional[str]:
183+
) -> str:
183184
"""
184185
Concatenate a symbols string or iterable of symbol strings (if not None).
185186
@@ -192,11 +193,11 @@ def maybe_symbols_list_to_string(
192193
193194
Returns
194195
-------
195-
str or ``None``
196+
str
196197
197198
"""
198199
if symbols is None:
199-
return None # Full universe
200+
return ALL_SYMBOLS
200201

201202
symbols_list = symbols.split(",") if isinstance(symbols, str) else list(symbols)
202203
cleaned_symbols: List[str] = []
@@ -214,7 +215,7 @@ def maybe_symbols_list_to_string(
214215
return ",".join(cleaned_symbols)
215216

216217

217-
def maybe_date_to_string(value: Optional[Union[date, str]]) -> Optional[str]:
218+
def optional_date_to_string(value: Optional[Union[date, str]]) -> Optional[str]:
218219
"""
219220
Return a valid date string from the given value (if not None).
220221
@@ -251,7 +252,7 @@ def datetime_to_string(value: Union[pd.Timestamp, date, str, int]) -> str:
251252
return str(pd.to_datetime(value)).replace(" ", "T")
252253

253254

254-
def maybe_datetime_to_string(
255+
def optional_datetime_to_string(
255256
value: Optional[Union[pd.Timestamp, date, str, int]],
256257
) -> Optional[str]:
257258
"""

databento/common/symbology.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from dataclasses import dataclass
33

44

5+
ALL_SYMBOLS = "ALL_SYMBOLS"
6+
7+
58
@dataclass(frozen=True)
69
class ProductIdMappingInterval:
710
"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
API_VERSION = 0
2+
ALL_SYMBOLS = "ALL_SYMBOLS"

databento/historical/api/batch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
SType,
1414
)
1515
from databento.common.parsing import (
16-
maybe_datetime_to_string,
17-
maybe_values_list_to_string,
16+
optional_datetime_to_string,
17+
optional_values_list_to_string,
1818
)
1919
from databento.common.validation import validate_enum
2020
from databento.historical.api import API_VERSION
@@ -67,7 +67,7 @@ def submit_job(
6767
symbols : List[Union[str, int]] or str
6868
The product symbols to filter for. Takes up to 2,000 symbols per request.
6969
If more than 1 symbol is specified, the data is merged and sorted by time.
70-
If `*` or ``None`` then will be for **all** symbols.
70+
If 'ALL_SYMBOLS' or ``None`` then will be for **all** symbols.
7171
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
7272
The data record schema for the request.
7373
encoding : Encoding or str {'dbn', 'csv', 'json'}, default 'dbn'
@@ -163,8 +163,8 @@ def list_jobs(
163163
164164
"""
165165
params: List[Tuple[str, Optional[str]]] = [
166-
("states", maybe_values_list_to_string(states)),
167-
("since", maybe_datetime_to_string(since)),
166+
("states", optional_values_list_to_string(states)),
167+
("since", optional_datetime_to_string(since)),
168168
]
169169

170170
return self._get(

databento/historical/api/metadata.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from databento.common.enums import Dataset, Encoding, FeedMode, Schema, SType
66
from databento.common.parsing import (
77
enum_or_str_uppercase,
8-
maybe_date_to_string,
9-
maybe_datetime_to_string,
10-
maybe_enum_or_str_lowercase,
11-
maybe_symbols_list_to_string,
8+
optional_date_to_string,
9+
optional_datetime_to_string,
10+
optional_enum_or_str_lowercase,
11+
optional_symbols_list_to_string,
1212
)
1313
from databento.common.validation import validate_enum, validate_maybe_enum
1414
from databento.historical.api import API_VERSION
@@ -70,8 +70,8 @@ def list_datasets(
7070
7171
"""
7272
params: List[Tuple[str, Optional[str]]] = [
73-
("start_date", maybe_date_to_string(start_date)),
74-
("end_date", maybe_date_to_string(end_date)),
73+
("start_date", optional_date_to_string(start_date)),
74+
("end_date", optional_date_to_string(end_date)),
7575
]
7676

7777
response: Response = self._get(
@@ -108,8 +108,8 @@ def list_schemas(
108108
"""
109109
params: List[Tuple[str, Optional[str]]] = [
110110
("dataset", enum_or_str_uppercase(dataset, "dataset")),
111-
("start_date", maybe_date_to_string(start_date)),
112-
("end_date", maybe_date_to_string(end_date)),
111+
("start_date", optional_date_to_string(start_date)),
112+
("end_date", optional_date_to_string(end_date)),
113113
]
114114

115115
response: Response = self._get(
@@ -153,8 +153,8 @@ def list_fields(
153153

154154
params: List[Tuple[str, str]] = [
155155
("dataset", enum_or_str_uppercase(dataset, "dataset")),
156-
("schema", maybe_enum_or_str_lowercase(schema, "schema")),
157-
("encoding", maybe_enum_or_str_lowercase(encoding, "encoding")),
156+
("schema", optional_enum_or_str_lowercase(schema, "schema")),
157+
("encoding", optional_enum_or_str_lowercase(encoding, "encoding")),
158158
]
159159

160160
response: Response = self._get(
@@ -230,8 +230,8 @@ def list_unit_prices(
230230

231231
params: List[Tuple[str, Optional[str]]] = [
232232
("dataset", enum_or_str_uppercase(dataset, "dataset")),
233-
("mode", maybe_enum_or_str_lowercase(mode, "mode")),
234-
("schema", maybe_enum_or_str_lowercase(schema, "schema")),
233+
("mode", optional_enum_or_str_lowercase(mode, "mode")),
234+
("schema", optional_enum_or_str_lowercase(schema, "schema")),
235235
]
236236

237237
response: Response = self._get(
@@ -308,7 +308,7 @@ def get_record_count(
308308
If an integer is passed, then this represents nanoseconds since UNIX epoch.
309309
symbols : List[Union[str, int]] or str, optional
310310
The product symbols to filter for. Takes up to 2,000 symbols per request.
311-
If `*` or ``None`` then will be for **all** symbols.
311+
If 'ALL_SYMBOLS' or ``None`` then will be for **all** symbols.
312312
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
313313
The data record schema for the request.
314314
stype_in : SType or str, default 'native'
@@ -328,10 +328,10 @@ def get_record_count(
328328

329329
params: List[Tuple[str, Optional[str]]] = [
330330
("dataset", enum_or_str_uppercase(dataset, "dataset")),
331-
("symbols", maybe_symbols_list_to_string(symbols, SType(stype_in))),
331+
("symbols", optional_symbols_list_to_string(symbols, SType(stype_in))),
332332
("schema", Schema(schema).value),
333-
("start", maybe_datetime_to_string(start)),
334-
("end", maybe_datetime_to_string(end)),
333+
("start", optional_datetime_to_string(start)),
334+
("end", optional_datetime_to_string(end)),
335335
("stype_in", SType(stype_in).value),
336336
]
337337
if limit is not None:
@@ -373,7 +373,7 @@ def get_billable_size(
373373
If an integer is passed, then this represents nanoseconds since UNIX epoch.
374374
symbols : List[Union[str, int]] or str, optional
375375
The product symbols to filter for. Takes up to 2,000 symbols per request.
376-
If `*` or ``None`` then will be for **all** symbols.
376+
If 'ALL_SYMBOLS' or ``None`` then will be for **all** symbols.
377377
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
378378
The data record schema for the request.
379379
stype_in : SType or str, default 'native'
@@ -439,7 +439,7 @@ def get_cost(
439439
The data feed mode for the request.
440440
symbols : List[Union[str, int]] or str, optional
441441
The product symbols to filter for. Takes up to 2,000 symbols per request.
442-
If `*` or ``None`` then will be for **all** symbols.
442+
If 'ALL_SYMBOLS' or ``None`` then will be for **all** symbols.
443443
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
444444
The data record schema for the request.
445445
stype_in : SType or str, default 'native'

databento/historical/api/symbology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from databento.common.parsing import (
77
enum_or_str_lowercase,
88
enum_or_str_uppercase,
9-
maybe_symbols_list_to_string,
9+
optional_symbols_list_to_string,
1010
)
1111
from databento.historical.api import API_VERSION
1212
from databento.historical.http import BentoHttpAPI
@@ -63,7 +63,7 @@ def resolve(
6363
"""
6464
params: List[Tuple[str, Optional[str]]] = [
6565
("dataset", enum_or_str_uppercase(dataset, "dataset")),
66-
("symbols", maybe_symbols_list_to_string(symbols, SType(stype_in))),
66+
("symbols", optional_symbols_list_to_string(symbols, SType(stype_in))),
6767
("stype_in", enum_or_str_lowercase(stype_in, "stype_in")),
6868
("stype_out", enum_or_str_lowercase(stype_out, "stype_out")),
6969
("start_date", str(pd.to_datetime(start_date).date())),

databento/historical/api/timeseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def stream(
5555
symbols : List[Union[str, int]] or str, optional
5656
The product symbols to filter for. Takes up to 2,000 symbols per request.
5757
If more than 1 symbol is specified, the data is merged and sorted by time.
58-
If `*` or ``None`` then will be for **all** symbols.
58+
If 'ALL_SYMBOLS' or ``None`` then will be for **all** symbols.
5959
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
6060
The data record schema for the request.
6161
stype_in : SType or str, default 'native'
@@ -154,7 +154,7 @@ async def stream_async(
154154
symbols : List[Union[str, int]] or str, optional
155155
The product symbols to filter for. Takes up to 2,000 symbols per request.
156156
If more than 1 symbol is specified, the data is merged and sorted by time.
157-
If `*` or ``None`` then will be for **all** symbols.
157+
If 'ALL_SYMBOLS' or ``None`` then will be for **all** symbols.
158158
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
159159
The data record schema for the request.
160160
stype_in : SType or str, default 'native'

databento/historical/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from databento.common.parsing import (
1414
datetime_to_string,
1515
enum_or_str_uppercase,
16-
maybe_symbols_list_to_string,
16+
optional_symbols_list_to_string,
1717
)
1818
from databento.historical.error import BentoClientError, BentoServerError
1919
from databento.version import __version__
@@ -54,7 +54,7 @@ def _timeseries_params(
5454
("dataset", enum_or_str_uppercase(dataset, "dataset")),
5555
("start", datetime_to_string(start)),
5656
("end", datetime_to_string(end)),
57-
("symbols", maybe_symbols_list_to_string(symbols, SType(stype_in)) or "*"),
57+
("symbols", optional_symbols_list_to_string(symbols, SType(stype_in))),
5858
("schema", schema.value),
5959
("stype_in", stype_in.value),
6060
("stype_out", stype_out.value),

tests/test_common_parsing.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
from databento.common.parsing import (
1010
enum_or_str_lowercase,
1111
enum_or_str_uppercase,
12-
maybe_date_to_string,
13-
maybe_datetime_to_string,
14-
maybe_enum_or_str_lowercase,
15-
maybe_enum_or_str_uppercase,
16-
maybe_symbols_list_to_string,
17-
maybe_values_list_to_string,
12+
optional_date_to_string,
13+
optional_datetime_to_string,
14+
optional_enum_or_str_lowercase,
15+
optional_enum_or_str_uppercase,
16+
optional_symbols_list_to_string,
17+
optional_values_list_to_string,
1818
parse_flags,
1919
)
2020

@@ -56,7 +56,7 @@ def test_maybe_enum_or_str_lowercase_given_incorrect_types_raises_error(
5656
) -> None:
5757
# Arrange, Act, Assert
5858
with pytest.raises(TypeError):
59-
maybe_enum_or_str_lowercase(INCORRECT_TYPE, "param")
59+
optional_enum_or_str_lowercase(INCORRECT_TYPE, "param")
6060

6161
@pytest.mark.parametrize(
6262
"value, expected",
@@ -73,7 +73,7 @@ def test_maybe_enum_or_str_lowercase_returns_expected_outputs(
7373
expected: Optional[str],
7474
) -> None:
7575
# Arrange, Act, Assert
76-
assert maybe_enum_or_str_lowercase(value, "param") == expected
76+
assert optional_enum_or_str_lowercase(value, "param") == expected
7777

7878
def test_enum_or_str_uppercase_given_none_raises_type_error(self) -> None:
7979
# Arrange, Act, Assert
@@ -106,7 +106,7 @@ def test_maybe_enum_or_str_uppercase_given_incorrect_types_raises_error(
106106
) -> None:
107107
# Arrange, Act, Assert
108108
with pytest.raises(TypeError):
109-
maybe_enum_or_str_lowercase(INCORRECT_TYPE, "param")
109+
optional_enum_or_str_lowercase(INCORRECT_TYPE, "param")
110110

111111
@pytest.mark.parametrize(
112112
"value, expected",
@@ -123,14 +123,14 @@ def test_maybe_enum_or_str_uppercase_returns_expected_outputs(
123123
expected: Optional[str],
124124
) -> None:
125125
# Arrange, Act, Assert
126-
assert maybe_enum_or_str_uppercase(value, "param") == expected
126+
assert optional_enum_or_str_uppercase(value, "param") == expected
127127

128128
def test_maybe_values_list_to_string_given_invalid_input_raises_type_error(
129129
self,
130130
) -> None:
131131
# Arrange, Act, Assert
132132
with pytest.raises(TypeError):
133-
maybe_values_list_to_string(INCORRECT_TYPE)
133+
optional_values_list_to_string(INCORRECT_TYPE)
134134

135135
@pytest.mark.parametrize(
136136
"values, expected",
@@ -149,7 +149,7 @@ def test_maybe_values_list_to_string_given_valid_inputs_returns_expected(
149149
expected: str,
150150
) -> None:
151151
# Arrange, Act
152-
result: Optional[str] = maybe_values_list_to_string(values)
152+
result: Optional[str] = optional_values_list_to_string(values)
153153

154154
# Assert
155155
assert result == expected
@@ -159,12 +159,12 @@ def test_maybe_symbols_list_to_string_given_invalid_input_raises_type_error(
159159
) -> None:
160160
# Arrange, Act, Assert
161161
with pytest.raises(TypeError):
162-
maybe_symbols_list_to_string(INCORRECT_TYPE, SType.NATIVE)
162+
optional_symbols_list_to_string(INCORRECT_TYPE, SType.NATIVE)
163163

164164
@pytest.mark.parametrize(
165165
"symbols, expected",
166166
[
167-
[None, None],
167+
[None, "ALL_SYMBOLS"],
168168
["ES.fut", "ES.FUT"],
169169
["ES,CL", "ES,CL"],
170170
["ES,CL,", "ES,CL"],
@@ -180,7 +180,7 @@ def test_maybe_symbols_list_to_string_given_valid_inputs_returns_expected(
180180
expected: str,
181181
) -> None:
182182
# Arrange, Act
183-
result: Optional[str] = maybe_symbols_list_to_string(symbols, SType.SMART)
183+
result: str = optional_symbols_list_to_string(symbols, SType.SMART)
184184

185185
# Assert
186186
assert result == expected
@@ -199,7 +199,7 @@ def test_maybe_date_to_string_give_valid_values_returns_expected_results(
199199
expected: str,
200200
) -> None:
201201
# Arrange, Act
202-
result: Optional[str] = maybe_date_to_string(value)
202+
result: Optional[str] = optional_date_to_string(value)
203203

204204
# Assert
205205
assert result == expected
@@ -220,7 +220,7 @@ def test_maybe_datetime_to_string_give_valid_values_returns_expected_results(
220220
expected: str,
221221
) -> None:
222222
# Arrange, Act
223-
result: Optional[str] = maybe_datetime_to_string(value)
223+
result: Optional[str] = optional_datetime_to_string(value)
224224

225225
# Assert
226226
assert result == expected

0 commit comments

Comments
 (0)