Skip to content

Commit 304e36b

Browse files
committed
MOD: Apply various Python client library improvements
1 parent 115b379 commit 304e36b

14 files changed

+55
-83
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
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]().
13-
- [Multiple schemas]() such as MBO, MBP, top of book, OHLCV, last sale, and more.
14-
- [Fully normalized](), 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]() for futures rollovers.
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.
1616
- [Point-in-time]() instrument definitions, free of look-ahead bias and retroactive adjustments.
1717
- Reads and stores market data in an extremely efficient file format using [Databento Binary Encoding]().
18-
- Event-driven [market replay](), including at high-frequency order book granularity.
19-
- Support for [batch download]() of flat files.
20-
- Support for [pandas](), CSV, and JSON.
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.
20+
- 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]() section for various tutorials and code samples.
27+
[Examples](https://docs0.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.
@@ -56,10 +56,11 @@ import databento as db
5656
client = db.Historical('YOUR_API_KEY')
5757
data = client.timeseries.stream(
5858
dataset='GLBX.MDP3',
59-
start='2020-11-02T14:30',
60-
end='2020-11-02T14:40')
59+
start='2022-06-10T14:30',
60+
end='2022-06-10T14:40',
61+
)
6162

62-
data.replay(callback=print) # market replay, with `print` as event handler
63+
data.replay(callback=print) # market replay, with `print` as event handler
6364
```
6465

6566
Replace `YOUR_API_KEY` with an actual API key, then run this program.
@@ -70,7 +71,7 @@ and dispatch each data event to an event handler. You can also use
7071

7172
```python
7273
df = data.to_df(pretty_ts=True, pretty_px=True) # to DataFrame, with pretty formatting
73-
array = data.to_ndarray() # to ndarray
74+
array = data.to_ndarray() # to ndarray
7475
```
7576

7677
Note that the API key was also passed as a parameter, which is
@@ -81,7 +82,7 @@ Instead, you can leave out this parameter to pass your API key via the `DATABENT
8182
import databento as db
8283

8384
client = db.Historical('YOUR_API_KEY') # pass as parameter
84-
client = db.Historical() # pass as `DATABENTO_API_KEY` environment variable
85+
client = db.Historical() # pass as `DATABENTO_API_KEY` environment variable
8586
```
8687

8788
## License

examples/historical_batch.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
response = client.batch.submit_job(
1313
dataset="GLBX.MDP3",
14-
symbols=["ESH1"],
14+
symbols=["ESM2"],
1515
schema="mbo",
16-
start="2020-12-27T12:00",
17-
end="2020-12-29",
16+
start="2022-06-10T12:00",
17+
end="2022-06-10T14:00",
18+
limit=1000, # <-- limiting batch request to 1000 records only
1819
encoding="csv",
1920
compression="zstd",
2021
delivery="download",

examples/historical_metadata_get_billable_size.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
size: int = client.metadata.get_billable_size(
1111
dataset="GLBX.MDP3",
12-
symbols=["ESH1"],
12+
symbols=["ESM2"],
1313
schema="mbo",
14-
start="2020-12-28T12:00",
15-
end="2020-12-29",
14+
start="2022-06-10T12:00",
15+
end="2022-06-10T14:00",
1616
)
1717

1818
print(size)

examples/historical_metadata_get_cost.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@
77
key = "YOUR_API_KEY"
88
client = db.Historical(key=key)
99

10-
cost1: float = client.metadata.get_cost(
10+
cost: float = client.metadata.get_cost(
1111
dataset="GLBX.MDP3",
12-
symbols="*",
12+
symbols="ESM2",
1313
schema="mbo",
14-
start="2020-12-27T12:00",
15-
end="2020-12-29",
14+
start="2022-06-10",
15+
end="2022-06-15",
1616
)
1717

18-
print(cost1)
19-
20-
cost2: float = client.metadata.get_cost(
21-
dataset="XNAS.ITCH",
22-
symbols=["MSFT"],
23-
schema="trades",
24-
start="2015-04-22",
25-
end="2015-04-22T12:10",
26-
)
27-
28-
print(cost2)
18+
print(cost)

examples/historical_metadata_get_shape.py

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

1212
shape: Tuple = client.metadata.get_shape(
1313
dataset="GLBX.MDP3",
14-
symbols=["ESH1"],
14+
symbols=["ESM2"],
1515
schema="mbo",
16-
start="2020-12-28T12:00",
17-
end="2020-12-29",
16+
start="2022-06-10T12:00",
17+
end="2022-06-10T14:00",
1818
encoding="csv",
1919
)
2020

examples/historical_symbology_resolve.py

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

1313
response = client.symbology.resolve(
1414
dataset="GLBX.MDP3",
15-
symbols=["ESH1"],
15+
symbols=["ESM2"],
1616
stype_in=SType.NATIVE,
1717
stype_out=SType.PRODUCT_ID,
18-
start_date="2020-12-27",
19-
end_date="2020-12-29",
18+
start_date="2022-06-01",
19+
end_date="2022-06-30",
2020
)
2121

2222
pprint(response)

examples/historical_timeseries_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ async def request_stream_async():
1313

1414
data: Bento = await client.timeseries.stream_async(
1515
dataset="GLBX.MDP3",
16-
symbols=["ESH1"],
16+
symbols=["ESM2"],
1717
schema="mbo",
18-
start="2020-12-28T10:00",
19-
end="2020-12-29T10:10",
18+
start="2022-06-10T12:00",
19+
end="2022-06-10T14:00",
2020
limit=1000, # <-- limiting response to 1000 records only
2121
)
2222
pprint(data.to_df())

examples/historical_timeseries_disk_io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# Execute request through client
1616
data: Bento = client.timeseries.stream(
1717
dataset="GLBX.MDP3",
18-
symbols=["ESH1"],
18+
symbols=["ESM2"],
1919
schema="mbo",
20-
start="2020-12-27T12:00",
21-
end="2020-12-29",
20+
start="2022-06-10T12:00",
21+
end="2022-06-10T14:00",
2222
limit=1000, # <-- limiting response to 1000 records only
2323
path=path,
2424
)

examples/historical_timeseries_from_file.py

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

77
if __name__ == "__main__":
88
db.log = "debug" # optional debug logging
9+
ts_start = datetime.datetime.utcnow()
910

1011
# Can load from file path (if exists)
11-
ts_start = datetime.datetime.utcnow()
12-
data = Bento.from_file(path="test_data.mbo.dbz")
12+
data = Bento.from_file(path="my_data.dbz")
1313

1414
print(data.to_df())
1515
print(datetime.datetime.utcnow() - ts_start)

examples/historical_timeseries_replay.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
data: Bento = client.timeseries.stream(
1212
dataset="GLBX.MDP3",
13-
symbols=["ESH1"],
13+
symbols=["ESM2"],
1414
schema="trades",
15-
start="2020-12-27T10:00",
16-
end="2020-12-28T23:10",
15+
start="2022-06-10T12:00",
16+
end="2022-06-10T14:00",
1717
limit=1000, # <-- limiting response to 1000 records only
1818
)
1919

0 commit comments

Comments
 (0)