Skip to content

Commit 33d75be

Browse files
committed
MOD: Standardize Python client API with backend
1 parent 7b9b5b5 commit 33d75be

File tree

8 files changed

+66
-66
lines changed

8 files changed

+66
-66
lines changed

databento/historical/api/batch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ def submit_job(
115115

116116
params: List[Tuple[str, str]] = BentoHttpAPI._timeseries_params(
117117
dataset=dataset,
118-
symbols=symbols,
119-
schema=Schema(schema),
120118
start=start,
121119
end=end,
120+
symbols=symbols,
121+
schema=Schema(schema),
122122
limit=limit,
123123
stype_in=SType(stype_in),
124124
stype_out=SType(stype_out),

databento/historical/api/metadata.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ def list_unit_prices(
244244
def get_shape(
245245
self,
246246
dataset: Union[Dataset, str],
247+
start: Union[pd.Timestamp, date, str, int],
248+
end: Union[pd.Timestamp, date, str, int],
247249
symbols: Optional[Union[List[str], str]] = None,
248250
schema: Union[Schema, str] = "trades",
249-
start: Optional[Union[pd.Timestamp, date, str, int]] = None,
250-
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
251251
encoding: Union[Encoding, str] = "dbz",
252252
stype_in: Optional[Union[SType, str]] = "native",
253253
limit: Optional[int] = None,
@@ -261,17 +261,17 @@ def get_shape(
261261
----------
262262
dataset : Dataset or str
263263
The dataset code for the request.
264+
start : pd.Timestamp or date or str or int
265+
The start datetime for the request range. Assumes UTC as timezone unless otherwise specified.
266+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
267+
end : pd.Timestamp or date or str or int
268+
The end datetime for the request range. Assumes UTC as timezone unless otherwise specified.
269+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
264270
symbols : List[Union[str, int]] or str, optional
265271
The product symbols to filter for. Takes up to 2,000 symbols per request.
266272
If `*` or ``None`` then will be for **all** symbols.
267273
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
268274
The data record schema for the request.
269-
start : pd.Timestamp or date or str or int, optional
270-
The start datetime for the request range. Assumes UTC as timezone unless otherwise specified.
271-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
272-
end : pd.Timestamp or date or str or int, optional
273-
The end datetime for the request range. Assumes UTC as timezone unless otherwise specified.
274-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
275275
encoding : Encoding or str {'dbz', 'csv', 'json'}, optional
276276
The data encoding.
277277
stype_in : SType or str, default 'native'
@@ -313,10 +313,10 @@ def get_shape(
313313
def get_billable_size(
314314
self,
315315
dataset: Union[Dataset, str],
316+
start: Union[pd.Timestamp, date, str, int],
317+
end: Union[pd.Timestamp, date, str, int],
316318
symbols: Optional[Union[List[str], str]] = None,
317319
schema: Union[Schema, str] = "trades",
318-
start: Optional[Union[pd.Timestamp, date, str, int]] = None,
319-
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
320320
stype_in: Optional[Union[SType, str]] = "native",
321321
limit: Optional[int] = None,
322322
) -> int:
@@ -330,17 +330,17 @@ def get_billable_size(
330330
----------
331331
dataset : Dataset or str
332332
The dataset code for the request.
333-
symbols : List[Union[str, int]] or str, optional
334-
The product symbols to filter for. Takes up to 2,000 symbols per request.
335-
If `*` or ``None`` then will be for **all** symbols.
336-
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
337-
The data record schema for the request.
338333
start : pd.Timestamp or date or str or int, optional
339334
The start datetime for the request range. Assumes UTC as timezone unless otherwise specified.
340335
If an integer is passed, then this represents nanoseconds since UNIX epoch.
341336
end : pd.Timestamp or date or str or int, optional
342337
The end datetime for the request range. Assumes UTC as timezone unless otherwise specified.
343338
If an integer is passed, then this represents nanoseconds since UNIX epoch.
339+
symbols : List[Union[str, int]] or str, optional
340+
The product symbols to filter for. Takes up to 2,000 symbols per request.
341+
If `*` or ``None`` then will be for **all** symbols.
342+
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
343+
The data record schema for the request.
344344
stype_in : SType or str, default 'native'
345345
The input symbology type to resolve from.
346346
limit : int, optional
@@ -357,10 +357,10 @@ def get_billable_size(
357357

358358
params: List[Tuple[str, str]] = super()._timeseries_params(
359359
dataset=dataset,
360-
symbols=symbols,
361-
schema=Schema(schema),
362360
start=start,
363361
end=end,
362+
symbols=symbols,
363+
schema=Schema(schema),
364364
stype_in=SType(stype_in),
365365
limit=limit,
366366
)
@@ -376,11 +376,11 @@ def get_billable_size(
376376
def get_cost(
377377
self,
378378
dataset: Union[Dataset, str],
379+
start: Union[pd.Timestamp, date, str, int],
380+
end: Union[pd.Timestamp, date, str, int],
379381
mode: Union[FeedMode, str] = "historical-streaming",
380382
symbols: Optional[Union[List[str], str]] = None,
381383
schema: Union[Schema, str] = "trades",
382-
start: Optional[Union[pd.Timestamp, date, str, int]] = None,
383-
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
384384
stype_in: Optional[Union[SType, str]] = "native",
385385
limit: Optional[int] = None,
386386
) -> float:
@@ -394,19 +394,19 @@ def get_cost(
394394
----------
395395
dataset : Dataset or str
396396
The dataset code for the request.
397+
start : pd.Timestamp or date or str or int
398+
The start datetime for the request range. Assumes UTC as timezone unless otherwise specified.
399+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
400+
end : pd.Timestamp or date or str or int
401+
The end datetime for the request range. Assumes UTC as timezone unless otherwise specified.
402+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
397403
mode : FeedMode or str {'live', 'historical-streaming', 'historical'}, default 'historical-streaming'
398404
The data feed mode for the request.
399405
symbols : List[Union[str, int]] or str, optional
400406
The product symbols to filter for. Takes up to 2,000 symbols per request.
401407
If `*` or ``None`` then will be for **all** symbols.
402408
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
403409
The data record schema for the request.
404-
start : pd.Timestamp or date or str or int, optional
405-
The start datetime for the request range. Assumes UTC as timezone unless otherwise specified.
406-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
407-
end : pd.Timestamp or date or str or int, optional
408-
The end datetime for the request range. Assumes UTC as timezone unless otherwise specified.
409-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
410410
stype_in : SType or str, default 'native'
411411
The input symbology type to resolve from.
412412
limit : int, optional
@@ -424,10 +424,10 @@ def get_cost(
424424

425425
params: List[Tuple[str, str]] = super()._timeseries_params(
426426
dataset=dataset,
427-
symbols=symbols,
428-
schema=Schema(schema),
429427
start=start,
430428
end=end,
429+
symbols=symbols,
430+
schema=Schema(schema),
431431
stype_in=SType(stype_in),
432432
limit=limit,
433433
)

databento/historical/api/timeseries.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def __init__(self, key: str, gateway: str) -> None:
2222
def stream(
2323
self,
2424
dataset: Union[Dataset, str],
25+
start: Union[pd.Timestamp, date, str, int],
26+
end: Union[pd.Timestamp, date, str, int],
2527
symbols: Optional[Union[List[str], str]] = None,
2628
schema: Union[Schema, str] = "trades",
27-
start: Optional[Union[pd.Timestamp, date, str, int]] = None,
28-
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
2929
stype_in: Union[SType, str] = "native",
3030
stype_out: Union[SType, str] = "product_id",
3131
limit: Optional[int] = None,
@@ -40,18 +40,18 @@ def stream(
4040
----------
4141
dataset : Dataset or str
4242
The dataset code (string identifier) for the request.
43+
start : pd.Timestamp or date or str or int
44+
The start datetime (UTC) of the request time range (inclusive).
45+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
46+
end : pd.Timestamp or date or str or int
47+
The end datetime (UTC) of the request time range (exclusive).
48+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
4349
symbols : List[Union[str, int]] or str, optional
4450
The product symbols to filter for. Takes up to 2,000 symbols per request.
4551
If more than 1 symbol is specified, the data is merged and sorted by time.
4652
If `*` or ``None`` then will be for **all** symbols.
4753
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
4854
The data record schema for the request.
49-
start : pd.Timestamp or date or str or int, optional
50-
The start datetime (UTC) of the request time range (inclusive).
51-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
52-
end : pd.Timestamp or date or str or int, optional
53-
The end datetime (UTC) of the request time range (exclusive).
54-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
5555
stype_in : SType or str, default 'native'
5656
The input symbology type to resolve from.
5757
stype_out : SType or str, default 'product_id'
@@ -81,10 +81,10 @@ def stream(
8181

8282
params: List[Tuple[str, str]] = BentoHttpAPI._timeseries_params(
8383
dataset=dataset,
84-
symbols=symbols,
85-
schema=Schema(schema),
8684
start=start,
8785
end=end,
86+
symbols=symbols,
87+
schema=Schema(schema),
8888
stype_in=SType(stype_in),
8989
stype_out=SType(stype_out),
9090
limit=limit,
@@ -114,10 +114,10 @@ def stream(
114114
async def stream_async(
115115
self,
116116
dataset: Union[Dataset, str],
117+
start: Union[pd.Timestamp, date, str, int],
118+
end: Union[pd.Timestamp, date, str, int],
117119
symbols: Optional[Union[List[str], str]] = None,
118120
schema: Union[Schema, str] = "trades",
119-
start: Optional[Union[pd.Timestamp, date, str, int]] = None,
120-
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
121121
stype_in: Union[SType, str] = "native",
122122
stype_out: Union[SType, str] = "product_id",
123123
limit: Optional[int] = None,
@@ -132,18 +132,18 @@ async def stream_async(
132132
----------
133133
dataset : Dataset or str
134134
The dataset code (string identifier) for the request.
135+
start : pd.Timestamp or date or str or int
136+
The start datetime (UTC) of the request time range (inclusive).
137+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
138+
end : pd.Timestamp or date or str or int
139+
The end datetime (UTC) of the request time range (exclusive).
140+
If an integer is passed, then this represents nanoseconds since UNIX epoch.
135141
symbols : List[Union[str, int]] or str, optional
136142
The product symbols to filter for. Takes up to 2,000 symbols per request.
137143
If more than 1 symbol is specified, the data is merged and sorted by time.
138144
If `*` or ``None`` then will be for **all** symbols.
139145
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
140146
The data record schema for the request.
141-
start : pd.Timestamp or date or str or int, optional
142-
The start datetime (UTC) of the request time range (inclusive).
143-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
144-
end : pd.Timestamp or date or str or int, optional
145-
The end datetime (UTC) of the request time range (exclusive).
146-
If an integer is passed, then this represents nanoseconds since UNIX epoch.
147147
stype_in : SType or str, default 'native'
148148
The input symbology type to resolve from.
149149
stype_out : SType or str, default 'product_id'
@@ -173,10 +173,10 @@ async def stream_async(
173173

174174
params: List[Tuple[str, str]] = BentoHttpAPI._timeseries_params(
175175
dataset=dataset,
176-
symbols=symbols,
177-
schema=Schema(schema),
178176
start=start,
179177
end=end,
178+
symbols=symbols,
179+
schema=Schema(schema),
180180
stype_in=SType(stype_in),
181181
stype_out=SType(stype_out),
182182
limit=limit,

databento/historical/http.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ def __init__(self, key: str, gateway: str):
4242
def _timeseries_params(
4343
*,
4444
dataset: Union[Dataset, str],
45+
start: Union[pd.Timestamp, date, str, int],
46+
end: Union[pd.Timestamp, date, str, int],
4547
symbols: Optional[Union[List[str], str]] = None,
4648
schema: Schema,
47-
start: Optional[Union[pd.Timestamp, date, str, int]] = None,
48-
end: Optional[Union[pd.Timestamp, date, str, int]] = None,
4949
limit: Optional[int] = None,
5050
stype_in: SType,
5151
stype_out: SType = SType.PRODUCT_ID,
5252
) -> List[Tuple[str, str]]:
5353
# Parse inputs
5454
dataset = enum_or_str_lowercase(dataset, "dataset")
55-
symbols = maybe_symbols_list_to_string(symbols)
5655
start = maybe_datetime_to_string(start)
5756
end = maybe_datetime_to_string(end)
57+
symbols = maybe_symbols_list_to_string(symbols)
5858

5959
params: List[Tuple[str, Any]] = [
6060
("dataset", dataset),
61-
("symbols", symbols),
62-
("schema", schema.value),
6361
("start", start),
6462
("end", end),
63+
("symbols", symbols),
64+
("schema", schema.value),
6565
("stype_in", stype_in.value),
6666
("stype_out", stype_out.value),
6767
]

tests/test_historical_batch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ def test_batch_submit_job_sends_expected_request(
8484
)
8585
assert call["params"] == [
8686
("dataset", "glbx.mdp3"),
87-
("symbols", "ESH1"),
88-
("schema", "trades"),
8987
("start", "2020-12-28T12:00:00"),
9088
("end", "2020-12-29T00:00:00"),
89+
("symbols", "ESH1"),
90+
("schema", "trades"),
9191
("stype_in", "native"),
9292
("stype_out", "product_id"),
9393
("encoding", "csv"),

tests/test_historical_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ def test_request_full_definitions_expected_request(
119119
)
120120
assert call["params"] == [
121121
("dataset", "glbx.mdp3"),
122-
("symbols", "ESH1"),
123-
("schema", "definition"),
124122
("start", "2020-12-28T13:00:00+00:00"),
125123
("end", "2020-12-29T00:00:00+00:00"),
124+
("symbols", "ESH1"),
125+
("schema", "definition"),
126126
("stype_in", "native"),
127127
("stype_out", "product_id"),
128128
("encoding", "dbz"),

tests/test_historical_metadata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ def test_get_billable_size_sends_expected_request(
279279
)
280280
assert call["params"] == [
281281
("dataset", "glbx.mdp3"),
282-
("symbols", "ESH1"),
283-
("schema", "mbo"),
284282
("start", "2020-12-28T12:00:00"),
285283
("end", "2020-12-29T00:00:00"),
284+
("symbols", "ESH1"),
285+
("schema", "mbo"),
286286
("stype_in", "native"),
287287
("stype_out", "product_id"),
288288
("limit", "1000000"),
@@ -318,10 +318,10 @@ def test_get_cost_sends_expected_request(self, mocker: MockerFixture) -> None:
318318
)
319319
assert call["params"] == [
320320
("dataset", "glbx.mdp3"),
321-
("symbols", "ESH1"),
322-
("schema", "mbo"),
323321
("start", "2020-12-28T12:00:00"),
324322
("end", "2020-12-29T00:00:00"),
323+
("symbols", "ESH1"),
324+
("schema", "mbo"),
325325
("stype_in", "native"),
326326
("stype_out", "product_id"),
327327
("limit", "1000000"),

tests/test_historical_timeseries.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def test_stream_sends_expected_request(self, mocker: MockerFixture) -> None:
7373
)
7474
assert call["params"] == [
7575
("dataset", "glbx.mdp3"),
76-
("symbols", "ESH1"),
77-
("schema", "trades"),
7876
("start", "2020-12-28T12:00:00"),
7977
("end", "2020-12-29T00:00:00"),
78+
("symbols", "ESH1"),
79+
("schema", "trades"),
8080
("stype_in", "native"),
8181
("stype_out", "product_id"),
8282
("encoding", "dbz"),
@@ -114,10 +114,10 @@ def test_stream_with_limit_sends_expected_request(
114114
)
115115
assert call["params"] == [
116116
("dataset", "glbx.mdp3"),
117-
("symbols", "ESH1"),
118-
("schema", "trades"),
119117
("start", "2020-12-28T12:00:00"),
120118
("end", "2020-12-29T00:00:00"),
119+
("symbols", "ESH1"),
120+
("schema", "trades"),
121121
("stype_in", "native"),
122122
("stype_out", "product_id"),
123123
("limit", "1000000"),

0 commit comments

Comments
 (0)