Datasets

Polygon

Introduction

Instead of using the data from QuantConnect or your brokerage, you can use data from Polygon if you have an API key. To get an API key, see the API Keys page on the Polygon website

To view the implementation of the Polygon integration, see the Lean.DataSource.Polygon repository.

Supported Datasets

Our Polygon integration supports securities from the following asset classes:

Universe Selection

Universe Selection is available with the Polygon data provider if you download the data from the Dataset Market. The dataset listings show how to download the universe selection data with the CLI. For live trading, you'll need to periodically download the new data from QuantConnect Cloud, which you can automate with Python scripts. For example, the following tutorials explain how to download historical data and download daily updates:

Alternative Data

If you have licensed alternative data with QuantConnect, it works as expected with the Polygon data provider for research, backtesting, and live trading.

Download

To download Polygon data, open a terminal in your organization workspace and then run lean data download --data-provider-historical Polygon --data-type <data-type> --resolution <resolution> --security-type <security-type> --ticker <tickers> --start <YYYYMMDD> --end <YYYYMMDD> --polygon-api-key <apiKey>.

$ lean data download --data-provider-historical Polygon --data-type Trade --resolution Hour --security-type Equity --ticker SOFI,TSLA,NIO --start 20200101 --end 20240404 --polygon-api-key apiKey

If you provide your credentials, your Lean configuration file saves them.

Research

To access Polygon data from the local Research Environment, open a terminal in your organization workspace and then run lean research <projectName> --data-provider-historical Polygon --polygon-api-key <apiKey>.

$ lean research "My Project" --data-provider-historical Polygon --polygon-api-key apiKey

If you provide any of the preceding options, your Lean configuration file saves them so that you only need to run lean research <projectName> to open the Research Environment with the same options.

Backtesting

To run a local backtest with Polygon data, open a terminal in your organization workspace and then run lean backtest <projectName> --data-provider-historical Polygon --polygon-api-key <apiKey>.

$ lean backtest "My Project" --data-provider-historical Polygon --polygon-api-key apiKey

If you provide any of the preceding options, your Lean configuration file saves them so that you only need to run lean backtest <projectName> to run another backtest with the same options.

Optimization

Follow these steps to run a local optimization job with Polygon data:

  1. Add some parameters to your project.
  2. Open a terminal in your organization workspace.
  3. Run lean optimize <projectName> --data-provider-historical Polygon --polygon-api-key <apiKey>.
  4. $ lean optimize "My Project" --data-provider-historical Polygon --polygon-api-key apiKey
  5. Follow the steps in the interactive wizard to configure your optimization job settings.

The lean optimize command also accepts additional options so that you can select Polgyon and run the command in non-interactive mode. If you provide any of the preceding options, your Lean configuration file saves them so that you only need to run lean optimize <projectName> to run another optimization job with the same options.

Live Trading

To deploy a local live algorithm that uses Polygon as the data provider, open a terminal in your organization workspace and then run lean live deploy <projectName> --data-provider-live Polygon --polygon-api-key <apiKey> --brokerage <brokerageName> <requiredBrokerageOptions>.

$ lean live deploy "My Project" --data-provider-live Polygon --polygon-api-key apiKey --brokerage "Paper Trading"

Depending on the brokerage you select, you may need to provide some required brokerage options. To use a different provider for historical data, include the --data-provider-historical option. If you provide any of the preceding options, your Lean configuration file saves them so that you only need to run lean live deploy <projectName> --brokerage <brokerageName> to deploy another live algorithm with the same options.

To deploy the algorithm in QuantConnect Cloud while still using Polygon as the data provider, run lean cloud live deploy <projectName> --data-provider-live Polygon --polygon-api-key <apiKey> --brokerage <brokerageName> <requiredBrokerageOptions> --node <nodeName> --auto-restart <enableAutoRestarts> --notify-order-events <enableOrderEventNotifications> --notify-insights <enableInsightNotifications> <requiredNotificationOptions>.

$ lean cloud live deploy "My Project" --data-provider-live Polygon --polygon-api-key apiKey --brokerage "Paper Trading" --node "My Node" --auto-restart yes --notify-order-events no --notify-insights no

To deploy the live algorithm through the interactive mode of the CLI, see Polygon.

Pricing

To view the prices of the Polygon API packages, see the Simple Pricing page on the Polygon website.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: