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:

In [2]:
from quantrocket.realtime import create_polygon_tick_db
create_polygon_tick_db(
    "us-stk-tick", 
    fields=["LastPrice", "LastSize"],
    # 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"  
)
Out[2]:
{'status': 'successfully created tick database us-stk-tick'}

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-tick-1min", 
    tick_db_code="us-stk-tick", 
    bar_size="1m", 
    fields={"LastPrice": ["Open","High","Low","Close"], "LastSize":["Sum"]})
Out[3]:
{'status': 'successfully created aggregate database us-stk-tick-1min from tick database us-stk-tick'}