Skip to content

Commit d959eeb

Browse files
committed
ADD: Add Python client corporate actions
1 parent 290451c commit d959eeb

21 files changed

+454
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
This release adds a new feature to the `Live` client for automatically reconnecting when an unexpected disconnection occurs.
66

77
#### Enhancements
8+
- Added `Reference` data client with `corporate_actions.get_range(...)` method
89
- Added `ReconnectPolicy` enumeration
910
- Added `reconnect_policy` parameter to the `Live` client to specify client reconnection behavior
1011
- Added `Live.add_reconnect_callback` method for specifying a callback to handle client reconnections

databento/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from databento_dbn import SystemMsg
2323
from databento_dbn import TradeMsg
2424

25+
from databento.common import API_VERSION
2526
from databento.common import bentologging
2627
from databento.common import symbology
2728
from databento.common.dbnstore import DBNStore
@@ -43,9 +44,9 @@
4344
from databento.common.publishers import Venue
4445
from databento.common.symbology import InstrumentMap
4546
from databento.common.types import DBNRecord
46-
from databento.historical.api import API_VERSION
4747
from databento.historical.client import Historical
4848
from databento.live.client import Live
49+
from databento.reference.client import Reference
4950
from databento.version import __version__ # noqa
5051

5152

@@ -73,6 +74,7 @@
7374
"HistoricalGateway",
7475
"InstrumentMap",
7576
"Live",
77+
"Reference",
7678
"Packaging",
7779
"ReconnectPolicy",
7880
"RollRule",

databento/common/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_VERSION = 0

databento/common/constants.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,36 @@
7373
Schema.BBO_1S: BBOMsg,
7474
Schema.BBO_1M: BBOMsg,
7575
}
76+
77+
78+
CORPORATE_ACTIONS_DATETIME_COLUMNS: Final[list[str]] = [
79+
"ts_record",
80+
"ts_created",
81+
]
82+
83+
CORPORATE_ACTIONS_DATE_COLUMNS: Final[list[str]] = [
84+
"event_date",
85+
"event_created_date",
86+
"effective_date",
87+
"ex_date",
88+
"record_date",
89+
"listing_date",
90+
"delisting_date",
91+
"payment_date",
92+
"duebills_redemption_date",
93+
"from_date",
94+
"to_date",
95+
"registration_date",
96+
"start_date",
97+
"end_date",
98+
"open_date",
99+
"close_date",
100+
"start_subscription_date",
101+
"end_subscription_date",
102+
"option_election_date",
103+
"withdrawal_right_from_date",
104+
"withdrawal_rights_to_date",
105+
"notification_date",
106+
"financial_year_end_date",
107+
"exp_completion_date",
108+
]

