def grid_trader(self):
    '\n        执行核心逻辑，网格交易的逻辑.\n        :return:\n        '
    (bid_price, ask_price) = self.get_bid_ask_price()
    print(f'bid_price: {bid_price}, ask_price: {ask_price}')
    quantity = round_to(float(config.quantity), float(config.min_qty))
    self.buy_orders.sort(key=(lambda x: float(x['price'])), reverse=True)
    self.sell_orders.sort(key=(lambda x: float(x['price'])), reverse=True)
    print(f'buy orders: {self.buy_orders}')
    print('------------------------------')
    print(f'sell orders: {self.sell_orders}')
    buy_delete_orders = []
    sell_delete_orders = []
    for buy_order in self.buy_orders:
        check_order = self.http_client.get_order(buy_order.get('symbol', config.symbol), client_order_id=buy_order.get('clientOrderId'))
        if check_order:
            if (check_order.get('status') == OrderStatus.CANCELED.value):
                buy_delete_orders.append(buy_order)
                print(f"buy order status was canceled: {check_order.get('status')}")
            elif (check_order.get('status') == OrderStatus.FILLED.value):
                logging.info(f"买单成交时间: {datetime.now()}, 价格: {check_order.get('price')}, 数量: {check_order.get('origQty')}")
                sell_price = round_to((float(check_order.get('price')) * (1 + float(config.gap_percent))), float(config.min_price))
                if (0 < sell_price < ask_price):
                    sell_price = round_to(ask_price, float(config.min_price))
                new_sell_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.SELL, order_type=OrderType.LIMIT, quantity=quantity, price=sell_price)
                if new_sell_order:
                    buy_delete_orders.append(buy_order)
                    self.sell_orders.append(new_sell_order)
                buy_price = round_to((float(check_order.get('price')) * (1 - float(config.gap_percent))), config.min_price)
                if (buy_price > bid_price > 0):
                    buy_price = round_to(bid_price, float(config.min_price))
                new_buy_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.BUY, order_type=OrderType.LIMIT, quantity=quantity, price=buy_price)
                if new_buy_order:
                    self.buy_orders.append(new_buy_order)
            elif (check_order.get('status') == OrderStatus.NEW.value):
                print('buy order status is: New')
            else:
                print(f"buy order status is not above options: {check_order.get('status')}")
    for delete_order in buy_delete_orders:
        self.buy_orders.remove(delete_order)
    for sell_order in self.sell_orders:
        check_order = self.http_client.get_order(sell_order.get('symbol', config.symbol), client_order_id=sell_order.get('clientOrderId'))
        if check_order:
            if (check_order.get('status') == OrderStatus.CANCELED.value):
                sell_delete_orders.append(sell_order)
                print(f"sell order status was canceled: {check_order.get('status')}")
            elif (check_order.get('status') == OrderStatus.FILLED.value):
                logging.info(f"卖单成交时间: {datetime.now()}, 价格: {check_order.get('price')}, 数量: {check_order.get('origQty')}")
                buy_price = round_to((float(check_order.get('price')) * (1 - float(config.gap_percent))), float(config.min_price))
                if (buy_price > bid_price > 0):
                    buy_price = round_to(bid_price, float(config.min_price))
                new_buy_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.BUY, order_type=OrderType.LIMIT, quantity=quantity, price=buy_price)
                if new_buy_order:
                    sell_delete_orders.append(sell_order)
                    self.buy_orders.append(new_buy_order)
                sell_price = round_to((float(check_order.get('price')) * (1 + float(config.gap_percent))), float(config.min_price))
                if (0 < sell_price < ask_price):
                    sell_price = round_to(ask_price, float(config.min_price))
                new_sell_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.SELL, order_type=OrderType.LIMIT, quantity=quantity, price=sell_price)
                if new_sell_order:
                    self.sell_orders.append(new_sell_order)
            elif (check_order.get('status') == OrderStatus.NEW.value):
                print('sell order status is: New')
            else:
                print(f"sell order status is not in above options: {check_order.get('status')}")
    for delete_order in sell_delete_orders:
        self.sell_orders.remove(delete_order)
    if (len(self.buy_orders) <= 0):
        if (bid_price > 0):
            price = round_to((bid_price * (1 - float(config.gap_percent))), float(config.min_price))
            buy_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.BUY, order_type=OrderType.LIMIT, quantity=quantity, price=price)
            if buy_order:
                self.buy_orders.append(buy_order)
    elif (len(self.buy_orders) > int(config.max_orders)):
        self.buy_orders.sort(key=(lambda x: float(x['price'])), reverse=False)
        delete_order = self.buy_orders[0]
        order = self.http_client.cancel_order(delete_order.get('symbol'), client_order_id=delete_order.get('clientOrderId'))
        if order:
            self.buy_orders.remove(delete_order)
    if (len(self.sell_orders) <= 0):
        if (ask_price > 0):
            price = round_to((ask_price * (1 + float(config.gap_percent))), float(config.min_price))
            order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.SELL, order_type=OrderType.LIMIT, quantity=quantity, price=price)
            if order:
                self.sell_orders.append(order)
    elif (len(self.sell_orders) > int(config.max_orders)):
        self.sell_orders.sort(key=(lambda x: x['price']), reverse=True)
        delete_order = self.sell_orders[0]
        order = self.http_client.cancel_order(delete_order.get('symbol'), client_order_id=delete_order.get('clientOrderId'))
        if order:
            self.sell_orders.remove(delete_order)
