To prepare for live trading with Alpaca, the following steps are required:
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.
from quantrocket.master import collect_alpaca_listings
collect_alpaca_listings()
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:
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"
)
Then create the 1-minute aggregate database derived from the tick database:
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"]})