Skip to content

Commit b44d2d3

Browse files
committed
DOC: Update intraday replay docs
1 parent f0c0143 commit b44d2d3

File tree

5 files changed

+74
-38
lines changed

5 files changed

+74
-38
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.63.1 - TBD
4+
5+
#### Bug fixes
6+
- Fixed type hint for `start` parameter in `Live.subscribe()`
7+
38
## 0.63.0 - 2025-09-02
49

510
#### Enhancements
@@ -18,7 +23,7 @@ This release delivers a number of breaking changes to the Python interface for D
1823
- Removed `hd` property from records in Python. Header fields are accessible
1924
directly from the record
2025
- Removed ability to directly instantiate most enums from an `int` in Python and coercion
21-
from `int` in `__eq__`. They can still be instantitated with the `from_int` class method.
26+
from `int` in `__eq__`. They can still be instantiated with the `from_int` class method.
2227
Write `Side.from_int(66)` instead of `Side(66)` and `Side.BID == Side.from_int(66)`
2328
instead of `Side.BID == 66`. Affected enums:
2429
- `Side`

databento/common/parsing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,14 @@ def optional_datetime_to_string(
344344

345345

346346
def datetime_to_unix_nanoseconds(
347-
value: pd.Timestamp | date | str | int,
347+
value: pd.Timestamp | datetime | date | str | int,
348348
) -> int:
349349
"""
350350
Return a valid UNIX nanosecond timestamp from the given value.
351351
352352
Parameters
353353
----------
354-
value : pd.Timestamp, date, str, or int
354+
value : pd.Timestamp, datetime, date, str, or int
355355
The value to parse.
356356
357357
Returns
@@ -378,15 +378,15 @@ def datetime_to_unix_nanoseconds(
378378

379379

380380
def optional_datetime_to_unix_nanoseconds(
381-
value: pd.Timestamp | date | str | int | None,
381+
value: pd.Timestamp | datetime | date | str | int | None,
382382
) -> int | None:
383383
"""
384384
Return a valid UNIX nanosecond timestamp from the given value (if not
385385
None).
386386
387387
Parameters
388388
----------
389-
value : pd.Timestamp, date, str, or int
389+
value : pd.Timestamp, datetime, date, str, or int
390390
The value to parse.
391391
392392
Returns

databento/live/client.py

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import threading
99
from collections.abc import Iterable
1010
from concurrent import futures
11+
from datetime import date
12+
from datetime import datetime
1113
from os import PathLike
1214
from typing import IO
1315

1416
import databento_dbn
17+
import pandas as pd
1518
from databento_dbn import Schema
1619
from databento_dbn import SType
1720

@@ -368,20 +371,22 @@ def start(
368371
self,
369372
) -> None:
370373
"""
371-
Start the live client session.
374+
Start the session.
372375
373-
It is not necessary to call `Live.start` before iterating a `Live` client and doing so will result in an error.
376+
It is not necessary to call this method before iterating a `Live` client and doing so
377+
will result in an error.
374378
375379
Raises
376380
------
377381
ValueError
378-
If `Live.start` is called before a subscription has been made.
379-
If `Live.start` is called after streaming has already started.
380-
If `Live.start` is called after the live session has closed.
382+
If called before a subscription has been made.
383+
If called after the session has already started.
384+
If called after the session has closed.
381385
382386
See Also
383387
--------
384388
Live.stop
389+
Live.terminate
385390
386391
"""
387392
logger.info("starting live client")
@@ -396,17 +401,25 @@ def start(
396401

397402
def stop(self) -> None:
398403
"""
399-
Stop the live client session as soon as possible. Once stopped, a
400-
client cannot be restarted.
404+
Stop the session and finish processing received records.
405+
406+
A client can only be stopped after a successful connection is made with `Live.start`.
407+
408+
This method does not block waiting for the connection to close.
409+
410+
The connection will eventually close after calling this method. Once the connection
411+
is closed, the client can be reused, but the session state is not preserved.
401412
402413
Raises
403414
------
404415
ValueError
405-
If `Live.stop` is called before a connection has been made.
416+
If called before a connection has started.
406417
407418
See Also
408419
--------
409-
Live.start
420+
Live.terminate
421+
Live.block_for_close
422+
Live.wait_for_close
410423
411424
"""
412425
logger.info("stopping live client")
@@ -424,17 +437,18 @@ def subscribe(
424437
schema: Schema | str,
425438
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
426439
stype_in: SType | str = SType.RAW_SYMBOL,
427-
start: str | int | None = None,
440+
start: pd.Timestamp | datetime | date | str | int | None = None,
428441
snapshot: bool = False,
429442
) -> None:
430443
"""
431-
Subscribe to a data stream. Multiple subscription requests can be made
432-
for a streaming session. Once one subscription has been made, future
433-
subscriptions must all belong to the same dataset.
444+
Add a new subscription to the session.
445+
446+
All subscriptions must be for the same `dataset`.
447+
448+
Multiple subscriptions for different schemas can be made.
434449
435-
When creating the first subscription this method will also create
436-
the TCP connection to the remote gateway. All subscriptions must
437-
have the same dataset.
450+
When creating the first subscription, this method will also create
451+
the TCP connection to the remote gateway.
438452
439453
Parameters
440454
----------
@@ -446,13 +460,14 @@ def subscribe(
446460
The symbols to subscribe to.
447461
stype_in : SType or str, default 'raw_symbol'
448462
The input symbology type to resolve from.
449-
start : str or int, optional
450-
UNIX nanosecond epoch timestamp to start streaming from (inclusive), based on `ts_event`. Must be within 24 hours except when requesting the mbo or definition schemas.
463+
start : pd.Timestamp, datetime, date, str or int, optional
464+
The inclusive start of subscription replay.
465+
Pass `0` to request all available data.
466+
Cannot be specified after the session is started.
467+
See `Intraday Replay` https://databento.com/docs/api-reference-live/basics/intraday-replay.
451468
snapshot: bool, default to 'False'
452469
Request subscription with snapshot. The `start` parameter must be `None`.
453470
454-
455-
456471
Raises
457472
------
458473
ValueError
@@ -497,17 +512,23 @@ def subscribe(
497512

498513
def terminate(self) -> None:
499514
"""
500-
Terminate the live client session and stop processing records as soon
501-
as possible.
515+
Terminate the session and stop processing records immediately.
516+
517+
A client can only be terminated after a connection is started with `Live.start`.
518+
519+
Once terminated, the client can be reused, but the session state
520+
is not preserved.
502521
503522
Raises
504523
------
505524
ValueError
506-
If the client is not connected.
525+
If called before a connection has started.
507526
508527
See Also
509528
--------
510529
Live.stop
530+
Live.block_for_close
531+
Live.wait_for_close
511532
512533
"""
513534
logger.info("terminating live client")
@@ -521,11 +542,14 @@ def block_for_close(
521542
) -> None:
522543
"""
523544
Block until the session closes or a timeout is reached. A session will
524-
close after `Live.stop` is called or the remote gateway disconnects.
545+
close after the remote gateway disconnects, or after `Live.stop` or
546+
`Live.terminate` are called.
525547
526-
If a `timeout` is specified, `Live.stop` will be called when the
548+
If a `timeout` is specified, `Live.terminate` will be called when the
527549
timeout is reached.
528550
551+
When this method unblocks, the session is guaranteed to be closed.
552+
529553
Parameters
530554
----------
531555
timeout : float, optional
@@ -541,7 +565,7 @@ def block_for_close(
541565
542566
See Also
543567
--------
544-
wait_for_close
568+
Live.wait_for_close
545569
546570
"""
547571
try:
@@ -565,12 +589,14 @@ async def wait_for_close(
565589
) -> None:
566590
"""
567591
Coroutine to wait until the session closes or a timeout is reached. A
568-
session will close after `Live.stop` is called or the remote gateway
569-
disconnects.
592+
session will close when the remote gateway disconnects, or after
593+
`Live.stop` or `Live.terminate` are called.
570594
571-
If a `timeout` is specified, `Live.stop` will be called when the
595+
If a `timeout` is specified, `Live.terminate` will be called when the
572596
timeout is reached.
573597
598+
When this method unblocks, the session is guaranteed to be closed.
599+
574600
Parameters
575601
----------
576602
timeout : float, optional
@@ -586,7 +612,7 @@ async def wait_for_close(
586612
587613
See Also
588614
--------
589-
block_for_close
615+
Live.block_for_close
590616
591617
"""
592618
waiter = asyncio.wrap_future(

examples/historical_timeseries_from_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
if __name__ == "__main__":
7-
ts_start = datetime.datetime.utcnow()
7+
ts_start = datetime.datetime.now(tz=datetime.timezone.utc)
88

99
# Can load from file path (if exists)
1010
data = DBNStore.from_file(path="my_data.dbn")
1111

1212
print(data.to_df())
13-
print(datetime.datetime.utcnow() - ts_start)
13+
print(datetime.datetime.now(tz=datetime.timezone.utc) - ts_start)

tests/test_common_parsing.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ def test_maybe_datetime_to_string_give_valid_values_returns_expected_results(
291291
pytest.param(1680736543000000000, 1680736543000000000, id="int"),
292292
pytest.param("1680736543000000000", 1680736543000000000, id="str-int"),
293293
pytest.param(dt.date(2023, 4, 5), 1680652800000000000, id="date"),
294+
pytest.param(
295+
dt.datetime(2023, 4, 5, 23, 15, 43, tzinfo=dt.timezone.utc),
296+
1680736543000000000,
297+
id="datetime",
298+
),
294299
pytest.param(
295300
pd.to_datetime("2023-04-05T00:00:00"),
296301
1680652800000000000,
@@ -304,7 +309,7 @@ def test_maybe_datetime_to_string_give_valid_values_returns_expected_results(
304309
],
305310
)
306311
def test_datetime_to_unix_nanoseconds(
307-
value: pd.Timestamp | str | int,
312+
value: pd.Timestamp | dt.datetime | dt.date | str | int,
308313
expected: int,
309314
) -> None:
310315
"""

0 commit comments

Comments
 (0)