def delete_overdue_order(self, latest_deal_price): now_ts = int(time.time()) self.timeLog('Start to delete pending orders..., %s' % timestamp2string(now_ts)) orders_list = self.spotAPI.get_orders_list('open', instrument_id) self.timeLog('before delete, pending orders num: %d' % len(orders_list)) for order in orders_list[0]: o_price = float(order['price']) o_time = string2timestamp(order['timestamp']) if o_time < now_ts - 60 or o_price < latest_deal_price * 0.995 or o_price or o_price > 1.005 * latest_deal_price: order_id = order['order_id'] self.revoke_order(order_id, now_ts) self.timeLog('Finish delete pending orders')
# 完全成交的订单或已经撤单的订单 status = order_info['status'] side = order_info['side'] if status == 'filled': print("order %s 已完全成交" % str(old_order_id)) del_list.append(old_order_id) if side == 'buy': more = 1 elif side == 'sell': more = 0 elif status == 'part_filled': if side == 'buy': more = 1 elif status == 'cancelled': del_list.append(old_order_id) elif int(ts) - (string2timestamp(order_info['timestamp']) + 8 * 3600) >= 3: print('撤单重挂,ts:%s, 真实时间:%s' % (timestamp2string(ts), timestamp2string(time.time()))) try: print('撤单结果: %s' % spotAPI.revoke_order(instrument_id, old_order_id)) except Exception as e: print(repr(e)) traceback.print_exc() del_list.append(old_order_id) continue ret = spotAPI.get_specific_ticker(instrument_id) print('当前行情: %s' % ret) if side == 'buy': buy_price = float(ret['best_ask']) try: order_id = buy_all_position(spotAPI, instrument_id, buy_price) if order_id:
status = order_info['status'] ret = spotAPI.get_specific_ticker(instrument_id) buy_price = float(ret['best_bid']) + 0.0001 sell_price = float(ret['best_ask']) - 0.0001 if status == 'filled': print("order %s 已完全成交" % str(old_order_id)) del_list.append(old_order_id) side = order_info['side'] if side == 'buy': more = 1 elif side == 'sell': more = 0 elif status == 'cancelled': del_list.append(old_order_id) elif int(ts) > string2timestamp( order_info['timestamp']) + 10 + 8 * 3600: spotAPI.revoke_order(instrument_id, old_order_id) for del_id in del_list: order_id_queue.remove(del_id) del_list = [] time.sleep(1) if int(ts) - last_minute_ts > 10: last_minute_ts = int(ts) if more == 1: print("持有做多单") else: print("未持有单") print("calculating macd...") try:
order_info = spotAPI.get_order_info( old_order_id, instrument_id) except Exception as e: print(repr(e)) traceback.print_exc() del_list.append(old_order_id) continue print('order_id: %s, order_info: %s' % (old_order_id, order_info)) # 完全成交的订单或已经撤单的订单 status = order_info['status'] side = order_info['side'] print('now timestamp: %d, order created time: %d' % (int(ts), string2timestamp(order_info['created_at']) + 8 * 3600)) if status == 'filled': print("order %s 已完全成交" % str(old_order_id)) del_list.append(old_order_id) if side == 'buy': more = 1 elif side == 'sell': more = 0 elif status == 'cancelled': del_list.append(old_order_id) elif int(ts) - (string2timestamp(order_info['created_at']) + 8 * 3600) >= 3: print('撤单重挂') try: