Skip to content

Commit de7eab9

Browse files
authored
VER: Release 0.38.0
2 parents 5592db7 + dd450ef commit de7eab9

35 files changed

+1162
-301
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## 0.38.0 - 2024-07-23
4+
5+
This release adds a new feature to the `Live` client for automatically reconnecting when an unexpected disconnection occurs.
6+
7+
#### Enhancements
8+
- Added `Reference` data client with `corporate_actions.get_range(...)` method
9+
- Added `ReconnectPolicy` enumeration
10+
- Added `reconnect_policy` parameter to the `Live` client to specify client reconnection behavior
11+
- Added `Live.add_reconnect_callback` method for specifying a callback to handle client reconnections
12+
- Added platform information to the user agent reported by the `Historical` and `Live` clients
13+
- Upgraded `databento-dbn` to 0.19.1
14+
- Added `BBOMsg`, `CBBOMsg`, and `StatusMsg` exports to the root `databento` package
15+
16+
#### Breaking changes
17+
- Calling `Live.stop` will now clear all user streams and callbacks
18+
- Renamed `Session` to `LiveSession` in the `databento.live.session` module
19+
320
## 0.37.0 - 2024-07-09
421

522
#### Enhancements

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The library is fully compatible with the latest distribution of Anaconda 3.8 and
3232
The minimum dependencies as found in the `pyproject.toml` are also listed below:
3333
- python = "^3.8"
3434
- aiohttp = "^3.8.3"
35-
- databento-dbn = "0.19.0"
35+
- databento-dbn = "0.19.1"
3636
- numpy= ">=1.23.5"
3737
- pandas = ">=1.5.3"
3838
- pip-system-certs = ">=4.0" (Windows only)

databento/__init__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import warnings
33

4+
from databento_dbn import BBOMsg
5+
from databento_dbn import CBBOMsg
46
from databento_dbn import Compression
57
from databento_dbn import Encoding
68
from databento_dbn import ErrorMsg
@@ -14,18 +16,21 @@
1416
from databento_dbn import Schema
1517
from databento_dbn import StatMsg
1618
from databento_dbn import StatType
19+
from databento_dbn import StatusMsg
1720
from databento_dbn import SType
1821
from databento_dbn import SymbolMappingMsg
1922
from databento_dbn import SystemMsg
2023
from databento_dbn import TradeMsg
2124

25+
from databento.common import API_VERSION
2226
from databento.common import bentologging
2327
from databento.common import symbology
2428
from databento.common.dbnstore import DBNStore
2529
from databento.common.enums import Delivery
2630
from databento.common.enums import FeedMode
2731
from databento.common.enums import HistoricalGateway
2832
from databento.common.enums import Packaging
33+
from databento.common.enums import ReconnectPolicy
2934
from databento.common.enums import RecordFlags
3035
from databento.common.enums import RollRule
3136
from databento.common.enums import SplitDuration
@@ -39,9 +44,9 @@
3944
from databento.common.publishers import Venue
4045
from databento.common.symbology import InstrumentMap
4146
from databento.common.types import DBNRecord
42-
from databento.historical.api import API_VERSION
4347
from databento.historical.client import Historical
4448
from databento.live.client import Live
49+
from databento.reference.client import Reference
4550
from databento.version import __version__ # noqa
4651

4752

@@ -69,26 +74,31 @@
6974
"HistoricalGateway",
7075
"InstrumentMap",
7176
"Live",
77+
"Reference",
7278
"Packaging",
79+
"ReconnectPolicy",
7380
"RollRule",
7481
"Schema",
7582
"SplitDuration",
83+
"StatType",
7684
"SType",
7785
"SymbologyResolution",
7886
# DBN Record Types
7987
"Metadata",
88+
"BBOMsg",
89+
"CBBOMsg",
90+
"ErrorMsg",
91+
"ImbalanceMsg",
92+
"InstrumentDefMsg",
8093
"MBOMsg",
8194
"MBP1Msg",
8295
"MBP10Msg",
83-
"TradeMsg",
8496
"OHLCVMsg",
8597
"StatMsg",
86-
"InstrumentDefMsg",
87-
"ImbalanceMsg",
88-
"ErrorMsg",
89-
"StatType",
90-
"SystemMsg",
98+
"StatusMsg",
9199
"SymbolMappingMsg",
100+
"SystemMsg",
101+
"TradeMsg",
92102
]
93103

94104
# Setup logging

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/enums.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,10 @@ class RecordFlags(StringyMixin, IntFlag): # type: ignore
220220
F_MBP = 16
221221
F_BAD_TS_RECV = 8
222222
F_MAYBE_BAD_BOOK = 4
223+
224+
225+
@unique
226+
@coercible
227+
class ReconnectPolicy(StringyMixin, str, Enum):
228+
NONE = "none"
229+
RECONNECT = "reconnect"

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)

databento/common/system.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import sys
1+
import platform
2+
import re
3+
from typing import Final
24

35
from databento.version import __version__
46

57

6-
PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}"
7-
USER_AGENT = f"Databento/{__version__} Python/{PYTHON_VERSION}"
8+
TOKEN_PATTERN: Final = re.compile(r"[^a-zA-Z0-9\.]")
9+
10+
PLATFORM_NAME: Final = TOKEN_PATTERN.sub("-", platform.system())
11+
PLATFORM_VERSION: Final = TOKEN_PATTERN.sub("-", platform.release())
12+
PYTHON_VERSION: Final = TOKEN_PATTERN.sub("-", platform.python_version())
13+
14+
USER_AGENT: Final = (
15+
f"Databento/{__version__} Python/{PYTHON_VERSION} {PLATFORM_NAME}/{PLATFORM_VERSION}"
16+
)

databento/common/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Union
77

88
import databento_dbn
9+
import pandas as pd
910

1011

1112
DBNRecord = Union[
@@ -31,6 +32,7 @@
3132

3233
RecordCallback = Callable[[DBNRecord], None]
3334
ExceptionCallback = Callable[[Exception], None]
35+
ReconnectCallback = Callable[[pd.Timestamp, pd.Timestamp], None]
3436

3537
_T = TypeVar("_T")
3638

0 commit comments

Comments
 (0)