databento/common/parsing.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,81 @@ def optional_datetime_to_unix_nanoseconds(
310310
if value is None:
311311
return None
312312
return datetime_to_unix_nanoseconds(value)
313+
314+
315+
def convert_to_date(value: str) -> date | None:
316+
"""
317+
Convert the given `value` to a date (or None).
318+
319+
Parameters
320+
----------
321+
value : str
322+
The date string value to convert.
323+
324+
Returns
325+
-------
326+
datetime.date or `None`
327+
The corresponding `date` object if the conversion succeeds,
328+
or `None` if the input value cannot be converted.
329+
330+
"""
331+
# Calling `.date()` on a NaT value will retain the NaT value
332+
timestamp = pd.to_datetime(value, utc=True, errors="coerce")
333+
return timestamp.date() if pd.notna(timestamp) else None
334+
335+
336+
def convert_to_datetime(value: str) -> pd.Timestamp | None:
337+
"""
338+
Convert the given `value` to a pandas Timestamp (or None).
339+
340+
Parameters
341+
----------
342+
value : str
343+
The datetime string value to convert.
344+
345+
Returns
346+
-------
347+
pandas.Timestamp or None
348+
The corresponding `Timestamp` object if the conversion succeeds,
349+
or `None` if the input value cannot be converted.
350+
351+
"""
352+
return pd.to_datetime(value, utc=True, errors="coerce")
353+
354+
355+
def convert_date_columns(df: pd.DataFrame, columns: list[str]) -> None:
356+
"""
357+
Convert the specified columns in a DataFrame to date objects.
358+
359+
The function modifies the input DataFrame in place.
360+
361+
Parameters
362+
----------
363+
df : pandas.DataFrame
364+
The pandas DataFrame to modify.
365+
columns : List[str]
366+
The column names to convert.
367+
368+
"""
369+
for column in columns:
370+
if column not in df:
371+
continue
372+
df[column] = df[column].apply(convert_to_date)
373+
374+
375+
def convert_datetime_columns(df: pd.DataFrame, columns: list[str]) -> None:
376+
"""
377+
Convert the specified columns in a DataFrame to pandas Timestamp objects.
378+
379+
Parameters
380+
----------
381+
df : pandas.DataFrame
382+
The pandas DataFrame to modify.
383+
columns : List[str]
384+
The column names to convert.
385+
386+
"""
387+
for column in columns:
388+
if column not in df:
389+
continue
390+
df[column] = df[column].apply(convert_to_datetime)
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
API_VERSION = 0
2-
ALL_SYMBOLS = "ALL_SYMBOLS"

databento/historical/api/batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
from databento_dbn import SType
2525
from requests.auth import HTTPBasicAuth
2626

27+
from databento.common import API_VERSION
2728
from databento.common.constants import HTTP_STREAMING_READ_SIZE
2829
from databento.common.enums import Delivery
2930
from databento.common.enums import Packaging
3031
from databento.common.enums import SplitDuration
3132
from databento.common.error import BentoError
3233
from databento.common.error import BentoHttpError
3334
from databento.common.error import BentoWarning
35+
from databento.common.http import BentoHttpAPI
36+
from databento.common.http import check_http_error
3437
from databento.common.parsing import datetime_to_string
3538
from databento.common.parsing import optional_datetime_to_string
3639
from databento.common.parsing import optional_symbols_list_to_list
@@ -40,9 +43,6 @@
4043
from databento.common.validation import validate_enum
4144
from databento.common.validation import validate_path
4245
from databento.common.validation import validate_semantic_string
43-
from databento.historical.api import API_VERSION
44-
from databento.historical.http import BentoHttpAPI
45-
from databento.historical.http import check_http_error
4646

4747

4848
logger = logging.getLogger(__name__)

databento/historical/api/metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
from databento_dbn import SType
1111
from requests import Response
1212

13+
from databento.common import API_VERSION
1314
from databento.common.enums import FeedMode
15+
from databento.common.http import BentoHttpAPI
1416
from databento.common.parsing import datetime_to_string
1517
from databento.common.parsing import optional_date_to_string
1618
from databento.common.parsing import optional_datetime_to_string
1719
from databento.common.parsing import optional_symbols_list_to_list
1820
from databento.common.publishers import Dataset
1921
from databento.common.validation import validate_enum
2022
from databento.common.validation import validate_semantic_string
21-
from databento.historical.api import API_VERSION
22-
from databento.historical.http import BentoHttpAPI
2323

2424

2525
class MetadataHttpAPI(BentoHttpAPI):

databento/historical/api/symbology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from databento_dbn import SType
88
from requests import Response
99

10+
from databento.common import API_VERSION
11+
from databento.common.http import BentoHttpAPI
1012
from databento.common.parsing import datetime_to_date_string
1113
from databento.common.parsing import optional_date_to_string
1214
from databento.common.parsing import optional_symbols_list_to_list
1315
from databento.common.publishers import Dataset
1416
from databento.common.validation import validate_enum
1517
from databento.common.validation import validate_semantic_string
16-
from databento.historical.api import API_VERSION
17-
from databento.historical.http import BentoHttpAPI
1818

1919

2020
class SymbologyHttpAPI(BentoHttpAPI):

0 commit comments

Comments
 (0)