def perform_trade_logic(self):
        # Is buying at the market lower than the average price?
        is_buy_signal = self.ask_price < self.average_price

        # Is selling at the market higher than the average price?
        is_sell_signal = self.average_price > self.bid_price

        # Print signal values on every tick
        print dt.datetime.now(), \
            " BUY/SELL? ", is_buy_signal, "/", is_sell_signal, \
            " Avg:", self.average_price

        # Use generated signals, if any, to open a position
        if self.average_price != 0 \
            and self.bid_price != 0 \
            and self.ask_price != 0 \
            and self.position == 0 \
                and not self.is_position_opened:

            if is_sell_signal:
                self.place_market_order(self.symbol, self.qty, False)
                self.is_position_opened = True

            elif is_buy_signal:
                self.place_market_order(self.symbol, self.qty, True)
                self.is_position_opened = True

        # If position is already opened, use generated signals
        # to close the position.
        elif self.is_position_opened:

            if self.position > 0 and is_sell_signal:
                self.place_market_order(self.symbol, self.qty, False)
                self.is_position_opened = False

            elif self.position <0 and is_buy_signal:
                self.place_market_order(self.symbol, self.qty, True)
                self.is_position_opened = False

            # When the position is open, keep track of our
            # unrealized and realized P&Ls
            self.monitor_position()
dataset/ETHPy150Open jamesmawm/Mastering-Python-for-Finance-source-codes/B03898_08_codes/AlgoSystem.py/AlgoSystem.perform_trade_logic/swapped operands of `>`