Skip to content

polygon module

Module with PolygonData.


PolygonData class

PolygonData(
    wrapper,
    data,
    single_key=True,
    classes=None,
    level_name=None,
    fetch_kwargs=None,
    returned_kwargs=None,
    last_index=None,
    delisted=None,
    tz_localize=None,
    tz_convert=None,
    missing_index=None,
    missing_columns=None,
    **kwargs
)

Data class for fetching from Polygon.

See https://github.com/polygon-io/client-python for API.

See PolygonData.fetch_symbol() for arguments.

Usage

  • Set up the API key globally:
>>> from vectorbtpro import *

>>> vbt.PolygonData.set_custom_settings(
...     client_config=dict(
...         api_key="YOUR_KEY"
...     )
... )
  • Pull stock data:
>>> data = vbt.PolygonData.pull(
...     "AAPL",
...     start="2021-01-01",
...     end="2022-01-01",
...     timeframe="1 day"
... )
  • Pull crypto data:
>>> data = vbt.PolygonData.pull(
...     "X:BTCUSD",
...     start="2021-01-01",
...     end="2022-01-01",
...     timeframe="1 day"
... )

Superclasses

Inherited members


fetch_symbol class method

PolygonData.fetch_symbol(
    symbol,
    client=None,
    client_config=None,
    start=None,
    end=None,
    timeframe=None,
    tz=None,
    adjusted=None,
    limit=None,
    params=None,
    delay=None,
    retries=None,
    show_progress=None,
    pbar_kwargs=None,
    silence_warnings=None
)

Override Data.fetch_symbol() to fetch a symbol from Polygon.

Args

symbol : str

Symbol.

Supports the following APIs:

  • Stocks and equities
  • Currencies - symbol must have the prefix C:
  • Crypto - symbol must have the prefix X:
client : polygon.rest.RESTClient

Client.

See PolygonData.resolve_client().

client_config : dict

Client config.

See PolygonData.resolve_client().

start : any

The start of the aggregate time window.

See to_tzaware_datetime().

end : any

The end of the aggregate time window.

See to_tzaware_datetime().

timeframe : str

Timeframe.

Allows human-readable strings such as "15 minutes".

tz : any

Timezone.

See to_timezone().

adjusted : str

Whether the results are adjusted for splits.

By default, results are adjusted. Set this to False to get results that are NOT adjusted for splits.

limit : int

Limits the number of base aggregates queried to create the aggregate results.

Max 50000 and Default 5000.

params : dict
Any additional query params.
delay : float
Time to sleep after each request (in seconds).
retries : int
The number of retries on failure to fetch data.
show_progress : bool
Whether to show the progress bar.
pbar_kwargs : dict
Keyword arguments passed to ProgressBar.
silence_warnings : bool
Whether to silence all warnings.

For defaults, see custom.polygon in data.

Note

If you're using a free plan that has an API rate limit of several requests per minute, make sure to set delay to a higher number, such as 12 (which makes 5 requests per minute).


list_symbols class method

PolygonData.list_symbols(
    pattern=None,
    use_regex=False,
    sort=True,
    client=None,
    client_config=None,
    **list_tickers_kwargs
)

List all symbols.

Uses CustomData.key_match() to check each symbol against pattern.

For supported keyword arguments, see polygon.RESTClient.list_tickers.


resolve_client class method

PolygonData.resolve_client(
    client=None,
    **client_config
)

Resolve the client.

If provided, must be of the type polygon.rest.RESTClient. Otherwise, will be created using client_config.