Real-Time Data#

StockDataStream#

class alpaca.data.live.stock.StockDataStream(api_key: str, secret_key: str, raw_data: bool = False, feed: DataFeed = DataFeed.IEX, websocket_params: Optional[Dict] = None, url_override: Optional[str] = None)#

A WebSocket client for streaming live stock data via IEX or SIP depending on your market data subscription.

See BaseStream for more information on implementation and the methods available.

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, *symbols) None#

Subscribe to minute bar data for symbol inputs

Parameters:
  • handler (Callable) – The coroutine callback function to handle live minute bar data

  • *symbols – Variable string arguments for ticker identifiers to be subscribed to.

subscribe_daily_bars(handler: Callable, *symbols) None#

Subscribe to daily bar data for symbol inputs

Parameters:
  • handler (Callable) – The coroutine callback function to handle live daily bar data

  • *symbols – Variable string arguments for ticker identifiers to be subscribed to.

subscribe_quotes(handler: Callable, *symbols) None#

Subscribe to quote data for symbol inputs

Parameters:
  • handler (Callable) – The coroutine callback function to handle live quote data

  • *symbols – Variable string arguments for ticker identifiers to be subscribed to.

subscribe_trades(handler: Callable, *symbols) None#

Subscribe to trade data for symbol inputs

Parameters:
  • handler (Callable) – The coroutine callback function to handle live trade data

  • *symbols – Variable string arguments for ticker identifiers to be subscribed to.

subscribe_updated_bars(handler: Callable, *symbols) None#

Subscribe to updated bar data for symbol inputs

Parameters:
  • handler (Callable) – The coroutine callback function to handle live updated bar data

  • *symbols – Variable string arguments for ticker identifiers to be subscribed to.

unsubscribe_bars(*symbols) None#

Unsubscribe from minute bar data for symbol inputs

Parameters:

*symbols – Variable string arguments for ticker identifiers to be unsubscribed from.

unsubscribe_daily_bars(*symbols) None#

Unsubscribe from daily bar data for symbol inputs

Parameters:

*symbols – Variable string arguments for ticker identifiers to be unsubscribed from.

unsubscribe_quotes(*symbols) None#

Unsubscribe from quote data for symbol inputs

Parameters:

*symbols – Variable string arguments for ticker identifiers to be unsubscribed from.

unsubscribe_trades(*symbols) None#

Unsubscribe from trade data for symbol inputs

Parameters:

*symbols – Variable string arguments for ticker identifiers to be unsubscribed from.

unsubscribe_updated_bars(*symbols) None#

Unsubscribe from updated bar data for symbol inputs

Parameters:

*symbols – Variable string arguments for ticker identifiers to be unsubscribed from.