Skip to content

LiveMarketFeed


class backtide.live.LiveMarketFeed(provider, symbols, interval="1m", include_partial=True, reconnect_attempts=5, backoff_seconds=0.25)

Reusable, cancellable exchange market-data collector.

The feed retains a healthy WebSocket across bounded collect calls and retries disconnects with exponential backoff. Call cancel safely from another Python thread; cancellation latency is at most 250 ms and closes the retained socket. A later call requires reset.

Parameters

provider : str | Provider

Exchange WebSocket provider.

symbols : list[str]
Provider symbols to subscribe to.

interval : str | Interval, default="1m"
Candle interval. Coinbase supports "5m" only.

include_partial : bool, default=True
Include updates for candles that have not closed yet.

reconnect_attempts : int, default=5
Maximum connection attempts for a collection batch.

backoff_seconds : float, default=0.25
Initial reconnect delay in seconds.


See Also

collect_market_updates

Collect a finite batch from an exchange WebSocket.

Session

A stateful simulated account with optional strategy evaluation.


Example

>>> from backtide.live import LiveMarketFeed

>>> feed = LiveMarketFeed("kraken", ["BTC-USD"], interval="1m")
>>> feed.cancel()
>>> print(feed.is_cancelled())

True


Methods

collect Collect up to `max_events`, retrying transient disconnects.
cancel Request cancellation of an in-progress `collect` call.
reset Clear cancellation before intentionally reusing this feed.
is_cancelled Whether cancellation has been requested.


method collect(max_events=1, timeout_seconds=30.0)

Collect up to max_events, retrying transient disconnects.

Example

>>> from backtide.live import LiveMarketFeed

>>> feed = LiveMarketFeed("binance", ["BTC-USDT"])
>>> updates = feed.collect(max_events=10, timeout_seconds=5)  
Parameters

max_events : int, default=1

Maximum number of updates to return.

timeout_seconds : float, default=30
Maximum collection time in seconds.

Returns

list[MarketUpdate]

Updates received before the event limit or timeout.



method cancel()

Request cancellation of an in-progress collect call.

Example

>>> from backtide.live import LiveMarketFeed

>>> feed = LiveMarketFeed("kraken", ["BTC-USD"])
>>> feed.cancel()
>>> print(feed.is_cancelled())

True


method reset()

Clear cancellation before intentionally reusing this feed.

Example

>>> from backtide.live import LiveMarketFeed

>>> feed = LiveMarketFeed("kraken", ["BTC-USD"])
>>> feed.cancel()
>>> feed.reset()
>>> print(feed.is_cancelled())

False


method is_cancelled()

Whether cancellation has been requested.

Example

>>> from backtide.live import LiveMarketFeed

>>> feed = LiveMarketFeed("kraken", ["BTC-USD"])
>>> print(feed.is_cancelled())

False
Returns

bool

True after cancel and False after construction or reset.