Skip to content

Commit d38d152

Browse files
authored
VER: Release 0.6.0
See release notes.
2 parents 4316cb0 + 540e877 commit d38d152

18 files changed

+302
-78
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_run:
77
workflows:
88
- test
9-
branches: [ main ]
9+
branches: [main]
1010
types:
1111
- completed
1212

@@ -25,7 +25,7 @@ jobs:
2525

2626
# Python setup
2727
- name: Set up Python environment
28-
uses: actions/setup-python@v2
28+
uses: actions/setup-python@v4
2929
with:
3030
python-version: "3.10"
3131

@@ -64,7 +64,7 @@ jobs:
6464
prerelease: false
6565

6666
publish-sdist:
67-
needs: [ tag-release ]
67+
needs: [tag-release]
6868
name: publish-sdist - Python 3.10 (ubuntu-latest)
6969
runs-on: ubuntu-latest
7070

@@ -73,7 +73,7 @@ jobs:
7373

7474
# Python setup
7575
- name: Set up Python environment
76-
uses: actions/setup-python@v2
76+
uses: actions/setup-python@v4
7777
with:
7878
python-version: "3.10"
7979

@@ -119,7 +119,7 @@ jobs:
119119
run: twine upload dist/*
120120

121121
publish-wheel:
122-
needs: [ tag-release ]
122+
needs: [tag-release]
123123
name: publish-wheel - Python 3.10 (ubuntu-latest)
124124
runs-on: ubuntu-latest
125125

@@ -128,7 +128,7 @@ jobs:
128128

129129
# Python setup
130130
- name: Set up Python environment
131-
uses: actions/setup-python@v2
131+
uses: actions/setup-python@v4
132132
with:
133133
python-version: "3.10"
134134

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ name: test
44

55
on:
66
push:
7-
branches: [ main, dev ]
7+
branches: [main, dev]
88

99
jobs:
1010
test:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
os: [ ubuntu-latest, macos-latest, windows-latest ]
15-
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
14+
os: [ubuntu-latest, macos-latest, windows-latest]
15+
python-version: ["3.7", "3.8", "3.9", "3.10"]
1616
name: build - Python ${{ matrix.python-version }} (${{ matrix.os }})
1717
runs-on: ${{ matrix.os }}
1818

@@ -21,7 +21,7 @@ jobs:
2121

2222
# Python setup
2323
- name: Set up Python environment
24-
uses: actions/setup-python@v2
24+
uses: actions/setup-python@v4
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727

CHANGELOG.md

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

3+
## 0.6.0 - 2022-12-02
4+
- Added `metadata.get_dataset_condition` method to `Historical` client
5+
- Upgraded `dbz-python` to `0.2.0`
6+
37
## 0.5.0 - 2022-11-07
48
- Fixed dataframe columns for derived data schemas (dropped `channel_id`)
59
- Fixed `batch.submit_job` requests for `dbz` encoding

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
The official Python client library for [Databento](https://databento.com).
1010

1111
Key features include:
12-
- Fast, lightweight access to both live and historical data from [multiple markets](https://docs0.databento.com/knowledge-base/new-users/venues-and-publishers?historical=python&live=python).
13-
- [Multiple schemas](https://docs0.databento.com/knowledge-base/new-users/list-of-supported-market-data-schemas?historical=python&live=python) such as MBO, MBP, top of book, OHLCV, last sale, and more.
14-
- [Fully normalized](https://docs0.databento.com/knowledge-base/new-users/normalization?historical=python&live=python), i.e. identical message schemas for both live and historical data, across multiple asset classes.
15-
- Provides mappings between different symbology systems, including [smart symbology](https://docs0.databento.com/reference-historical/basics/symbology?historical=python&live=python) for futures rollovers.
12+
- Fast, lightweight access to both live and historical data from [multiple markets](https://docs.databento.com/knowledge-base/new-users/venues-and-publishers?historical=python&live=python).
13+
- [Multiple schemas](https://docs.databento.com/knowledge-base/new-users/list-of-supported-market-data-schemas?historical=python&live=python) such as MBO, MBP, top of book, OHLCV, last sale, and more.
14+
- [Fully normalized](https://docs.databento.com/knowledge-base/new-users/normalization?historical=python&live=python), i.e. identical message schemas for both live and historical data, across multiple asset classes.
15+
- Provides mappings between different symbology systems, including [smart symbology](https://docs.databento.com/reference-historical/basics/symbology?historical=python&live=python) for futures rollovers.
1616
- [Point-in-time]() instrument definitions, free of look-ahead bias and retroactive adjustments.
17-
- Reads and stores market data in an extremely efficient file format using [Databento Binary Encoding](https://docs0.databento.com/knowledge-base/new-users/dbz-format?historical=python&live=python).
18-
- Event-driven [market replay](https://docs0.databento.com/reference-historical/helpers/bento-replay?historical=python&live=python), including at high-frequency order book granularity.
19-
- Support for [batch download](https://docs0.databento.com/knowledge-base/new-users/historical-data-streaming-vs-batch-download?historical=python&live=python) of flat files.
17+
- Reads and stores market data in an extremely efficient file format using [Databento Binary Encoding](https://docs.databento.com/knowledge-base/new-users/dbz-format?historical=python&live=python).
18+
- Event-driven [market replay](https://docs.databento.com/reference-historical/helpers/bento-replay?historical=python&live=python), including at high-frequency order book granularity.
19+
- Support for [batch download](https://docs.databento.com/knowledge-base/new-users/historical-data-streaming-vs-batch-download?historical=python&live=python) of flat files.
2020
- Support for [pandas](https://pandas.pydata.org/docs/), CSV, and JSON.
2121

2222
## Documentation
2323
The best place to begin is with our [Getting started](https://docs.databento.com/getting-started?historical=python&live=python) guide.
2424

2525
You can find our full client API reference on the [Historical Reference](https://docs.databento.com/reference-historical?historical=python&live=python) and
2626
[Live Reference](https://docs.databento.com/reference-live?historical=python&live=python) sections of our documentation. See also the
27-
[Examples](https://docs0.databento.com/examples?historical=python&live=python) section for various tutorials and code samples.
27+
[Examples](https://docs.databento.com/examples?historical=python&live=python) section for various tutorials and code samples.
2828

2929
## Requirements
3030
The library is fully compatible with the latest distribution of Anaconda 3.7 and above.
3131
The minimum dependencies as found in the `requirements.txt` are also listed below:
3232
- Python (>=3.7)
3333
- aiohttp (>=3.7.2)
34-
- dbz-python (>=0.1.5)
34+
- dbz-python (>=0.2.0)
3535
- numpy (>=1.17.0)
3636
- pandas (>=1.1.3)
3737
- requests (>=2.24.0)

databento/common/bento.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def _build_product_id_index(self) -> Dict[dt.date, Dict[int, str]]:
662662
end_date=row["end_date"],
663663
native=native,
664664
product_id=int(row["symbol"]),
665-
)
665+
),
666666
)
667667

668668
product_id_index: Dict[dt.date, Dict[int, str]] = {}

databento/common/parsing.py

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def enum_or_str_lowercase(
1111
param: str,
1212
) -> str:
1313
"""
14-
Return the given value parsed to a lowercase string if possible.
14+
Return the given value parsed to a lowercase string.
1515
1616
Parameters
1717
----------
@@ -44,7 +44,7 @@ def maybe_enum_or_str_lowercase(
4444
param: str,
4545
) -> Optional[str]:
4646
"""
47-
Return the given value parsed to a lowercase string if possible.
47+
Return the given value parsed to a lowercase string (if not `None`).
4848
4949
Parameters
5050
----------
@@ -68,6 +68,68 @@ def maybe_enum_or_str_lowercase(
6868
return enum_or_str_lowercase(value, param)
6969

7070

71+
def enum_or_str_uppercase(
72+
value: Union[Enum, str],
73+
param: str,
74+
) -> str:
75+
"""
76+
Return the given value parsed to an uppercase string.
77+
78+
Parameters
79+
----------
80+
value : Enum or str
81+
The value to parse.
82+
param : str
83+
The name of the parameter being validated (for any error message).
84+
85+
Returns
86+
-------
87+
str
88+
89+
Raises
90+
------
91+
TypeError
92+
If value is not of type NoneType, Enum or str.
93+
94+
"""
95+
if isinstance(value, Enum):
96+
return value.value.upper()
97+
elif isinstance(value, str):
98+
if not value.isspace():
99+
return value.upper()
100+
101+
raise TypeError(f"invalid `{param}` type, was {type(value)}.")
102+
103+
104+
def maybe_enum_or_str_uppercase(
105+
value: Optional[Union[Enum, str]],
106+
param: str,
107+
) -> Optional[str]:
108+
"""
109+
Return the given value parsed to an uppercase string (if not `None`).
110+
111+
Parameters
112+
----------
113+
value : Enum or str, optional
114+
The value to parse.
115+
param : str
116+
The name of the parameter being validated (for any error message).
117+
118+
Returns
119+
-------
120+
str or ``None``
121+
122+
Raises
123+
------
124+
TypeError
125+
If value is not of type NoneType, Enum or str.
126+
127+
"""
128+
if value is None:
129+
return value
130+
return enum_or_str_uppercase(value, param)
131+
132+
71133
def values_list_to_string(
72134
values: Union[Iterable[str], str],
73135
) -> str:
@@ -116,6 +178,7 @@ def maybe_values_list_to_string(
116178

117179
def maybe_symbols_list_to_string(
118180
symbols: Optional[Union[Iterable[str], str]],
181+
stype_in: SType,
119182
) -> Optional[str]:
120183
"""
121184
Concatenate a symbols string or iterable of symbol strings (if not None).
@@ -124,21 +187,31 @@ def maybe_symbols_list_to_string(
124187
----------
125188
symbols : iterable of str or str, optional
126189
The symbols to concatenate.
190+
stype_in : SType
191+
The input symbology type for the request.
127192
128193
Returns
129194
-------
130195
str or ``None``
131196
132197
"""
133198
if symbols is None:
134-
return None # All symbols
135-
136-
if isinstance(symbols, str):
137-
return symbols.strip().rstrip(",").upper()
138-
elif isinstance(symbols, Iterable):
139-
return ",".join(symbols).strip().upper()
140-
else:
141-
raise TypeError(f"invalid symbols type, was {type(symbols)}")
199+
return None # Full universe
200+
201+
symbols_list = symbols.split(",") if isinstance(symbols, str) else list(symbols)
202+
cleaned_symbols: List[str] = []
203+
for symbol in symbols_list:
204+
if not symbol:
205+
continue
206+
symbol = symbol.strip().upper()
207+
if stype_in == SType.SMART:
208+
pieces: List[str] = symbol.split(".")
209+
if len(pieces) == 3:
210+
symbol = f"{pieces[0]}.{pieces[1].lower()}.{pieces[2]}"
211+
212+
cleaned_symbols.append(symbol)
213+
214+
return ",".join(cleaned_symbols)
142215

143216

144217
def maybe_date_to_string(value: Optional[Union[date, str]]) -> Optional[str]:

databento/historical/api/metadata.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pandas as pd
55
from databento.common.enums import Dataset, Encoding, FeedMode, Schema, SType
66
from databento.common.parsing import (
7-
enum_or_str_lowercase,
7+
enum_or_str_uppercase,
88
maybe_date_to_string,
99
maybe_datetime_to_string,
1010
maybe_enum_or_str_lowercase,
@@ -107,7 +107,7 @@ def list_schemas(
107107
108108
"""
109109
params: List[Tuple[str, Optional[str]]] = [
110-
("dataset", enum_or_str_lowercase(dataset, "dataset")),
110+
("dataset", enum_or_str_uppercase(dataset, "dataset")),
111111
("start_date", maybe_date_to_string(start_date)),
112112
("end_date", maybe_date_to_string(end_date)),
113113
]
@@ -152,7 +152,7 @@ def list_fields(
152152
validate_maybe_enum(encoding, Encoding, "encoding")
153153

154154
params: List[Tuple[str, str]] = [
155-
("dataset", enum_or_str_lowercase(dataset, "dataset")),
155+
("dataset", enum_or_str_uppercase(dataset, "dataset")),
156156
("schema", maybe_enum_or_str_lowercase(schema, "schema")),
157157
("encoding", maybe_enum_or_str_lowercase(encoding, "encoding")),
158158
]
@@ -229,7 +229,7 @@ def list_unit_prices(
229229
validate_maybe_enum(mode, FeedMode, "mode")
230230

231231
params: List[Tuple[str, Optional[str]]] = [
232-
("dataset", enum_or_str_lowercase(dataset, "dataset")),
232+
("dataset", enum_or_str_uppercase(dataset, "dataset")),
233233
("mode", maybe_enum_or_str_lowercase(mode, "mode")),
234234
("schema", maybe_enum_or_str_lowercase(schema, "schema")),
235235
]
@@ -241,6 +241,46 @@ def list_unit_prices(
241241
)
242242
return response.json()
243243

244+
def get_dataset_condition(
245+
self,
246+
dataset: Union[Dataset, str],
247+
start_date: Union[date, str],
248+
end_date: Union[date, str],
249+
) -> Dict[str, Any]:
250+
"""
251+
Get the dataset condition from Databento.
252+
253+
Makes a `GET /metadata.get_dataset_condition` HTTP request.
254+
255+
Use this method to discover data availability and qualility.
256+
257+
Parameters
258+
----------
259+
dataset : Dataset or str
260+
The dataset code (string identifier) for the request.
261+
start_date : date or str
262+
The start date (UTC) for the request range.
263+
end_date : date or str
264+
The end date (UTC) for the request range.
265+
266+
Returns
267+
-------
268+
Dict[str, Any]
269+
270+
"""
271+
params: List[Tuple[str, Optional[str]]] = [
272+
("dataset", enum_or_str_uppercase(dataset, "dataset")),
273+
("start_date", str(pd.to_datetime(start_date).date())),
274+
("end_date", str(pd.to_datetime(end_date).date())),
275+
]
276+
277+
response: Response = self._get(
278+
url=self._base_url + ".get_dataset_condition",
279+
params=params,
280+
basic_auth=True,
281+
)
282+
return response.json()
283+
244284
def get_record_count(
245285
self,
246286
dataset: Union[Dataset, str],
@@ -290,8 +330,8 @@ def get_record_count(
290330
validate_enum(stype_in, SType, "stype_in")
291331

292332
params: List[Tuple[str, Optional[str]]] = [
293-
("dataset", enum_or_str_lowercase(dataset, "dataset")),
294-
("symbols", maybe_symbols_list_to_string(symbols)),
333+
("dataset", enum_or_str_uppercase(dataset, "dataset")),
334+
("symbols", maybe_symbols_list_to_string(symbols, SType(stype_in))),
295335
("schema", Schema(schema).value),
296336
("start", maybe_datetime_to_string(start)),
297337
("end", maybe_datetime_to_string(end)),

databento/historical/api/symbology.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
import pandas as pd
55
from databento.common.enums import SType
6-
from databento.common.parsing import enum_or_str_lowercase, maybe_symbols_list_to_string
6+
from databento.common.parsing import (
7+
enum_or_str_lowercase,
8+
enum_or_str_uppercase,
9+
maybe_symbols_list_to_string,
10+
)
711
from databento.historical.api import API_VERSION
812
from databento.historical.http import BentoHttpAPI
913
from requests import Response
@@ -58,8 +62,8 @@ def resolve(
5862
5963
"""
6064
params: List[Tuple[str, Optional[str]]] = [
61-
("dataset", enum_or_str_lowercase(dataset, "dataset")),
62-
("symbols", maybe_symbols_list_to_string(symbols)),
65+
("dataset", enum_or_str_uppercase(dataset, "dataset")),
66+
("symbols", maybe_symbols_list_to_string(symbols, SType(stype_in))),
6367
("stype_in", enum_or_str_lowercase(stype_in, "stype_in")),
6468
("stype_out", enum_or_str_lowercase(stype_out, "stype_out")),
6569
("start_date", str(pd.to_datetime(start_date).date())),

0 commit comments

Comments
 (0)