Market Data

Schwab Market Data Prouction

Market Data Operations

The Schwab API provides extensive market data functionality, allowing you to retrieve real-time quotes, historical price data, options chains, market movers, and instrument details.


Method: quotes

Fetches real-time quotes for a list of ticker symbols.

Usage:

client.quotes(symbols=None, fields=None, indicative=False)

Parameters:

  • symbols (str | list[str], optional): A comma-separated string or list of ticker symbols (e.g., "AAPL,MSFT" or ["AAPL", "MSFT"]). Default is None.

  • fields (list, optional): A list of fields to include in the response (e.g., "quote", "fundamental"). Default is None, which fetches all available fields.

  • indicative (bool, optional): Whether to retrieve indicative quotes. Default is False.

Returns:

  • A request.Response object containing the quotes for the requested symbols.

Example:

response = client.quotes(symbols=["AAPL", "MSFT"], fields=["quote", "fundamental"])
print(response.json())

Method: quote

Fetches a real-time quote for a single ticker symbol.

Usage:

client.quote(symbol_id, fields=None)

Parameters:

  • symbol_id (str): The stock ticker symbol (e.g., "AAPL", "/ES", "USD/EUR").

  • fields (list, optional): A list of fields to include in the response (e.g., "quote", "fundamental"). Default is None, which fetches all available fields.

Returns:

  • A request.Response object containing the quote for the requested symbol.

Example:

response = client.quote(symbol_id="AAPL", fields=["quote"])
print(response.json())

Method: option_chains

Fetches the options chain for a specific ticker symbol, including both calls and puts for different expirations.

Usage:

client.option_chains(symbol, contractType=None, strikeCount=None, includeUnderlyingQuote=None, strategy=None, interval=None, strike=None, range=None, fromDate=None, toDate=None, volatility=None, underlyingPrice=None, interestRate=None, daysToExpiration=None, expMonth=None, optionType=None, entitlement=None)

Parameters:

  • symbol (str): The ticker symbol (e.g., "AAPL").

  • contractType (str, optional): The type of options contracts to retrieve ("CALL", "PUT", or "ALL"). Default is None.

  • strikeCount (int, optional): The number of strikes to retrieve. Default is None.

  • includeUnderlyingQuote (bool, optional): Whether to include the underlying stock's quote. Default is None.

  • strategy (str, optional): Option strategy to use (e.g., "SINGLE", "COVERED"). Default is None.

  • interval (str, optional): The strike price interval. Default is None.

  • strike (float, optional): The specific strike price. Default is None.

  • range (str, optional): Range filter for strike prices (e.g., "ITM", "OTM"). Default is None.

  • fromDate (str | datetime, optional): Start date for the option chain. Default is None.

  • toDate (str | datetime, optional): End date for the option chain. Default is None.

  • volatility (float, optional): Implied volatility for the options. Default is None.

  • underlyingPrice (float, optional): Underlying price for the options. Default is None.

  • interestRate (float, optional): Interest rate for the options. Default is None.

  • daysToExpiration (int, optional): Number of days to expiration for the options. Default is None.

  • expMonth (str, optional): Expiration month ("JAN", "FEB", etc.). Default is None.

  • optionType (str, optional): Option type ("CALL", "PUT"). Default is None.

  • entitlement (str, optional): Entitlement type ("PN", "NP", "PP"). Default is None.

Returns:

  • A request.Response object containing the options chain.

Example:

response = client.option_chains(symbol="AAPL", contractType="CALL", strikeCount=50)
print(response.json())

Method: option_expiration_chain

Fetches the expiration dates for options of a specific ticker symbol.

Usage:

client.option_expiration_chain(symbol)

Parameters:

  • symbol (str): The ticker symbol for which to retrieve the options expiration chain (e.g., "AAPL").

Returns:

  • A request.Response object containing the expiration chain for the symbol.

Example:

response = client.option_expiration_chain(symbol="AAPL")
print(response.json())

Method: price_history

Fetches the historical price data for a specific stock or symbol.

Usage:

client.price_history(symbol, periodType=None, period=None, frequencyType=None, frequency=None, startDate=None, endDate=None, needExtendedHoursData=None, needPreviousClose=None)

Parameters:

  • symbol (str): The stock ticker symbol (e.g., "AAPL").

  • periodType (str, optional): The type of period to retrieve (e.g., "day", "month", "year", "ytd"). Default is None.

  • period (int, optional): The length of the period (e.g., 5 days, 1 month). Default is None.

  • frequencyType (str, optional): The frequency of data points (e.g., "minute", "daily", "weekly"). Default is None.

  • frequency (int, optional): The number of minutes or days between each data point. Default is None.

  • startDate (str | datetime, optional): The start date for the price history. Default is None.

  • endDate (str | datetime, optional): The end date for the price history. Default is None.

  • needExtendedHoursData (bool, optional): Whether to include extended trading hours. Default is False.

  • needPreviousClose (bool, optional): Whether to include the previous closing price. Default is False.

Returns:

  • A request.Response object containing the price history data.

Example:

response = client.price_history(symbol="AAPL", periodType="day", period=30, frequencyType="minute", frequency=5)
print(response.json())

Method: movers

Fetches the top movers in a specific index, such as the Dow Jones or NASDAQ, with options to sort by various metrics.

Usage:

client.movers(symbol, sort=None, frequency=None)

Parameters:

  • symbol (str): The index symbol (e.g., "$DJI", "$COMPX", "$SPX").

  • sort (str, optional): Sorting criteria (e.g., "VOLUME", "TRADES", "PERCENT_CHANGE_UP", "PERCENT_CHANGE_DOWN"). Default is None.

  • frequency (int, optional): The frequency of updates (e.g., 1, 5, 10, 30, 60 minutes). Default is None.

Returns:

  • A request.Response object containing the top movers in the specified index.

Example:

response = client.movers(symbol="$DJI", sort="PERCENT_CHANGE_UP", frequency=5)
print(response.json())

Method: market_hours

Fetches the market hours for specific symbols and dates across different asset classes, such as equities, options, bonds, futures, and forex.

Usage:

client.market_hours(symbols, date=None)

Parameters:

  • symbols (list, optional): A list of market symbols (e.g., ["equity", "option", "bond", "future", "forex"]). Default is None.

  • date (str | datetime, optional): The date for which to retrieve market hours. Default is None.

Returns:

  • A request.Response object containing the market hours.

Example:

response = client.market_hours(symbols=["equity", "option"], date="2024-01-01")
print(response.json())

Method: instruments

Fetches instrument details for a list of symbols based on a projection type (e.g., symbol search or fundamental data).

Usage:

client.instruments(symbol, projection)

Parameters:

  • symbol (str): The stock ticker symbol (e.g., "AAPL").

  • projection (str): The projection type (e.g., "symbol-search", "fundamental").

Returns:

  • A request.Response object containing instrument details.

Example:

response = client.instruments(symbol="AAPL", projection="fundamental")
print(response.json())

Method: instrument_cusip

Fetches the details for an instrument based on its CUSIP (Committee on Uniform Securities Identification Procedures) ID.

Usage:

client.instrument_cusip(cusip_id)

Parameters:

  • cusip_id (str | int): The CUSIP ID of the instrument.

Returns:

  • A request.Response object containing the instrument details for the provided CUSIP ID.

Example:

response = client.instrument_cusip(cusip_id="037833100")
print(response.json())

Last updated