From 74bddd8eb0d49e31238a8901dda98d9d04f7d33d Mon Sep 17 00:00:00 2001 From: pragi Date: Mon, 8 Mar 2021 15:44:08 -0500 Subject: [PATCH] Update main.py - Handle scenario where we are holding a position, but there's no open sell order. - pd.Timestamp in checkup function giving "Cannot pass a datetime or Timestamp with tzinfo". Replaced with tz_convert --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index c435e68..8426c9b 100644 --- a/main.py +++ b/main.py @@ -51,6 +51,7 @@ def _init_state(self): if self._position is not None: if self._order is None: self._state = 'TO_SELL' + self._submit_sell() # we should trigger sell, otherwise the stock is stuck in TO_SELL state until EOD else: self._state = 'SELL_SUBMITTED' if self._order.side != 'sell': @@ -78,7 +79,7 @@ def checkup(self, position): order = self._order if (order is not None and order.side == 'buy' and now - - pd.Timestamp(order.submitted_at, tz='America/New_York') > pd.Timedelta('2 min')): + pd.Timestamp(order.submitted_at).tz_convert('America/New_York') > pd.Timedelta('2 min')): last_price = self._api.get_last_trade(self._symbol).price self._l.info( f'canceling missed buy order {order.id} at {order.limit_price} '