From 5896f0e9fe5ff692fe26c2e34f846d3c9073b42d Mon Sep 17 00:00:00 2001 From: davidlatte Date: Thu, 3 Oct 2024 15:08:59 -0700 Subject: [PATCH] after_market_closes() was getting the wrong price data from get_last_price() --- lumibot/entities/data.py | 4 +++- lumibot/trading_builtins/custom_stream.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lumibot/entities/data.py b/lumibot/entities/data.py index 393aab69..042a0ff2 100644 --- a/lumibot/entities/data.py +++ b/lumibot/entities/data.py @@ -402,7 +402,9 @@ def get_last_price(self, dt, length=1, timeshift=0): float """ iter_count = self.get_iter_count(dt) - price = self.datalines["open"].dataline[iter_count] + open_price = self.datalines["open"].dataline[iter_count] + close_price = self.datalines["close"].dataline[iter_count] + price = close_price if dt > self.datalines["datetime"].dataline[iter_count] else open_price return price @check_data diff --git a/lumibot/trading_builtins/custom_stream.py b/lumibot/trading_builtins/custom_stream.py index f1abf25b..a3bea9ff 100644 --- a/lumibot/trading_builtins/custom_stream.py +++ b/lumibot/trading_builtins/custom_stream.py @@ -82,9 +82,13 @@ def _poll(self): if self.POLL_EVENT not in self._actions_mapping: raise ValueError("No action is defined for the poll event. You must register a polling action with " "add_action()") + try: self._process_queue_event(self.POLL_EVENT, {}) except queue.Full: logging.info("Polling action itself has added too many events to the queue. Skipping this polling cycle, " "(it is incomplete) to allow the queue to drain. The next cycle will occur as scheduled.") return + # Ensure that the Polling thread does not die if an exception is raised in the event processing. + except Exception as e: # noqa + logging.exception(f"An error occurred while polling. {e}")