Hi Brian,
I've been trying to figure out why my minute-freq Zipline strategy works fine in backtest but not in live. I've found that the minute data is not correctly being passed to the 'data' object during the live strategy run.
I discovered this by writing the price values from data.current to file each minute in the handle_data method. A screenshot of this file output is here:
To check that the data was being received correctly from IBKR, I queried the aggregate database that is supposed to be mapped to zipline. There, I see that all the data exists and looks correct. A screenshot of this download is here:
As you can see, most of the data passed to the 'data' object in live trading is missing (nan), and when not null, is not accurate. This is the case for all the assets I had under watch (roughly a couple dozen).
My implementation of the realtime data collection in before_trading_start is verbatim from the user guide. Specifically:
if context.arena == 'trade':
# Request tick data for all assets under watch + SPY
sids = [asset.real_sid for asset in context.assets] + ['FIBBG000BDTBL9']
if sids:
collect_market_data('all-stk-etf-tick-2',
sids=sids,
until='16:01:00 America/New_York')
# Assign fields for zipline to recognize
set_realtime_db('usstock-tick-1min-2',
fields={'close': 'LastPriceClose',
'open': 'LastPriceOpen',
'high': 'LastPriceHigh',
'low': 'LastPriceLow',
'volume': 'VolumeClose' })
Tldr, it appears that data is correctly being received and aggregated locally, but is not being fed/mapped to the live zipline strategy correctly. Not sure how to further debug this further. Any ideas?
Additionally, the 'VolumeClose' field in the aggregate db appears to be cumulative volume for the day. The zipline 'volume' field is supposed to be volume traded in the single minute. Is this something that needs to be manually changed in the mapping?
Thanks,
Paul.