Skip to content

Commit 8b9ac5a

Browse files
authored
VER: Relese 0.34.1
See release notes.
2 parents 7237474 + 5ceec80 commit 8b9ac5a

File tree

9 files changed

+130
-6
lines changed

9 files changed

+130
-6
lines changed

CHANGELOG.md

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

3+
## 0.34.1 - 2024-05-21
4+
5+
#### Enhancements
6+
- Added `use_snapshot` parameter to `Live.subscribe`, defaults to `False`
7+
38
## 0.34.0 - 2024-05-14
49

510
#### Enhancements
@@ -11,6 +16,9 @@
1116
- Fixed an issue where `batch.download`, `batch.download_async`, and `timeseries.get_range` could use a lot of memory while streaming data
1217
- Fixed an issue where reusing a `Live` client with an open output stream would drop DBN records when received at the same time as the `Metadata` header
1318

19+
##### Deprecations
20+
- The `start_date` and `end_date` keys in the response from `Historical.metadata.get_dataset_range` will be removed in a future release. Use the new `start` and `end` keys instead, which include time resolution
21+
1422
## 0.33.0 - 2024-04-16
1523

1624
#### Enhancements

databento/live/client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def subscribe(
379379
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
380380
stype_in: SType | str = SType.RAW_SYMBOL,
381381
start: str | int | None = None,
382+
use_snapshot: bool = False,
382383
) -> None:
383384
"""
384385
Subscribe to a data stream. Multiple subscription requests can be made
@@ -401,11 +402,14 @@ def subscribe(
401402
The input symbology type to resolve from.
402403
start : str or int, optional
403404
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.
405+
use_snapshot: bool, default to 'False'
406+
Reserved for future use.
404407
405408
Raises
406409
------
407410
ValueError
408411
If a dataset is given that does not match the previous datasets.
412+
If use_snapshot is True and start is not None.
409413
BentoError
410414
If creating the connection times out.
411415
If creating the connection fails.
@@ -419,11 +423,12 @@ def subscribe(
419423
420424
"""
421425
logger.info(
422-
"subscribing to %s:%s %s start=%s",
426+
"subscribing to %s:%s %s start=%s use_snapshot=%s",
423427
schema,
424428
stype_in,
425429
symbols,
426430
start if start is not None else "now",
431+
use_snapshot,
427432
)
428433
dataset = validate_semantic_string(dataset, "dataset")
429434
schema = validate_enum(schema, Schema, "schema")
@@ -437,12 +442,17 @@ def subscribe(
437442
f"Cannot subscribe to dataset `{dataset}` "
438443
f"because subscriptions to `{self.dataset}` have already been made.",
439444
)
445+
446+
if use_snapshot and start is not None:
447+
raise ValueError("Subscription with snapshot expects start=None")
448+
440449
self._session.subscribe(
441450
dataset=dataset,
442451
schema=schema,
443452
stype_in=stype_in,
444453
symbols=symbols,
445454
start=start,
455+
use_snapshot=use_snapshot,
446456
)
447457

448458
def terminate(self) -> None:

databento/live/gateway.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class SubscriptionRequest(GatewayControl):
121121
stype_in: SType
122122
symbols: str
123123
start: int | None = None
124+
snapshot: int = 0
124125

125126

126127
@dataclasses.dataclass

databento/live/protocol.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def subscribe(
256256
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
257257
stype_in: SType | str = SType.RAW_SYMBOL,
258258
start: str | int | None = None,
259+
use_snapshot: bool = False,
259260
) -> None:
260261
"""
261262
Send a SubscriptionRequest to the gateway.
@@ -271,15 +272,19 @@ def subscribe(
271272
start : str or int, optional
272273
UNIX nanosecond epoch timestamp to start streaming from. Must be
273274
within 24 hours.
275+
use_snapshot: bool, default to 'False'
276+
Reserved for future use.
274277
275278
"""
276279
logger.info(
277-
"sending subscription to %s:%s %s start=%s",
280+
"sending subscription to %s:%s %s start=%s use_snapshot=%s",
278281
schema,
279282
stype_in,
280283
symbols,
281284
start if start is not None else "now",
285+
use_snapshot,
282286
)
287+
283288
stype_in_valid = validate_enum(stype_in, SType, "stype_in")
284289
symbols_list = optional_symbols_list_to_list(symbols, stype_in_valid)
285290

@@ -291,6 +296,7 @@ def subscribe(
291296
stype_in=stype_in_valid,
292297
symbols=batch_str,
293298
start=optional_datetime_to_unix_nanoseconds(start),
299+
snapshot=int(use_snapshot),
294300
)
295301
subscription_bytes.append(bytes(message))
296302

databento/live/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def subscribe(
408408
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
409409
stype_in: SType | str = SType.RAW_SYMBOL,
410410
start: str | int | None = None,
411+
use_snapshot: bool = False,
411412
) -> None:
412413
"""
413414
Send a subscription request on the current connection. This will create
@@ -426,6 +427,8 @@ def subscribe(
426427
start : str or int, optional
427428
UNIX nanosecond epoch timestamp to start streaming from. Must be
428429
within 24 hours.
430+
use_snapshot: bool, default to 'False'
431+
Reserved for future use.
429432
430433
"""
431434
with self._lock:
@@ -441,6 +444,7 @@ def subscribe(
441444
symbols=symbols,
442445
stype_in=stype_in,
443446
start=start,
447+
use_snapshot=use_snapshot,
444448
)
445449

