Skip to content

Commit f64f1ef

Browse files
committed
DOC: Align and refine API reference pt1
1 parent 25d935d commit f64f1ef

File tree

8 files changed

+72
-51
lines changed

8 files changed

+72
-51
lines changed

databento/common/bento.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def symbology(self) -> Dict[str, Any]:
414414

415415
def to_ndarray(self) -> np.ndarray:
416416
"""
417-
Return the data as a numpy ndarray.
417+
Return the data as a numpy `ndarray`.
418418
419419
Returns
420420
-------
@@ -480,7 +480,7 @@ def to_df(self, pretty_ts: bool = False, pretty_px: bool = False) -> pd.DataFram
480480

481481
def replay(self, callback: Callable[[Any], None]) -> None:
482482
"""
483-
Pass all data records sequentially to the given callback.
483+
Replay data by passing records sequentially to the given callback.
484484
485485
Parameters
486486
----------
@@ -538,7 +538,7 @@ def to_file(self, path: str) -> "FileBento":
538538
Parameters
539539
----------
540540
path : str
541-
The path to write to.
541+
The file path to write to.
542542
543543
Returns
544544
-------
@@ -555,24 +555,32 @@ def to_file(self, path: str) -> "FileBento":
555555

556556
def to_csv(self, path: str) -> None:
557557
"""
558-
Write the data to a CSV file at the given path.
558+
Write the data to a file in CSV format.
559559
560560
Parameters
561561
----------
562562
path : str
563-
The path to write to.
563+
The file path to write to.
564+
565+
Notes
566+
-----
567+
Requires all the data to be brought up into memory to then be written.
564568
565569
"""
566570
self.to_df().to_csv(path)
567571

568572
def to_json(self, path: str) -> None:
569573
"""
570-
Write the data to a JSON file at the given path.
574+
Write the data to a file in JSON format.
571575
572576
Parameters
573577
----------
574578
path : str
575-
The path to write to.
579+
The file path to write to.
580+
581+
Notes
582+
-----
583+
Requires all the data to be brought up into memory to then be written.
576584
577585
"""
578586
self.to_df().to_json(path, orient="records", lines=True)

