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. 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.
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"])
Then create the 1-minute aggregate database derived from the tick database:
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"]})