QuantRocket logo

Alpaca/Polygon.io Steps

To prepare for live trading with Alpaca, the following steps are required:

  • Collect listings from Alpaca
  • Create realtime database

Collect listings from Alpaca

To place orders with Alpaca, it is necessary to collect securities master listings from Alpaca. It is not sufficient to have collected the listings from another vendor; specific Alpaca fields must be present in the securities master database in order to allow QuantRocket to communite with the Alpaca API.

In [1]:
from quantrocket.master import collect_alpaca_listings
collect_alpaca_listings()
Out[1]:
{'status': 'success', 'msg': 'successfully loaded alpaca securities'}

Real-time database

Next, create the real-time database for collecting data from Polygon.io. These steps simply create the database. Real-time data collection will be initiated from the Zipline strategy code. First, create the tick database. Note that we are collecting second-level data instead of ticks to reduce the data volume and increase the potential universe size. See the usage guide for more information.

In [2]:
from quantrocket.realtime import create_polygon_tick_db
create_polygon_tick_db(
    "us-stk-realtime",
    # specifying a universe is required, but we will override this when initiating data 
    # collection in the Zipline strategy, so the universe need not exist
    universes="us-stk",
    fields=["SecondOpen",
            "SecondHigh",
            "SecondLow",
            "SecondClose",
            "SecondVolume"])
Out[2]:
{'status': 'successfully created tick database us-stk-realtime'}

Then create the 1-minute aggregate database derived from the tick database:

In [3]:
from quantrocket.realtime import create_agg_db
create_agg_db(
    "us-stk-realtime-1min",
    tick_db_code="us-stk-realtime",
    bar_size="1m",
    fields={
        "SecondOpen":["Open"],
        "SecondHigh": ["High"],
        "SecondLow": ["Low"],
        "SecondClose": ["Close"],
        "SecondVolume": ["Sum"]})
Out[3]:
{'status': 'successfully created aggregate database us-stk-realtime-1min from tick database us-stk-realtime'}