def on_data(self, data: Slice): self._latest_slice = data if self._active_straddle is None or self._equity_symbol not in data: return spy_price = data[self._equity_symbol].price if spy_price is None or spy_price <= 0: self.debug("[EXIT] No valid SPY price in this slice, skipping exit logic.") return self._check_exit_logic(spy_price) def _check_exit_logic(self, spy_price) -> None: if self._straddle_entry_price <= 0: self.debug("[_CHECK_EXIT_LOGIC] Early exit – invalid straddle_entry_price") return pct_move = (spy_price - self._straddle_entry_price) / self._straddle_entry_price self.debug(f"[EVAL] {self.time} Δ={pct_move:.4%} entry={self._straddle_entry_price:.2f}") self.debug( f"[_CHECK_EXIT_LOGIC][{'LIVE' if self.live_mode else 'BT'}] time={self.time} " f"SPY={spy_price:.4f}, straddle_entry={self._straddle_entry_price:.4f}, " f"pct_move={pct_move:.6f}" )
When back testing it is working just fine but when live deploy, SPY price is getting stuck at a single price. For eg, if it recorded 625 then code is using 625 every second and not changing and hence pct move will also be zero and code will not trigger any exit logic. What am i doing wrong here. I use IBKR and i have also subscribed to data L1 and L2.
thank you in advance
Mia Alissi
Here is a robust rewrite (with explanation and detailed logging) to help Jerry handle live and backtesting differences in QuantConnect, particularly with IBKR, where the incoming data format for SPY may differ:
Key Takeaways for Jerry:
self.securities[self._equity_symbol].priceis a last resort, as that value can be stale in live mode.Let me know if you want this refactored for your actual implementation details, or if you spot a specific data type in your logs!
Sources: Handling Data - QuantConnect.com, docs writing algorithms datasets quantconnect cash indices, Live Features Algorithm, Logging - QuantConnect.com, docs writing algorithms datasets cboe vix daily price
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jerry Patel
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!