|
|
@@ -325,37 +325,41 @@ class ArbitrageProcess:
|
|
|
msg = f"等待交易所现货卖出订单确认:{exchange_sell_order_id}"
|
|
|
logging.info(msg)
|
|
|
add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
|
|
|
+
|
|
|
+ last_order = None
|
|
|
try:
|
|
|
# 查询交易所订单状态
|
|
|
waiting_times = 30
|
|
|
- while True:
|
|
|
+ while waiting_times > 0:
|
|
|
params = {
|
|
|
"symbol": self.symbol.replace('_', ''),
|
|
|
"orderId": exchange_sell_order_id
|
|
|
}
|
|
|
order = mexc.trade.get_order(params)
|
|
|
+ last_order = order
|
|
|
|
|
|
- if order['status'] == "FILLED":
|
|
|
+ if order['status'] in ["FILLED", "PARTIALLY_CANCELED"]:
|
|
|
money = Decimal(order['cummulativeQuoteQty'])
|
|
|
amount = self.arbitrage_details["exchange_out_amount"]
|
|
|
price = money / amount
|
|
|
price = price.quantize(Decimal('1e-8'), rounding=ROUND_DOWN)
|
|
|
|
|
|
- msg = f"交易所现货卖出订单已完全成交, 价格:{price}。{order}"
|
|
|
- self.arbitrage_details["exchange_withdraw_amount"] = order['cummulativeQuoteQty']
|
|
|
-
|
|
|
+ msg = f"交易所现货卖出订单已完成, 价格:{price}。{order}"
|
|
|
logging.info(msg)
|
|
|
add_state_flow_entry(self.process_item, self.current_state, msg, "success")
|
|
|
|
|
|
+ self.arbitrage_details["exchange_withdraw_amount"] = order['cummulativeQuoteQty']
|
|
|
+
|
|
|
self._set_state(self.STATE_BUYING_ON_CHAIN)
|
|
|
return
|
|
|
else:
|
|
|
- # 继续等待成交
|
|
|
- pass
|
|
|
-
|
|
|
- time.sleep(1)
|
|
|
- waiting_times = waiting_times - 1
|
|
|
+ time.sleep(1)
|
|
|
+ waiting_times = waiting_times - 1
|
|
|
|
|
|
+ msg = f"交易所现货卖出订单失敗, 最後狀態:{last_order}。"
|
|
|
+ logging.info(msg)
|
|
|
+ add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
|
|
|
+ self._set_state(self.FAILED)
|
|
|
except Exception as e:
|
|
|
msg = f"查询交易所现货卖出订单状态时发生错误:{e}"
|
|
|
logging.error(msg)
|