执行核心逻辑，网格交易的逻辑.
:return:
def grid_trader(self):
    '\n        执行核心逻辑，网格交易的逻辑.\n        :return:\n        '
    (bid_price, ask_price) = self.get_bid_ask_price()
    print(f'bid_price: {bid_price}, ask_price: {ask_price}')
    quantity = round_to(float(config.quantity), float(config.min_qty))
    self.buy_orders.sort(key=(lambda x: float(x['price'])), reverse=True)
    self.sell_orders.sort(key=(lambda x: float(x['price'])), reverse=True)
    print(f'buy orders: {self.buy_orders}')
    print('------------------------------')
    print(f'sell orders: {self.sell_orders}')
    buy_delete_orders = []
    sell_delete_orders = []
    for buy_order in self.buy_orders:
        check_order = self.http_client.get_order(buy_order.get('symbol', config.symbol), client_order_id=buy_order.get('clientOrderId'))
        if check_order:
            if (check_order.get('status') == OrderStatus.CANCELED.value):
                buy_delete_orders.append(buy_order)
                print(f"buy order status was canceled: {check_order.get('status')}")
            elif (check_order.get('status') == OrderStatus.FILLED.value):
                logging.info(f"买单成交时间: {datetime.now()}, 价格: {check_order.get('price')}, 数量: {check_order.get('origQty')}")
                sell_price = round_to((float(check_order.get('price')) * (1 + float(config.gap_percent))), float(config.min_price))
                if (0 < sell_price < ask_price):
                    sell_price = round_to(ask_price, float(config.min_price))
                new_sell_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.SELL, order_type=OrderType.LIMIT, quantity=quantity, price=sell_price)
                if new_sell_order:
                    buy_delete_orders.append(buy_order)
                    self.sell_orders.append(new_sell_order)
                buy_price = round_to((float(check_order.get('price')) * (1 - float(config.gap_percent))), config.min_price)
                if (buy_price > bid_price > 0):
                    buy_price = round_to(bid_price, float(config.min_price))
                new_buy_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.BUY, order_type=OrderType.LIMIT, quantity=quantity, price=buy_price)
                if new_buy_order:
                    self.buy_orders.append(new_buy_order)
            elif (check_order.get('status') == OrderStatus.NEW.value):
                print('buy order status is: New')
            else:
                print(f"buy order status is not above options: {check_order.get('status')}")
    for delete_order in buy_delete_orders:
        self.buy_orders.remove(delete_order)
    for sell_order in self.sell_orders:
        check_order = self.http_client.get_order(sell_order.get('symbol', config.symbol), client_order_id=sell_order.get('clientOrderId'))
        if check_order:
            if (check_order.get('status') == OrderStatus.CANCELED.value):
                sell_delete_orders.append(sell_order)
                print(f"sell order status was canceled: {check_order.get('status')}")
            elif (check_order.get('status') == OrderStatus.FILLED.value):
                logging.info(f"卖单成交时间: {datetime.now()}, 价格: {check_order.get('price')}, 数量: {check_order.get('origQty')}")
                buy_price = round_to((float(check_order.get('price')) * (1 - float(config.gap_percent))), float(config.min_price))
                if (buy_price > bid_price > 0):
                    buy_price = round_to(bid_price, float(config.min_price))
                new_buy_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.BUY, order_type=OrderType.LIMIT, quantity=quantity, price=buy_price)
                if new_buy_order:
                    sell_delete_orders.append(sell_order)
                    self.buy_orders.append(new_buy_order)
                sell_price = round_to((float(check_order.get('price')) * (1 + float(config.gap_percent))), float(config.min_price))
                if (0 < sell_price < ask_price):
                    sell_price = round_to(ask_price, float(config.min_price))
                new_sell_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.SELL, order_type=OrderType.LIMIT, quantity=quantity, price=sell_price)
                if new_sell_order:
                    self.sell_orders.append(new_sell_order)
            elif (check_order.get('status') == OrderStatus.NEW.value):
                print('sell order status is: New')
            else:
                print(f"sell order status is not in above options: {check_order.get('status')}")
    for delete_order in sell_delete_orders:
        self.sell_orders.remove(delete_order)
    if (len(self.buy_orders) <= 0):
        if (bid_price > 0):
            price = round_to((bid_price * (1 - float(config.gap_percent))), float(config.min_price))
            buy_order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.BUY, order_type=OrderType.LIMIT, quantity=quantity, price=price)
            if buy_order:
                self.buy_orders.append(buy_order)
    elif (len(self.buy_orders) > int(config.max_orders)):
        self.buy_orders.sort(key=(lambda x: float(x['price'])), reverse=False)
        delete_order = self.buy_orders[0]
        order = self.http_client.cancel_order(delete_order.get('symbol'), client_order_id=delete_order.get('clientOrderId'))
        if order:
            self.buy_orders.remove(delete_order)
    if (len(self.sell_orders) <= 0):
        if (ask_price > 0):
            price = round_to((ask_price * (1 + float(config.gap_percent))), float(config.min_price))
            order = self.http_client.place_order(symbol=config.symbol, order_side=OrderSide.SELL, order_type=OrderType.LIMIT, quantity=quantity, price=price)
            if order:
                self.sell_orders.append(order)
    elif (len(self.sell_orders) > int(config.max_orders)):
        self.sell_orders.sort(key=(lambda x: x['price']), reverse=True)
        delete_order = self.sell_orders[0]
        order = self.http_client.cancel_order(delete_order.get('symbol'), client_order_id=delete_order.get('clientOrderId'))
        if order:
            self.sell_orders.remove(delete_order)