Ver Fonte

修復抹茶訂單查詢bug,15u買的

skyfffire há 5 meses atrás
pai
commit
21313aca07
3 ficheiros alterados com 32 adições e 15 exclusões
  1. 14 10
      arbitrage_process.py
  2. 15 2
      mexc_client.py
  3. 3 3
      price_checker_ok.py

+ 14 - 10
arbitrage_process.py

@@ -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)

+ 15 - 2
mexc_client.py

@@ -547,15 +547,28 @@ if __name__ == '__main__':
             # print("\n测试下单 (POST /order/test)...")
             # test_order_params = {
             #     "symbol": "RATOUSDT",  # 使用常见的交易对,如 MXUSDT 或 BTCUSDT
-            #     "side": "SELL",
+            #     "side": "BUY",
             #     "type": "MARKET",
-            #     "quantity": "30000000",   # 根据交易对的最小名义价值/数量调整数量
+            #     # "quantity": "30000000",   # 根据交易对的最小名义价值/数量调整数量
+            #     "quoteOrderQty": "189"
             #     # "price": "0.0000290"     # 调整价格以便于测试
             # }
             # print(f"  测试订单参数: {test_order_params}")
             # test_order_response = client.trade.post_order(params=test_order_params)
             # print(f"测试订单响应: {test_order_response}")
 
+            '''
+            {'symbol': 'RATOUSDT', 'orderId': 'C02__554739165556662272055', 'orderListId': -1, 'clientOrderId': None, 'price': '0.00001259', 'origQty': '28000000', 'executedQty': '14714393.18', 'cummulativeQuoteQty': '186.6202641971',
+            'status': 'PARTIALLY_CANCELED', 'timeInForce': None, 'type': 'MARKET', 'side': 'SELL', 'stopPrice': None, 'icebergQty': None, 'time': 1748042359000, 'updateTime': 1748042360000, 'isWorking': True, 'origQuoteOrderQty': '0'}
+            '''
+            # params = {
+            #     "symbol": "RATOUSDT",
+            #     "orderId": "C02__554739165556662272055"
+            # }
+            # order = client.trade.get_order(params)
+            # logging.info(order)
+
+
             # print("\n提币测试...")
             # withdraw_params = {
             #     'coin': 'USDT',

+ 3 - 3
price_checker_ok.py

@@ -26,14 +26,14 @@ ARB_EXECUTOR_URL = "http://localhost:5002/submit_process"
 
 # --- 配置部分 ---
 IN_AMOUNT_TO_QUERY = decimal.Decimal('350')
-EXCHANGE_OUT_AMOUNT = decimal.Decimal('20000000')
-PROFIT_LIMIT = 0.01                                                 # 触发交易的利润阈值
+EXCHANGE_OUT_AMOUNT = decimal.Decimal('28000000')
+PROFIT_LIMIT = 0.03                                                 # 触发交易的利润阈值
 IN_TOKEN_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'     # USDT on Ethereum
 IN_TOKEN_DECIMALS = 6
 OUT_TOKEN_ADDRESS = '0xf816507E690f5Aa4E29d164885EB5fa7a5627860'    # RATO on Ethereum
 USER_WALLET = '0xb1f33026Db86a86372493a3B124d7123e9045Bb4'
 USER_EXCHANGE_WALLET = '0xc71835a042F4d870B0F4296cc89cAeb921a9f3DA'
-SLIPPAGE = PROFIT_LIMIT
+SLIPPAGE = 0.05
 MEXC_TARGET_PAIR_USDT = 'RATO_USDT'                                 # MEXC 现货交易对
 CHAIN_ID = 1