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
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 isNone
.fields (
list
, optional): A list of fields to include in the response (e.g.,"quote"
,"fundamental"
). Default isNone
, which fetches all available fields.indicative (
bool
, optional): Whether to retrieve indicative quotes. Default isFalse
.
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
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 isNone
, 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
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 isNone
.strikeCount (
int
, optional): The number of strikes to retrieve. Default isNone
.includeUnderlyingQuote (
bool
, optional): Whether to include the underlying stock's quote. Default isNone
.strategy (
str
, optional): Option strategy to use (e.g.,"SINGLE"
,"COVERED"
). Default isNone
.interval (
str
, optional): The strike price interval. Default isNone
.strike (
float
, optional): The specific strike price. Default isNone
.range (
str
, optional): Range filter for strike prices (e.g.,"ITM"
,"OTM"
). Default isNone
.fromDate (
str | datetime
, optional): Start date for the option chain. Default isNone
.toDate (
str | datetime
, optional): End date for the option chain. Default isNone
.volatility (
float
, optional): Implied volatility for the options. Default isNone
.underlyingPrice (
float
, optional): Underlying price for the options. Default isNone
.interestRate (
float
, optional): Interest rate for the options. Default isNone
.daysToExpiration (
int
, optional): Number of days to expiration for the options. Default isNone
.expMonth (
str
, optional): Expiration month ("JAN"
,"FEB"
, etc.). Default isNone
.optionType (
str
, optional): Option type ("CALL"
,"PUT"
). Default isNone
.entitlement (
str
, optional): Entitlement type ("PN"
,"NP"
,"PP"
). Default isNone
.
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
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
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 isNone
.period (
int
, optional): The length of the period (e.g.,5
days,1
month). Default isNone
.frequencyType (
str
, optional): The frequency of data points (e.g.,"minute"
,"daily"
,"weekly"
). Default isNone
.frequency (
int
, optional): The number of minutes or days between each data point. Default isNone
.startDate (
str | datetime
, optional): The start date for the price history. Default isNone
.endDate (
str | datetime
, optional): The end date for the price history. Default isNone
.needExtendedHoursData (
bool
, optional): Whether to include extended trading hours. Default isFalse
.needPreviousClose (
bool
, optional): Whether to include the previous closing price. Default isFalse
.
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
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 isNone
.frequency (
int
, optional): The frequency of updates (e.g.,1
,5
,10
,30
,60
minutes). Default isNone
.
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
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 isNone
.date (
str | datetime
, optional): The date for which to retrieve market hours. Default isNone
.
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
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
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