Skip to content

Commit 6726ae4

Browse files
committed
MOD: Remove get_license_free from public API
1 parent 618948a commit 6726ae4

File tree

3 files changed

+11
-106
lines changed

3 files changed

+11
-106
lines changed

databento/historical/api/metadata.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
maybe_datetime_to_string,
1010
maybe_enum_or_str_lowercase,
1111
maybe_symbols_list_to_string,
12-
values_list_to_string,
1312
)
1413
from databento.common.validation import validate_enum, validate_maybe_enum
1514
from databento.historical.api import API_VERSION
@@ -467,43 +466,3 @@ def get_cost(
467466
)
468467

469468
return response.json()
470-
471-
def get_license_fee(
472-
self,
473-
dataset: Union[Dataset, str],
474-
purposes: Union[List[str], str],
475-
) -> int:
476-
"""
477-
Request the license fee in US Dollars for a dataset and access purposes
478-
from Databento.
479-
480-
Makes a `GET /metadata.get_license_fee` HTTP request.
481-
482-
Parameters
483-
----------
484-
dataset : Dataset or str
485-
The dataset name for the request.
486-
purposes : List[str] or str, {'professional trading', 'display usage', 'non-display usage', 'external redistribution', 'internal redistribution'} # noqa
487-
The licensing purposes.
488-
489-
Returns
490-
-------
491-
int
492-
The license fee in US Dollars.
493-
494-
"""
495-
dataset = enum_or_str_lowercase(dataset, "dataset")
496-
purposes = values_list_to_string(purposes)
497-
498-
params: List[Tuple[str, str]] = [
499-
("dataset", dataset),
500-
("purposes", purposes),
501-
]
502-
503-
response: Response = self._get(
504-
url=self._base_url + ".get_license_fee",
505-
params=params,
506-
basic_auth=True,
507-
)
508-
509-
return response.json()

databento/historical/api/timeseries.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import warnings
22
from datetime import date
3-
from typing import Any, List, Optional, Tuple, Union
3+
from typing import List, Optional, Tuple, Union
44

55
import pandas as pd
66
from databento.common.bento import Bento
77
from databento.common.enums import Compression, Dataset, Encoding, Schema, SType
8-
from databento.common.logging import log_debug
98
from databento.common.validation import validate_enum
109
from databento.historical.api import API_VERSION
1110
from databento.historical.http import BentoHttpAPI
12-
from requests import Response
13-
14-
15-
_5GB = 1024**3 * 5
1611

1712

1813
class TimeSeriesHttpAPI(BentoHttpAPI):
@@ -107,7 +102,6 @@ def stream(
107102
start=start,
108103
end=end,
109104
limit=limit,
110-
params=params,
111105
)
112106

113107
bento: Bento = self._create_bento(path=path)
@@ -204,7 +198,6 @@ async def stream_async(
204198
start=start,
205199
end=end,
206200
limit=limit,
207-
params=params,
208201
)
209202

210203
bento: Bento = self._create_bento(path=path)
@@ -225,44 +218,26 @@ def _pre_check_data_size(
225218
start: Optional[Union[pd.Timestamp, date, str, int]],
226219
end: Optional[Union[pd.Timestamp, date, str, int]],
227220
limit: Optional[int],
228-
params: List[Tuple[str, Any]],
229221
):
230222
if limit and limit < 10**7:
231223
return
232224

225+
# Use heuristics to check ballpark data size
233226
if (
234227
_is_large_data_size_schema(schema)
235228
or _is_greater_than_one_day(start, end)
236229
or _is_large_number_of_symbols(symbols)
237230
):
238-
params = params[:] # copy
239-
params.append(("mode", "historical-streaming"))
240-
params.append(("instruments", str(len(symbols))))
241-
log_debug(
242-
"Checking estimated data size for potentially large streaming "
243-
"request...",
244-
)
245-
response: Response = self._get(
246-
url=self._gateway + f"/v{API_VERSION}/metadata.get_size_estimation",
247-
params=params,
248-
basic_auth=True,
249-
)
250-
251-
size: int = response.json()["size"]
252-
log_debug(
253-
f"Requesting data stream for {size:,} bytes (binary uncompressed)...",
231+
warnings.warn(
232+
"\nThe size of the current streaming request is estimated "
233+
"to be 5 GB or greater. We recommend smaller "
234+
"individual streaming request sizes, or alternatively "
235+
"submit a batch data request."
236+
"\nYou can check the uncompressed binary size of a request "
237+
"through the metadata API (from the client library, or over "
238+
"HTTP).\nThis warning can be suppressed "
239+
"https://docs.python.org/3/library/warnings.html",
254240
)
255-
if size > _5GB:
256-
warnings.warn(
257-
f"\nThe size of the current streaming request is estimated "
258-
f"to exceed 5GB ({_5GB:,} bytes). We recommend smaller "
259-
f"individual streaming request sizes, or alternatively "
260-
f"submit a batch data request."
261-
f"\nYou can check the uncompressed binary size of a request "
262-
f"through the metadata API (from the client library, or over "
263-
f"HTTP).\nThis warning can be suppressed "
264-
f"https://docs.python.org/3/library/warnings.html",
265-
)
266241

267242

268243
def _is_large_number_of_symbols(symbols: Optional[Union[List[str], str]]):

tests/test_historical_metadata.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -295,32 +295,3 @@ def test_get_cost_sends_expected_request(self, mocker) -> None:
295295
]
296296
assert call["timeout"] == (100, 100)
297297
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
298-
299-
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
300-
def test_get_license_fee_sends_expected_request(self, mocker) -> None:
301-
# Arrange
302-
mocked_get = mocker.patch("requests.get")
303-
304-
# Act
305-
self.client.metadata.get_license_fee(
306-
dataset="GLBX.MDP3",
307-
purposes="professional trading",
308-
)
309-
310-
# Assert
311-
call = mocked_get.call_args.kwargs
312-
assert (
313-
call["url"]
314-
== f"https://hist.databento.com/v{db.API_VERSION}/metadata.get_license_fee"
315-
)
316-
assert sorted(call["headers"].keys()) == ["accept", "user-agent"]
317-
assert call["headers"]["accept"] == "application/json"
318-
assert all(
319-
v in call["headers"]["user-agent"] for v in ("Databento/", "Python/")
320-
)
321-
assert call["params"] == [
322-
("dataset", "glbx.mdp3"),
323-
("purposes", "professional trading"),
324-
]
325-
assert call["timeout"] == (100, 100)
326-
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)

0 commit comments

Comments
 (0)