Real-Time Data#

CryptoDataStream#

class alpaca.data.live.crypto.CryptoDataStream(api_key: str, secret_key: str, raw_data: bool = False, feed: CryptoFeed = CryptoFeed.US, url_override: Optional[str] = None, websocket_params: Optional[Dict] = None)#

A WebSocket client for streaming live crypto data.

async close() None#

Closes the websocket connection.

run() None#

Starts up the websocket connection’s event loop

stop() None#

Stops the websocket connection.

async stop_ws() None#

Signals websocket connection should close by adding a closing message to the stop_stream_queue

subscribe_bars(handler: Callable[[Union[Quote, Dict]], Awaitable[None]], *symbols: str) None#

Subscribe to minute bars

Parameters:
  • handler (Callable[[Union[Quote, Dict]], Awaitable[None]]) – The coroutine callback function to handle the incoming data.

  • *symbols – List of ticker symbols to subscribe to. “*” for everything.

subscribe_daily_bars(handler: Callable[[Union[Bar, Dict]], Awaitable[None]], *symbols: str) None#

Subscribe to daily bars

Parameters:
  • handler (Callable[[Union[Bar, Dict]], Awaitable[None]]) – The coroutine callback function to handle the incoming data.

  • *symbols – List of ticker symbols to subscribe to. “*” for everything.

subscribe_orderbooks(handler: Callable[[Union[Orderbook, Dict]], Awaitable[None]], *symbols) None#

Subscribe to orderbooks

Parameters:
  • handler (Callable[[Union[Bar, Dict]], Awaitable[None]]) – The coroutine callback function to handle the incoming data.

  • *symbols – List of ticker symbols to subscribe to. “*” for everything.

subscribe_quotes(handler: Callable[[Union[Quote, Dict]], Awaitable[None]], *symbols: str) None#

Subscribe to quotes

Parameters:
  • handler (Callable[[Union[Quote, Dict]], Awaitable[None]]) – The coroutine callback function to handle the incoming data.

  • *symbols – List of ticker symbols to subscribe to. “*” for everything.

subscribe_trades(handler: Callable[[Union[Trade, Dict]], Awaitable[None]], *symbols: str) None#

Subscribe to trades.

Parameters:
  • handler (Callable[[Union[Trade, Dict]], Awaitable[None]) – The coroutine callback function to handle the incoming data.

  • *symbols – List of ticker symbols to subscribe to. “*” for everything.

subscribe_updated_bars(handler: Callable[[Union[Bar, Dict]], Awaitable[None]], *symbols: str) None#

Subscribe to updated minute bars

Parameters:
  • handler (Callable[[Union[Bar, Dict]], Awaitable[None]]) – The coroutine callback function to handle the incoming data.

  • *symbols – List of ticker symbols to subscribe to. “*” for everything.

unsubscribe_bars(*symbols: str) None#

Unsubscribe from minute bars

Parameters:

*symbols (str) – List of ticker symbols to unsubscribe from. “*” for everything.

unsubscribe_daily_bars(*symbols: str) None#

Unsubscribe from daily bars

Parameters:

*symbols (str) – List of ticker symbols to unsubscribe from. “*” for everything.

unsubscribe_orderbooks(*symbols: str) None#

Unsubscribe from orderbooks

Parameters:

*symbols (str) – List of ticker symbols to unsubscribe from. “*” for everything.

unsubscribe_quotes(*symbols: str) None#

Unsubscribe from quotes

Parameters:

*symbols (str) – List of ticker symbols to unsubscribe from. “*” for everything.

unsubscribe_trades(*symbols: str) None#

Unsubscribe from trades

Parameters:

*symbols (str) – List of ticker symbols to unsubscribe from. “*” for everything.

unsubscribe_updated_bars(*symbols: str) None#

Unsubscribe from updated bars

Parameters:

*symbols (str) – List of ticker symbols to unsubscribe from. “*” for everything.