Streaming

Schwab Streaming Client

Schwab Streaming Overview

To access real-time data from Schwab, you can use the various level_one and book methods provided in the Schwab client. These methods allow you to:

  • Subscribe (SUBS) to real-time updates.

  • Unsubscribe (UNSUBS) from real-time updates.

  • Add (ADD) additional instruments to an existing stream.

  • View (VIEW) the current state of the stream.

Each streaming request requires the following:

  • Keys: Ticker symbols or specific keys for the instrument (e.g., "AAPL", "/ESF24").

  • Fields: The data points you wish to receive (e.g., price, volume).

  • Command: The action to perform (e.g., "SUBS" to subscribe, "UNSUBS" to unsubscribe).

Method: basic_request

All streaming requests are built upon the basic_request method, which sends the stream commands to Schwab’s servers.


Streaming Methods

Method: level_one_equities

Streams level one data (quotes and basic fields) for equities.

client.level_one_equities(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of ticker symbols (e.g., ["AMD", "INTC"]) or a single ticker symbol.

  • fields (list | str): A list of data fields you want to stream (e.g., ["0", "1", "2"]).

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD". (Add will append and SUBS will override)

Example:

client.level_one_equities(keys=["AAPL", "MSFT"], fields=["0", "1", "2"], command="SUBS")

Method: level_one_options

Streams level one data for options, including calls and puts.

client.level_one_options(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of option identifiers (e.g., ["GOOG 240809C00095000", "AAPL 240517P00190000"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.level_one_options(keys=["AAPL  240517P00190000"], fields=["0", "1", "2"], command="SUBS")

Method: level_one_futures

Streams level one data for futures contracts.

client.level_one_futures(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of futures contracts (e.g., ["/ESF24", "/GCG24"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.level_one_futures(keys=["/ESF24"], fields=["0", "1", "2"], command="SUBS")

Method: level_one_forex

Streams level one data for forex pairs.

client.level_one_forex(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of forex pairs (e.g., ["EUR/USD", "JPY/USD"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.level_one_forex(keys=["EUR/USD"], fields=["0", "1", "2"], command="SUBS")

Method: options_book

Streams real-time order book data for options.

client.options_book(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of options identifiers (e.g., ["AAPL 240517P00190000"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.options_book(keys=["GOOG  240809C00095000"], fields=["0", "1", "2"], command="SUBS")

Chart Data Streaming

Method: chart_equity

Streams real-time chart data for equities, such as tick-by-tick price movements and volume.

client.chart_equity(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of ticker symbols (e.g., ["AAPL", "MSFT"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.chart_equity(keys=["AAPL"], fields=["0", "1", "2"], command="SUBS")

Method: chart_futures

Streams real-time chart data for futures contracts.

client.chart_futures(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of futures contracts (e.g., ["/ESF24", "/GCG24"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.chart_futures(keys=["/ESF24"], fields=["0", "1", "2"], command="SUBS")

Screener Streaming

Method: screener_equity

Streams real-time equity screener data based on specified filters such as volume, trades, and percent change.

client.screener_equity(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of screener filters (e.g., ["$DJI_PERCENT_CHANGE_UP_60", "NASDAQ_VOLUME_30"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.screener_equity(keys=["$DJI_PERCENT_CHANGE_UP_60"], fields=["0", "1", "2"], command="SUBS")

Method: screener_options

Streams real-time options screener data based on specified filters such as volume and percent change.

client.screener_options(keys, fields, command="ADD")

Arguments:

  • keys (list | str): A list of screener filters (e.g., ["OPTION_PUT_PERCENT_CHANGE_UP_60"]).

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS", "ADD", "VIEW"). Default is "ADD".

Example:

client.screener_options(keys=["OPTION_PUT_PERCENT_CHANGE_UP_60"], fields=["0", "1", "2"], command="SUBS")

Account Activity Streaming

Method: account_activity

Streams real-time account activity, such as trades, orders, and balance updates.

client.account_activity(keys="Account Activity", fields="0,1,2,3", command="SUBS")

Arguments:

  • keys (list | str): A list of keys to track account activity (default is "Account Activity").

  • fields (list | str): A list of data fields to stream.

  • command (str): The action to perform (e.g., "SUBS", "UNSUBS"). Default is "SUBS".

Example:

client.account_activity(keys="Account Activity", fields="0,1,2,3", command="SUBS")

Streaming Command Explanation

  • SUBS: Subscribe to a stream for the provided keys and fields.

  • UNSUBS: Unsubscribe from the stream for the provided keys and fields.

  • ADD: Add new instruments or fields to an existing subscription.

  • VIEW: View the current stream for the provided keys and fields.

Last updated