(self)
Perform checks before placing orders.
Perform checks before placing orders.
Perform checks before placing orders .
def sanity_check(self):
        """Perform checks before placing orders."""

        # Check if OB is empty - if so, can't quote.
        self.exchange.check_if_orderbook_empty()

        # Ensure market is still open.
        self.exchange.check_market_open()

        # Get ticker, which sets price offsets and prints some debugging info.
        ticker = self.get_ticker()

        # Sanity check:
        if self.get_price_offset(-1) >= ticker["sell"] or self.get_price_offset(1) <= ticker["buy"]:
            logger.error(self.start_position_buy, self.start_position_sell)
            logger.error("%s %s %s %s" % (self.get_price_offset(-1), ticker["sell"], self.get_price_offset(1), ticker["buy"]))
            logger.error("Sanity check failed, exchange data is inconsistent")
            sys.exit()

        # Messanging if the position limits are reached
        if self.long_position_limit_exceeded():
            logger.info("Long delta limit exceeded")
            logger.info("Current Position: %.f, Maximum Position: %.f" %
                        (self.exchange.get_delta(), settings.MAX_POSITION))

        if self.short_position_limit_exceeded():
            logger.info("Short delta limit exceeded")
            logger.info("Current Position: %.f, Minimum Position: %.f" %
                        (self.exchange.get_delta(), settings.MIN_POSITION))
def sanity_check ( self ) : # Check if OB is empty - if so, can't quote. self . exchange . check_if_orderbook_empty ( ) # Ensure market is still open. self . exchange . check_market_open ( ) # Get ticker, which sets price offsets and prints some debugging info. ticker = self . get_ticker ( ) # Sanity check: if self . get_price_offset ( - 1 ) >= ticker [ "sell" ] or self . get_price_offset ( 1 ) <= ticker [ "buy" ] : logger . error ( self . start_position_buy , self . start_position_sell ) logger . error ( "%s %s %s %s" % ( self . get_price_offset ( - 1 ) , ticker [ "sell" ] , self . get_price_offset ( 1 ) , ticker [ "buy" ] ) ) logger . error ( "Sanity check failed, exchange data is inconsistent" ) sys . exit ( ) # Messanging if the position limits are reached if self . long_position_limit_exceeded ( ) : logger . info ( "Long delta limit exceeded" ) logger . info ( "Current Position: %.f, Maximum Position: %.f" % ( self . exchange . get_delta ( ) , settings . MAX_POSITION ) ) if self . short_position_limit_exceeded ( ) : logger . info ( "Short delta limit exceeded" ) logger . info ( "Current Position: %.f, Minimum Position: %.f" % ( self . exchange . get_delta ( ) , settings . MIN_POSITION ) )