Error in trading causes Zipline to crash

I’m running into this persistent error every time I try to make trades. I had already made a week of trades successfully before this started popping up. I’m curious if anyone here has seen something similar and resolved it?

quantrocket zipline trade ‘uptrend_ibkr’ --bundle usstock-1d --data-frequency daily XXXXXX

2021-05-05 16:46:25 quantrocket.zipline: ERROR Traceback (most recent call last):
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “sym://qrocket_log_py”, line 34, in wrapped
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “sym://qrocket_qrzipline_trade_trade_py”, line 63, in mule_trade_algo
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “sym://qrocket_qrzipline_trade_trade_py”, line 187, in trade_algo
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “/opt/conda/lib/python3.6/site-packages/zipline/algorithm.py”, line 675, in run
2021-05-05 16:46:25 quantrocket.zipline: ERROR for perf in self.get_generator():
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “/opt/conda/lib/python3.6/site-packages/zipline/gens/tradesimulation.py”, line 214, in transform
2021-05-05 16:46:25 quantrocket.zipline: ERROR self._cleanup_expired_assets(dt, position_assets)
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “/opt/conda/lib/python3.6/site-packages/zipline/gens/tradesimulation.py”, line 263, in _cleanup_expired_assets
2021-05-05 16:46:25 quantrocket.zipline: ERROR metrics_tracker.process_close_position(asset, dt, data_portal)
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “/opt/conda/lib/python3.6/site-packages/zipline/finance/metrics/tracker.py”, line 189, in process_close_position
2021-05-05 16:46:25 quantrocket.zipline: ERROR self._ledger.close_position(asset, dt, data_portal)
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “/opt/conda/lib/python3.6/site-packages/zipline/finance/ledger.py”, line 577, in close_position
2021-05-05 16:46:25 quantrocket.zipline: ERROR data_portal,
2021-05-05 16:46:25 quantrocket.zipline: ERROR File “sym://qrocket_qrzipline_patch_py”, line 22, in disable_if_live_trading
2021-05-05 16:46:25 quantrocket.zipline: ERROR NotImplementedError: PositionTracker.maybe_create_close_position_transaction() was called in live trading. This method simulates a transaction to auto-close a position (such as an expired futures contract), but in live trading a simulated transaction is problematic. Please close the position on your own with a real transaction.
2021-05-05 16:46:25 quantrocket.zipline: ERROR

I haven’t changed any code in my strategy. There seems to be some other underlying reason for it.

This probably means a stock in which you held a position was delisted. Does that sound right?

When this happens in a backtest, Zipline creates a simulated transaction to clear the position out. Zipline assumes the transaction gets filled at the last available sale price.

The error message you’re seeing is basically a placeholder we added for live trading to say, “we need to think about what should happen here.” Now that this has come up, we’ll try to devise a good solution and get it in an upcoming release.

In the meantime, a workaround would be to manually close out any existing positions, rename the file, and run the strategy under the new file name. This will result in a new OrderRef and thus will give Zipline a fresh start with no execution history and thus no record of positions it needs to auto-close with simulated transactions.

You are correct brian! It was APHA. I’m curious, is there a programmatic way to get advance warning about delistings?

Not that I’m aware of.