Skip to content

Commit 616866a

Browse files
committed
MOD: Update corporate actions API
1 parent 285b8a5 commit 616866a

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

databento/reference/api/corporate.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
from databento.common.http import BentoHttpAPI
1414
from databento.common.parsing import convert_date_columns
1515
from databento.common.parsing import convert_datetime_columns
16-
from databento.common.parsing import datetime_to_date_string
17-
from databento.common.parsing import optional_date_to_string
16+
from databento.common.parsing import datetime_to_string
17+
from databento.common.parsing import optional_datetime_to_string
1818
from databento.common.parsing import optional_symbols_list_to_list
19-
from databento.common.publishers import Dataset
20-
from databento.common.validation import validate_semantic_string
2119

2220

2321
class CorporateActionsHttpAPI(BentoHttpAPI):
@@ -31,12 +29,12 @@ def __init__(self, key: str, gateway: str) -> None:
3129

3230
def get_range(
3331
self,
34-
start_date: date | str,
35-
end_date: date | str | None = None,
36-
dataset: Dataset | str | None = None,
32+
start: pd.Timestamp | date | str | int,
33+
end: pd.Timestamp | date | str | int | None = None,
3734
symbols: Iterable[str] | str | None = None,
3835
stype_in: SType | str = "raw_symbol",
3936
events: Iterable[str] | str | None = None,
37+
us_only: bool = False,
4038
) -> pd.DataFrame:
4139
"""
4240
Request a new corporate actions time series from Databento.
@@ -45,12 +43,16 @@ def get_range(
4543
4644
Parameters
4745
----------
48-
start_date : date or str
49-
The start date (UTC) of the request time range (inclusive).
50-
end_date : date or str, optional
51-
The end date (UTC) of the request time range (exclusive).
52-
dataset : Dataset or str, optional
53-
The dataset code (string identifier) for the request.
46+
start : pd.Timestamp or date or str or int
47+
The start datetime of the request time range (inclusive).
48+
Assumes UTC as timezone unless passed a tz-aware object.
49+
If an integer is passed, then this represents nanoseconds since the UNIX epoch.
50+
end : pd.Timestamp or date or str or int, optional
51+
The end datetime of the request time range (exclusive).
52+
Assumes UTC as timezone unless passed a tz-aware object.
53+
If an integer is passed, then this represents nanoseconds since the UNIX epoch.
54+
Values are forward filled based on the resolution provided.
55+
Defaults to the same value as `start`.
5456
symbols : Iterable[str] or str, optional
5557
The symbols to filter for. Takes up to 2,000 symbols per request.
5658
If more than 1 symbol is specified, the data is merged and sorted by time.
@@ -64,26 +66,27 @@ def get_range(
6466
Takes any number of event types per request.
6567
If not specified then will be for **all** event types.
6668
See [EVENT](https://databento.com/docs/standards-and-conventions/reference-data-enums#event) enum.
69+
us_only : bool, default False
70+
If filtering for US markets only.
6771
6872
Returns
6973
-------
7074
pandas.DataFrame
7175
The data converted into a data frame.
7276
7377
"""
74-
dataset = validate_semantic_string(dataset, "dataset") if dataset is not None else None
7578
symbols_list = optional_symbols_list_to_list(symbols, SType.RAW_SYMBOL)
7679

7780
if isinstance(events, str):
7881
events = events.strip().strip(",").split(",")
7982

8083
data: dict[str, object | None] = {
81-
"start_date": datetime_to_date_string(start_date),
82-
"end_date": optional_date_to_string(end_date),
83-
"dataset": dataset,
84+
"start": datetime_to_string(start),
85+
"end": optional_datetime_to_string(end),
8486
"symbols": ",".join(symbols_list),
8587
"stype_in": stype_in,
8688
"events": ",".join(events) if events else None,
89+
"us_only": us_only,
8790
}
8891

8992
response = self._post(

examples/reference_corporate_actions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
client = Reference(key=key)
1010

1111
response: pd.DataFrame = client.corporate_actions.get_range(
12-
dataset="XNAS.ITCH",
1312
symbols="AAPL,MSFT,TSLA",
1413
stype_in="raw_symbol",
15-
start_date="2023",
16-
end_date="2024-04",
14+
start="2023",
15+
end="2024-04",
1716
events="DIV,LIQ",
17+
us_only=True,
1818
)
1919

2020
pprint(response.head())

tests/test_reference_corporate.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ def test_corporate_actions_get_range_sends_expected_request(
5252

5353
# Act
5454
reference_client.corporate_actions.get_range(
55-
dataset=None,
5655
symbols="AAPL",
5756
stype_in="raw_symbol",
58-
start_date="2024-01",
59-
end_date="2024-04",
57+
start="2024-01",
58+
end="2024-04",
6059
events=events,
6160
)
6261

@@ -69,12 +68,12 @@ def test_corporate_actions_get_range_sends_expected_request(
6968
assert call["headers"]["accept"] == "application/json"
7069
assert all(v in call["headers"]["user-agent"] for v in ("Databento/", "Python/"))
7170
assert call["data"] == {
72-
"dataset": None,
73-
"start_date": "2024-01",
74-
"end_date": "2024-04",
71+
"start": "2024-01",
72+
"end": "2024-04",
7573
"symbols": "AAPL",
7674
"stype_in": "raw_symbol",
7775
"events": data_events,
76+
"us_only": False,
7877
}
7978
assert call["timeout"] == (100, 100)
8079
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
@@ -94,11 +93,10 @@ def test_corporate_actions_get_range_response_parsing(
9493

9594
# Act
9695
df_raw = reference_client.corporate_actions.get_range(
97-
dataset=None,
9896
symbols="AAPL",
9997
stype_in="raw_symbol",
100-
start_date="2024-01",
101-
end_date="2024-04",
98+
start="2024-01",
99+
end="2024-04",
102100
)
103101

104102
# Assert

0 commit comments

Comments
 (0)