446450
def resume_reading(self) -> None:

databento/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.34.0"
1+
__version__ = "0.34.1"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "databento"
3-
version = "0.34.0"
3+
version = "0.34.1"
44
description = "Official Python client library for Databento"
55
authors = [
66
"Databento <[email protected]>",

tests/test_live_client.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,43 @@ def test_live_connection_cram_failure(
173173
exc.match(r"User authentication failed:")
174174

175175

176+
@pytest.mark.parametrize(
177+
"start",
178+
[
179+
"now",
180+
"2022-06-10T12:00",
181+
1671717080706865759,
182+
],
183+
)
184+
def test_live_subscription_with_snapshot_failed(
185+
mock_live_server: MockLiveServer,
186+
test_api_key: str,
187+
start: str | int,
188+
) -> None:
189+
"""
190+
Test that an invalid snapshot subscription raises a ValueError.
191+
"""
192+
# Arrange
193+
live_client = client.Live(
194+
key=test_api_key,
195+
gateway=mock_live_server.host,
196+
port=mock_live_server.port,
197+
)
198+
199+
# Act, Assert
200+
with pytest.raises(ValueError) as exc:
201+
live_client.subscribe(
202+
dataset=Dataset.GLBX_MDP3,
203+
schema=Schema.MBO,
204+
symbols=ALL_SYMBOLS,
205+
start=start,
206+
use_snapshot=True,
207+
)
208+
209+
# Ensure this was an authentication error
210+
exc.match(r"Subscription with snapshot expects start=None")
211+
212+
176213
@pytest.mark.parametrize(
177214
"dataset",
178215
[pytest.param(dataset, id=str(dataset)) for dataset in Dataset],
@@ -446,6 +483,52 @@ def test_live_subscribe(
446483
assert message.stype_in == stype_in
447484
assert message.symbols == symbols
448485
assert message.start == start
486+
assert message.snapshot == "0"
487+
488+
489+
@pytest.mark.parametrize(
490+
"use_snapshot",
491+
[
492+
False,
493+
True,
494+
],
495+
)
496+
def test_live_subscribe_snapshot(
497+
live_client: client.Live,
498+
mock_live_server: MockLiveServer,
499+
use_snapshot: bool,
500+
) -> None:
501+
"""
502+
Test that use_snapshot parameter is assigned correctly.
503+
"""
504+
# Arrange
505+
506+
schema = Schema.MBO
507+
stype_in = SType.RAW_SYMBOL
508+
symbols = ALL_SYMBOLS
509+
start = None
510+
511+
live_client.subscribe(
512+
dataset=Dataset.GLBX_MDP3,
513+
schema=schema,
514+
stype_in=stype_in,
515+
symbols=symbols,
516+
start=start,
517+
use_snapshot=use_snapshot,
518+
)
519+
520+
# Act
521+
message = mock_live_server.get_message_of_type(
522+
gateway.SubscriptionRequest,
523+
timeout=1,
524+
)
525+
526+
# Assert
527+
assert message.schema == schema
528+
assert message.stype_in == stype_in
529+
assert message.symbols == symbols
530+
assert message.start == start
531+
assert message.snapshot == str(int(use_snapshot))
449532

450533

451534
@pytest.mark.usefixtures("mock_live_server")

tests/test_live_gateway_messages.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,31 @@ def test_parse_subscription_request(
347347
stype_in=SType.INSTRUMENT_ID,
348348
symbols="1234,5678,90",
349349
),
350-
b"schema=mbo|" b"stype_in=instrument_id|" b"symbols=1234,5678,90\n",
350+
b"schema=mbo|" b"stype_in=instrument_id|" b"symbols=1234,5678,90|" b"snapshot=0\n",
351351
),
352352
pytest.param(
353353
SubscriptionRequest(
354354
schema=Schema.MBO,
355355
stype_in=SType.RAW_SYMBOL,
356356
symbols="UNI,TTE,ST",
357357
start=1671717080706865759,
358+
snapshot=0,
358359
),
359360
b"schema=mbo|"
360361
b"stype_in=raw_symbol|"
361362
b"symbols=UNI,TTE,ST|"
362-
b"start=1671717080706865759\n",
363+
b"start=1671717080706865759|"
364+
b"snapshot=0\n",
365+
),
366+
pytest.param(
367+
SubscriptionRequest(
368+
schema=Schema.MBO,
369+
stype_in=SType.INSTRUMENT_ID,
370+
symbols="1234,5678,90",
371+
start=None,
372+
snapshot=1,
373+
),
374+
b"schema=mbo|" b"stype_in=instrument_id|" b"symbols=1234,5678,90|" b"snapshot=1\n",
363375
),
364376
],
365377
)

0 commit comments

Comments
 (0)