Export price data (CLI)

A simple common case need is to export some price data to a CSV file or similar for offline analysis. In this tutorial we will use the command line to find an instrument and export candle data to a CSV file.

This example uses QQQ and the Polygon.io data module, but the process is the same for any broker/vendor and any instrument.

Preparation

This exercise requires only a Market data service to be running. Use the Configurator if you don't have an environment set up already.

If you haven't already, install the CLI tool

Method

Find the instrument

Use the data command and search subcommand to search for the full symbol for the instrument:

❯ awts data search QQQ
+--------------+------------------------------+
| SYMBOL       | NAME                         |
+--------------+------------------------------+
| POLYGON:PSQ  | ProShares Short QQQ          |
| POLYGON:QID  | ProShares UltraShort QQQ     |
| POLYGON:QLD  | ProShares Ultra QQQ          |
| POLYGON:QQQ  | Invesco QQQ Trust, Series 1  |
| POLYGON:SQQQ | ProShares UltraPro Short QQQ |
| POLYGON:TQQQ | ProShares  UltraPro QQQ      |
+--------------+------------------------------+

Pull candles

Then use the candles command to pull the candles. the --resolution, --from and --to arguments can be used to specify the output you want. See the CLI tool documentation for more information.

> awts candles POLYGON:QQQ --resolution=H --from=2023-10-20
                Timestamp         Vol         O         H         L         C      Vwap    Spread
      2023-10-19T00:00:00    71642938    364.81    366.02    359.16    359.97    362.68      0.00
      2023-10-20T00:00:00    72449723    359.46    360.04    354.37    354.60    356.86      0.00
      2023-10-23T00:00:00    59900585    353.26    359.26    351.12    355.67    355.78      0.00
      2023-10-24T00:00:00    46972078    357.51    359.91    355.79    359.13    358.23      0.00
      2023-10-25T00:00:00    71171536    356.70    356.88    349.75    350.34    352.74      0.00

You'll see the output displayed formatted in the terminal. Great, but lets put it into a file for easier processing...

Save as a CSV file

If you run the same command with --format=csv the tool will produce CSV-formatted data instead:

awts candles POLYGON:QQQ --resolution=H --from=2023-10-20 --format=csv

And this can be piped into a file:

awts candles POLYGON:QQQ --resolution=H --from=2023-10-20 --format=csv > candles.csv