def _check(self) -> None: """Based on the newly updated info, check if we should take action or not""" if not self._is_initiated: self._is_initiated = True if jh.is_live() and jh.is_debugging(): logger.info( f'Executing {self.name}-{self.exchange}-{self.symbol}-{self.timeframe}' ) # for caution to make sure testing on livetrade won't bleed your account if jh.is_test_driving() and store.completed_trades.count >= 2: logger.info('Maximum allowed trades in test-drive mode is reached') return if self._open_position_orders != [] and self.is_close and self.should_cancel( ): self._execute_cancel() # make sure order cancellation response is received via WS if jh.is_live(): # sleep a little until cancel is received via WS sleep(0.1) # just in case, sleep some more if necessary for _ in range(20): if store.orders.count_active_orders( self.exchange, self.symbol) == 0: break logger.info('sleeping 0.2 more seconds...') sleep(0.2) # If it's still not cancelled, something is wrong. Handle cancellation failure if store.orders.count_active_orders(self.exchange, self.symbol) != 0: raise exceptions.ExchangeNotResponding( 'The exchange did not respond as expected') if self.position.is_open: self._update_position() if jh.is_backtesting() or jh.is_unit_testing(): store.orders.execute_pending_market_orders() if self.position.is_close and self._open_position_orders == []: should_short = self.should_short() should_long = self.should_long() # validation if should_short and should_long: raise exceptions.ConflictingRules( 'should_short and should_long should not be true at the same time.' ) if should_long: self._execute_long() elif should_short: self._execute_short()
def test_is_test_driving(): assert jh.is_test_driving() is False