Crypto

Read this page to know everything you need to know about using the various Crypto 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

crypto_client = polygon.CryptoClient('KEY')  # for usual sync client
async_crypto_client = polygon.CryptoClient('KEY', True)  # for an async client

Note that most endpoints require you to specify the currency pairs as separate symbols (a from_symbol and a to_symbol).

however a few endpoints require you to supply them as one combined symbol. An example would be the get_aggregates_bars method. In those methods, the symbol is expected to have a prefix X: before the currency symbol names. but the library allows you to specify the symbol with or without the prefix. See the relevant method’s docs for more information on what the parameters expect.

Get Historic Trades

CryptoClient.get_historic_trades(from_symbol: str, to_symbol: str, date, offset: Optional[Union[str, int]] = None, limit: int = 500, raw_response: bool = False) Union[requests.models.Response, dict]

Get historic trade ticks for a cryptocurrency pair. Official Docs

Parameters
  • from_symbol – The “from” symbol of the crypto pair.

  • to_symbol – The “to” symbol of the crypto pair.

  • date – The date/day of the historic ticks to retrieve. Could be datetime, date or string YYYY-MM-DD

  • offset – The timestamp offset, used for pagination. This 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. I’m trying to think of a good way to implement pagination in the library for these endpoints which do not return a next_url attribute.

  • limit – Limit the size of the response, max 10000. Default 500

  • 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

CryptoClient.get_last_trade(from_symbol: str, to_symbol: str, raw_response: bool = False) Union[requests.models.Response, dict]

Get the last trade tick for a cryptocurrency pair. Official Docs

Parameters
  • from_symbol – The “from” symbol of the pair.

  • to_symbol – The “to” symbol of the pair.

  • 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

CryptoClient.get_daily_open_close(from_symbol: str, to_symbol: str, date, adjusted: bool = True, raw_response: bool = False) Union[requests.models.Response, dict]

Get the open, close prices of a cryptocurrency symbol on a certain day. Official Docs:

Parameters
  • from_symbol – The “from” symbol of the pair.

  • to_symbol – The “to” symbol of the pair.

  • date – The date of the requested open/close. Could be datetime, date or string YYYY-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)

CryptoClient.get_aggregate_bars(symbol: str, from_date, to_date, multiplier: int = 1, timespan='day', adjusted: bool = True, sort='asc', limit: int = 5000, raw_response: bool = False) Union[requests.models.Response, dict]

Get aggregate bars for a cryptocurrency pair over a given date range in custom time window sizes. For example, if timespan=‘minute’ and multiplier=‘5’ then 5-minute bars will be returned. Official Docs

Parameters
  • symbol – The ticker symbol of the currency pair. eg: X:BTCUSD. You can specify with or without prefix X:

  • from_date – The start of the aggregate time window. Could be datetime, date or string YYYY-MM-DD

  • to_date – The end of the aggregate time window. Could be datetime, date or string YYYY-MM-DD

  • multiplier – The size of the timespan multiplier

  • timespan – The size of the time window. Defaults to day candles. see polygon.enums.Timespan for choices

  • 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 – Order of sorting the results. See polygon.enums.SortOrder for available choices. Defaults to asc (oldest at the top)

  • limit – Limits the number of base aggregates queried to create the aggregate results. 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 Grouped Daily Bars (Candles)

CryptoClient.get_grouped_daily_bars(date, adjusted: bool = True, raw_response: bool = False) Union[requests.models.Response, dict]

Get the daily open, high, low, and close (OHLC) for the entire cryptocurrency market. Official Docs

Parameters
  • date – The date for the aggregate window. Could be datetime, date or string YYYY-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

CryptoClient.get_previous_close(symbol: str, adjusted: bool = True, raw_response: bool = False) Union[requests.models.Response, dict]

Get the previous day’s open, high, low, and close (OHLC) for the specified cryptocurrency pair. Official Docs

Parameters
  • symbol – The ticker symbol of the currency pair. eg: X:BTCUSD. You can specify with or without the prefix X:

  • 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 All

CryptoClient.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 cryptocurrency symbols Official Docs

Parameters
  • symbols – A 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 Snapshot

CryptoClient.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 cryptocurrency symbol. Official Docs

Parameters
  • symbol – Symbol of the currency pair. eg: X:BTCUSD. you can specify with or without prefix X:

  • 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 Level 2 Book

CryptoClient.get_level2_book(symbol: str, raw_response: bool = False) Union[requests.models.Response, dict]

Get the current level 2 book of a single ticker. This is the combined book from all of the exchanges. Official Docs

Parameters
  • symbol – The cryptocurrency ticker. eg: X:BTCUSD. You can specify with or without the prefix `X:

  • 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