Stocks
So you have completed the initial steps and are ready to dive deep into endpoints. Read this page to know everything you need to know about using the various Stocks HTTP endpoints.
See Async Support for REST endpoints for asynchronous use cases.
Docs below assume you have already read getting started page and know how to create the client. If you do not know how to create the client, first see General guide for clients and create client as below. As always you can have all 5 different clients together.
import polygon
stocks_client = polygon.StocksClient('KEY') # for usual sync client
async_stock_client = polygon.StocksClient('KEY', True) # for an async client
Get Trades
- StocksClient.get_trades(symbol: str, date, timestamp: Optional[int] = None, timestamp_limit: Optional[int] = None, reverse: bool = True, limit: int = 5000, raw_response: bool = False) Union[requests.models.Response, dict]
Get trades for a given ticker symbol on a specified date. The response from polygon seems to have a
map
attribute which gives a mapping of attribute names to readable values. Official Docs- Parameters
symbol – The ticker symbol we want trades for.
date – The date/day of the trades to retrieve. Could be
datetime
ordate
or stringYYYY-MM-DD
timestamp – The timestamp offset, used for pagination. Timestamp is the offset at which to start the results. Using the
timestamp
of the last result as the offset will give you the next page of results. Default: None. I’m trying to think of a good way to implement pagination support for this type of pagination.timestamp_limit – The maximum timestamp allowed in the results. Default: None
reverse – Reverse the order of the results. Default True: oldest first. Make it False for Newest first
limit – Limit the size of the response, max 50000 and default 5000.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Quotes
- StocksClient.get_quotes(symbol: str, date, timestamp: Optional[int] = None, timestamp_limit: Optional[int] = None, reverse: bool = True, limit: int = 5000, raw_response: bool = False) Union[requests.models.Response, dict]
Get Quotes for a given ticker symbol on a specified date. The response from polygon seems to have a
map
attribute which gives a mapping of attribute names to readable values. Official Docs- Parameters
symbol – The ticker symbol we want quotes for.
date – The date/day of the quotes to retrieve. Could be
datetime
ordate
or stringYYYY-MM-DD
timestamp – The timestamp offset, used for pagination. Timestamp is the offset at which to start the results. Using the
timestamp
of the last result as the offset will give you the next page of results. Default: None. Thinking of a good way to implement this pagination here.timestamp_limit – The maximum timestamp allowed in the results. Default: None
reverse – Reverse the order of the results. Default True: oldest first. Make it False for Newest first
limit – Limit the size of the response, max 50000 and default 5000.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Last Trade
- StocksClient.get_last_trade(symbol: str, raw_response: bool = False) Union[requests.models.Response, dict]
Get the most recent trade for a given stock. Official Docs
- Parameters
symbol – The ticker symbol of the stock/equity.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get last Quote
- StocksClient.get_last_quote(symbol: str, raw_response: bool = False) Union[requests.models.Response, dict]
Get the most recent NBBO (Quote) tick for a given stock. Official Docs
- Parameters
symbol – The ticker symbol of the stock/equity.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Daily Open Close
- StocksClient.get_daily_open_close(symbol: str, date, adjusted: bool = True, raw_response: bool = False) Union[requests.models.Response, dict]
Get the OCHLV and after-hours prices of a stock symbol on a certain date. Official Docs
- Parameters
symbol – The ticker symbol we want daily-OCHLV for.
date – The date/day of the daily-OCHLV to retrieve. Could be
datetime
ordate
or stringYYYY-MM-DD
adjusted – Whether or not the results are adjusted for splits. By default, results are adjusted. Set this to false to get results that are NOT adjusted for splits.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Aggregate Bars (Candles)
- StocksClient.get_aggregate_bars(symbol: str, from_date, to_date, adjusted: bool = True, sort='asc', limit: int = 5000, multiplier: int = 1, timespan='day', raw_response: bool = False) Union[requests.models.Response, dict]
Get aggregate bars for a stock over a given date range in custom time window sizes. For example, if
timespan = ‘minute’
andmultiplier = ‘5’
then 5-minute bars will be returned. Official Docs- Parameters
symbol – The ticker symbol of the stock/equity.
from_date – The start of the aggregate time window. Could be
datetime
ordate
or stringYYYY-MM-DD
to_date – The end of the aggregate time window. Could be
datetime
ordate
or stringYYYY-MM-DD
adjusted – Whether or not the results are adjusted for splits. By default, results are adjusted. Set this to false to get results that are NOT adjusted for splits.
sort – Sort the results by timestamp. See
polygon.enums.SortOrder
for choices.asc
default.limit – Limits the number of base aggregates queried to create the aggregate results. Max 50000 and Default 5000.
multiplier – The size of the timespan multiplier. Must be a positive whole number.
timespan – The size of the time window. See
polygon.enums.Timespan
for choices. defaults today
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Grouped daily Bars (Candles)
- StocksClient.get_grouped_daily_bars(date, adjusted: bool = True, raw_response: bool = False) Union[requests.models.Response, dict]
Get the daily OCHLV for the entire stocks/equities markets. Official docs
- Parameters
date – The date to get the data for. Could be
datetime
ordate
or stringYYYY-MM-DD
adjusted – Whether or not the results are adjusted for splits. By default, results are adjusted. Set this to false to get results that are NOT adjusted for splits.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Previous Close
- StocksClient.get_previous_close(symbol: str, adjusted: bool = True, raw_response: bool = False) Union[requests.models.Response, dict]
Get the previous day’s OCHLV for the specified stock ticker. Official Docs
- Parameters
symbol – The ticker symbol of the stock/equity.
adjusted – Whether or not the results are adjusted for splits. By default, results are adjusted. Set this to false to get results that are NOT adjusted for splits.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Snapshot
- StocksClient.get_snapshot(symbol: str, raw_response: bool = False) Union[requests.models.Response, dict]
Get the current minute, day, and previous day’s aggregate, as well as the last trade and quote for a single traded stock ticker. Official Docs
- Parameters
symbol – The ticker symbol of the stock/equity.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Snapshot (All)
- StocksClient.get_snapshot_all(symbols: list, raw_response: bool = False) Union[requests.models.Response, dict]
Get the current minute, day, and previous day’s aggregate, as well as the last trade and quote for all traded stock symbols. Official Docs
- Parameters
symbols – A comma separated list of tickers to get snapshots for.
raw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object
Get Current Price
- StocksClient.get_current_price(symbol: str) float
get current market price for the ticker symbol specified.
Uses
get_last_trade()
under the hood Official Docs- Parameters
symbol – The ticker symbol of the stock/equity.
- Returns
The current price. A
KeyError
indicates the request wasn’t successful.
Get Gainers & Losers
- StocksClient.get_gainers_and_losers(direction='gainers', raw_response: bool = False) Union[requests.models.Response, dict]
Get the current top 20 gainers or losers of the day in stocks/equities markets. Official Docs
- Parameters
direction – The direction of results. Defaults to gainers. See
polygon.enums.SnapshotDirection
for choicesraw_response – Whether or not to return the
Response
Object. Useful for when you need to say check the status code or inspect the headers. Defaults to False which returns the json decoded dictionary.
- Returns
A JSON decoded Dictionary by default. Make
raw_response=True
to get underlying response object