Skip to content

Commit

Permalink
MOD: Rename use_snapshot parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinicius Livramento committed May 22, 2024
1 parent a553324 commit d133ae5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.35.0 - TBD

#### Breaking changes
- Rename `use_snapshot` parameter in `Live.subscribe` function to `snapshot`

## 0.34.1 - 2024-05-21

#### Enhancements
Expand Down
14 changes: 7 additions & 7 deletions databento/live/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def subscribe(
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
stype_in: SType | str = SType.RAW_SYMBOL,
start: str | int | None = None,
use_snapshot: bool = False,
snapshot: bool = False,
) -> None:
"""
Subscribe to a data stream. Multiple subscription requests can be made
Expand All @@ -402,14 +402,14 @@ def subscribe(
The input symbology type to resolve from.
start : str or int, optional
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.
use_snapshot: bool, default to 'False'
snapshot: bool, default to 'False'
Reserved for future use.
Raises
------
ValueError
If a dataset is given that does not match the previous datasets.
If use_snapshot is True and start is not None.
If snapshot is True and start is not None.
BentoError
If creating the connection times out.
If creating the connection fails.
Expand All @@ -423,12 +423,12 @@ def subscribe(
"""
logger.info(
"subscribing to %s:%s %s start=%s use_snapshot=%s",
"subscribing to %s:%s %s start=%s snapshot=%s",
schema,
stype_in,
symbols,
start if start is not None else "now",
use_snapshot,
snapshot,
)
dataset = validate_semantic_string(dataset, "dataset")
schema = validate_enum(schema, Schema, "schema")
Expand All @@ -443,7 +443,7 @@ def subscribe(
f"because subscriptions to `{self.dataset}` have already been made.",
)

if use_snapshot and start is not None:
if snapshot and start is not None:
raise ValueError("Subscription with snapshot expects start=None")

self._session.subscribe(
Expand All @@ -452,7 +452,7 @@ def subscribe(
stype_in=stype_in,
symbols=symbols,
start=start,
use_snapshot=use_snapshot,
snapshot=snapshot,
)

def terminate(self) -> None:
Expand Down
10 changes: 5 additions & 5 deletions databento/live/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def subscribe(
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
stype_in: SType | str = SType.RAW_SYMBOL,
start: str | int | None = None,
use_snapshot: bool = False,
snapshot: bool = False,
) -> None:
"""
Send a SubscriptionRequest to the gateway.
Expand All @@ -272,17 +272,17 @@ def subscribe(
start : str or int, optional
UNIX nanosecond epoch timestamp to start streaming from. Must be
within 24 hours.
use_snapshot: bool, default to 'False'
snapshot: bool, default to 'False'
Reserved for future use.
"""
logger.info(
"sending subscription to %s:%s %s start=%s use_snapshot=%s",
"sending subscription to %s:%s %s start=%s snapshot=%s",
schema,
stype_in,
symbols,
start if start is not None else "now",
use_snapshot,
snapshot,
)

stype_in_valid = validate_enum(stype_in, SType, "stype_in")
Expand All @@ -296,7 +296,7 @@ def subscribe(
stype_in=stype_in_valid,
symbols=batch_str,
start=optional_datetime_to_unix_nanoseconds(start),
snapshot=int(use_snapshot),
snapshot=int(snapshot),
)
subscription_bytes.append(bytes(message))

Expand Down
6 changes: 3 additions & 3 deletions databento/live/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def subscribe(
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
stype_in: SType | str = SType.RAW_SYMBOL,
start: str | int | None = None,
use_snapshot: bool = False,
snapshot: bool = False,
) -> None:
"""
Send a subscription request on the current connection. This will create
Expand All @@ -427,7 +427,7 @@ def subscribe(
start : str or int, optional
UNIX nanosecond epoch timestamp to start streaming from. Must be
within 24 hours.
use_snapshot: bool, default to 'False'
snapshot: bool, default to 'False'
Reserved for future use.
"""
Expand All @@ -444,7 +444,7 @@ def subscribe(
symbols=symbols,
stype_in=stype_in,
start=start,
use_snapshot=use_snapshot,
snapshot=snapshot,
)

def resume_reading(self) -> None:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_live_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_live_subscription_with_snapshot_failed(
schema=Schema.MBO,
symbols=ALL_SYMBOLS,
start=start,
use_snapshot=True,
snapshot=True,
)

# Ensure this was an authentication error
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_live_subscribe(


@pytest.mark.parametrize(
"use_snapshot",
"snapshot",
[
False,
True,
Expand All @@ -496,10 +496,10 @@ def test_live_subscribe(
def test_live_subscribe_snapshot(
live_client: client.Live,
mock_live_server: MockLiveServer,
use_snapshot: bool,
snapshot: bool,
) -> None:
"""
Test that use_snapshot parameter is assigned correctly.
Test that snapshot parameter is assigned correctly.
"""
# Arrange

Expand All @@ -514,7 +514,7 @@ def test_live_subscribe_snapshot(
stype_in=stype_in,
symbols=symbols,
start=start,
use_snapshot=use_snapshot,
snapshot=snapshot,
)

# Act
Expand All @@ -528,7 +528,7 @@ def test_live_subscribe_snapshot(
assert message.stype_in == stype_in
assert message.symbols == symbols
assert message.start == start
assert message.snapshot == str(int(use_snapshot))
assert message.snapshot == str(int(snapshot))


@pytest.mark.usefixtures("mock_live_server")
Expand Down

0 comments on commit d133ae5

Please sign in to comment.