databento/historical/api/batch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def timeseries_submit(
4545
limit: Optional[int] = None,
4646
) -> Dict[str, Any]:
4747
"""
48-
Submit a timeseries batch data job to the Databento backend.
48+
Submit a time series batch data job to the Databento backend.
4949
5050
`POST /v0/batch.timeseries_submit` HTTP API endpoint.
5151
@@ -64,9 +64,9 @@ def timeseries_submit(
6464
The UTC end of the time range (exclusive) for the request.
6565
If using an integer then this represents nanoseconds since UNIX epoch.
6666
encoding : Encoding or str {'dbz', 'csv', 'json'}, default 'dbz'
67-
The data output encoding.
67+
The data encoding.
6868
compression : Compression or str {'none', 'zstd'}, default 'zstd'
69-
The data output compression.
69+
The data compression mode.
7070
split_duration : Duration or str {'day', 'week', 'month', 'none'}, default 'day'
7171
The time duration split per data file ('week' starts on Sunday UTC).
7272
split_size : int, optional
@@ -143,7 +143,7 @@ def list_jobs(
143143
Request all batch data jobs associated with the client access key with
144144
the optional query filters.
145145
146-
`GET /v0/batch.list_jobs` HTTP API endpoint.
146+
Makes a `GET /v0/batch.list_jobs` HTTP request.
147147
148148
Parameters
149149
----------

databento/historical/api/metadata.py

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def list_datasets(
3030
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
3131
) -> List[str]:
3232
"""
33-
Request the available datasets from the API server.
33+
List all datasets available from Databento.
3434
35-
`GET /v0/metadata.list_datasets` HTTP API endpoint.
35+
Makes a `GET /v0/metadata.list_datasets` HTTP request.
3636
3737
Parameters
3838
----------
@@ -47,6 +47,17 @@ def list_datasets(
4747
-------
4848
List[str]
4949
50+
Notes
51+
-----
52+
We use dataset names in the form `PUBLISHER.DATASET` for each dataset,
53+
where each publisher is represented by a 4 character code, which is
54+
usually its ISO 10383 [Market Identifier Code (MIC)](https://www.iso20022.org/market-identifier-codes). # noqa
55+
These dataset names are also found on the [Explore]() and [Quick Download]()
56+
features of the Databento user portal.
57+
58+
Use this method to list the _names_ of all available datasets, so you can use
59+
other methods which take the `dataset` parameter.
60+
5061
"""
5162
start = maybe_datetime_to_string(start)
5263
end = maybe_datetime_to_string(end)
@@ -70,9 +81,9 @@ def list_schemas(
7081
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
7182
) -> List[str]:
7283
"""
73-
Request the available data record schemas from the API server.
84+
List all data schemas available from Databento.
7485
75-
`GET /v0/metadata.list_schemas` HTTP API endpoint.
86+
Makes a `GET /v0/metadata.list_schemas` HTTP request.
7687
7788
Parameters
7889
----------
@@ -114,9 +125,12 @@ def list_fields(
114125
encoding: Optional[Union[Encoding, str]] = None,
115126
) -> Dict[str, Dict]:
116127
"""
117-
Request the data record fields from the API server.
128+
List all fields for a dataset, schema and encoding from Databento.
118129
119-
`GET /v0/metadata.list_fields` HTTP API endpoint.
130+
Makes a `GET /v0/metadata.list_fields` HTTP request.
131+
132+
The `schema` and `encoding` parameters act as optional filters. All
133+
metadata for that parameter is returned if they are not specified.
120134
121135
Parameters
122136
----------
@@ -125,7 +139,7 @@ def list_fields(
125139
schema : Schema or str {'mbo', 'mbp-1', 'mbp-10', 'trades', 'tbbo', 'ohlcv-1s', 'ohlcv-1m', 'ohlcv-1h', 'ohlcv-1d', 'definition', 'statistics', 'status'}, optional # noqa
126140
The data record schema for the request.
127141
encoding : Encoding or str {'dbz', 'csv', 'json'}, optional
128-
The data output encoding.
142+
The data encoding.
129143
130144
Returns
131145
-------
@@ -155,9 +169,9 @@ def list_fields(
155169

156170
def list_encodings(self) -> List[str]:
157171
"""
158-
Request the available encoding options from the API server.
172+
List all data encodings available from Databento.
159173
160-
`GET /v0/metadata.list_encodings` HTTP API endpoint.
174+
Makes a `GET /v0/metadata.list_encodings` HTTP request.
161175
162176
Returns
163177
-------
@@ -172,9 +186,9 @@ def list_encodings(self) -> List[str]:
172186

173187
def list_compressions(self) -> List[str]:
174188
"""
175-
Request the available compression options from the API server.
189+
List all data compression modes available from Databento.
176190
177-
`GET /v0/metadata.list_compressions` HTTP API endpoint.
191+
Makes a `GET /v0/metadata.list_compressions` HTTP request.
178192
179193
Returns
180194
-------
@@ -192,11 +206,11 @@ def list_unit_prices(
192206
dataset: Union[Dataset, str],
193207
mode: Optional[Union[FeedMode, str]] = None,
194208
schema: Optional[Union[Schema, str]] = None,
195-
) -> Union[Dict[str, Any], float]:
209+
) -> Dict[str, Any]:
196210
"""
197-
Request the data prices per unit GB from the API server.
211+
List data schema prices per GB unit from Databento.
198212
199-
`GET /v0/metadata.list_unit_prices` HTTP API endpoint.
213+
Makes a `GET /v0/metadata.list_unit_prices` HTTP request.
200214
201215
Parameters
202216
----------
@@ -209,8 +223,8 @@ def list_unit_prices(
209223
210224
Returns
211225
-------
212-
Dict[str, Any] or float
213-
A map of unit prices filtered on the given optional parameters.
226+
Dict[str, Any]
227+
A map of dataset to feed mode to unit price.
214228
215229
"""
216230
validate_maybe_enum(schema, Schema, "schema")
@@ -243,11 +257,11 @@ def get_shape(
243257
encoding: Union[Encoding, str] = "dbz",
244258
stype_in: Optional[Union[SType, str]] = "native",
245259
limit: Optional[int] = None,
246-
) -> Tuple[int, int]:
260+
) -> Tuple:
247261
"""
248-
Request the shape of the timeseries data as a rows and columns tuple.
262+
Get the shape of the time series data query.
249263
250-
GET `/v0/metadata.get_shape` HTTP API endpoint.
264+
Makes a GET `/v0/metadata.get_shape` HTTP request.
251265
252266
Parameters
253267
----------
@@ -264,15 +278,15 @@ def get_shape(
264278
The end datetime for the request range (UTC).
265279
If using an integer then this represents nanoseconds since UNIX epoch.
266280
encoding : Encoding or str {'dbz', 'csv', 'json'}, optional
267-
The data output encoding.
281+
The data encoding.
268282
stype_in : SType or str, default 'native'
269283
The input symbol type to resolve from.
270284
limit : int, optional
271-
The maximum number of records for the request.
285+
The maximum number of records to include in the query.
272286
273287
Returns
274288
-------
275-
Tuple[int, int]
289+
Tuple
276290
277291
"""
278292
validate_enum(schema, Schema, "schema")
@@ -319,9 +333,10 @@ def get_billable_size(
319333
limit: Optional[int] = None,
320334
) -> int:
321335
"""
322-
Request the uncompressed binary size of the data stream (used for billing).
336+
Get the raw uncompressed binary size of a historical streaming or batch
337+
data request, which would be used for billing.
323338
324-
GET `/v0/metadata.get_billable_size` HTTP API endpoint.
339+
Makes a GET `/v0/metadata.get_billable_size` HTTP request.
325340
326341
Parameters
327342
----------
@@ -340,12 +355,12 @@ def get_billable_size(
340355
stype_in : SType or str, default 'native'
341356
The input symbol type to resolve from.
342357
limit : int, optional
343-
The maximum number of records for the request.
358+
The maximum number of records to include in the query.
344359
345360
Returns
346361
-------
347362
int
348-
The uncompressed size of the data in bytes.
363+
The size in number of bytes used for billing.
349364
350365
"""
351366
validate_enum(schema, Schema, "schema")
@@ -384,9 +399,9 @@ def get_cost(
384399
limit: Optional[int] = None,
385400
) -> float:
386401
"""
387-
Request the expected total cost of the data stream.
402+
Get the expected total cost of the data stream.
388403
389-
`GET /v0/metadata.get_cost` HTTP API endpoint.
404+
Makes a `GET /v0/metadata.get_cost` HTTP request.
390405
391406
Parameters
392407
----------
@@ -407,7 +422,7 @@ def get_cost(
407422
stype_in : SType or str, default 'native'
408423
The input symbol type to resolve from.
409424
limit : int, optional
410-
The maximum number of records for the request.
425+
The maximum number of records to include in the query.
411426
412427
Returns
413428
-------

databento/historical/api/symbology.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def resolve(
3131
"""
3232
Request symbology resolution.
3333
34-
`GET /v0/symbology.resolve` HTTP API endpoint.
34+
Makes a `GET /v0/symbology.resolve` HTTP request.
3535
3636
Parameters
3737
----------

databento/historical/api/timeseries.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def stream(
3939
"""
4040
Request a historical time series stream from the Databento API servers.
4141
42-
`GET /v0/timeseries.stream` HTTP API endpoint.
42+
Makes a `GET /v0/timeseries.stream` HTTP request.
4343
4444
Parameters
4545
----------
@@ -60,7 +60,7 @@ def stream(
6060
stype_out : SType or str, default 'product_id'
6161
The output symbol type to resolve to.
6262
limit : int, optional
63-
The maximum number of records for the request.
63+
The maximum number of records to return.
6464
path : str, optional
6565
The path to the file to write to on disk (if provided).
6666
@@ -132,7 +132,7 @@ async def stream_async(
132132
Request a historical time series stream from the Databento API servers
133133
asynchronously.
134134
135-
`GET /v0/timeseries.stream` HTTP API endpoint.
135+
Makes a `GET /v0/timeseries.stream` HTTP request.
136136
137137
Parameters
138138
----------
@@ -153,7 +153,7 @@ async def stream_async(
153153
stype_out : SType or str, default 'product_id'
154154
The output symbol type to resolve to.
155155
limit : int, optional
156-
The maximum number of records for the request.
156+
The maximum number of records to return.
157157
path : str, optional
158158
The path to the file to write to (if provided).
159159

databento/historical/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def request_symbology(self, data: Bento) -> Dict[str, Dict[str, Any]]:
8585
"""
8686
Request symbology resolution based on the metadata properties.
8787
88-
`GET /v0/symbology.resolve` HTTP API endpoint.
88+
Makes a `GET /v0/symbology.resolve` HTTP request.
8989
9090
Current symbology mappings from the metadata are also available by
9191
calling the `.symbology` or `.mappings` properties.
@@ -118,7 +118,7 @@ def request_full_definitions(
118118
"""
119119
Request full instrument definitions based on the metadata properties.
120120
121-
`GET /v0/timeseries.stream` HTTP API endpoint.
121+
Makes a `GET /v0/timeseries.stream` HTTP request.
122122
123123
Parameters
124124
----------

examples/historical_metadata_get_shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
key = "YOUR_ACCESS_KEY"
1010
client = db.Historical(key=key)
1111

12-
shape: Tuple[int, int] = client.metadata.get_shape(
12+
shape: Tuple = client.metadata.get_shape(
1313
dataset="GLBX.MDP3",
1414
symbols=["ESH1"],
1515
schema="mbo",
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pprint import pprint
22

33
import databento as db
4-
from databento.common.enums import FeedMode
54

65

76
if __name__ == "__main__":
@@ -12,8 +11,7 @@
1211

1312
unit_prices = client.metadata.list_unit_prices(
1413
dataset="GLBX.MDP3",
15-
mode=FeedMode.HISTORICAL,
16-
schema="mbo",
14+
mode="historical-streaming",
1715
)
1816

1917
pprint(unit_prices)

0 commit comments

Comments
 (0)