Browse Source

_execute_buy_on_chain優化

skyfffire 5 months ago
parent
commit
985739874e
2 changed files with 9 additions and 4 deletions
  1. 8 3
      erc20_to_mexc.py
  2. 1 1
      toto.readme

+ 8 - 3
erc20_to_mexc.py

@@ -372,7 +372,12 @@ class ArbitrageProcess:
             # 调用链上客户端执行买入交易
             signed_tx = web3._sign(self.tx, self.gas_limit_multiplier)
             self.chain_tx_hash = web3.w3.to_hex(signed_tx.hash)
-            web3.w3.eth.send_raw_transaction(signed_tx.raw_transaction)
+            try:
+                web3.w3.eth.send_raw_transaction(signed_tx.raw_transaction)
+            except Exception as e:
+                msg = f"据反饋說链上买入失败:{e}, 交易哈希:{self.chain_tx_hash}"
+                logger.error(msg)
+                add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
 
             # 交易成功后刷新全局nonce
             with self.core_lock:
@@ -387,12 +392,12 @@ class ArbitrageProcess:
                 }
 
             # 交易成功
-            msg = f"链上买入交易已发送, 交易哈希:{self.chain_tx_hash}"
+            msg = f"再次確認交易是否上鏈:{self.chain_tx_hash}"
             logger.info(msg)
             add_state_flow_entry(self.process_item, self.current_state, msg, "success")
             self._set_state(self.STATE_WAITING_CHAIN_CONFIRM)
         except Exception as e:
-            msg = f"据反饋說链上买入失败:{e}, 交易哈希:{self.chain_tx_hash}"
+            msg = f"鏈上買入未處理的錯誤:{e}, 交易哈希:{self.chain_tx_hash}"
             logger.error(msg)
             add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
             self._set_state(self.STATE_WAITING_CHAIN_CONFIRM)

+ 1 - 1
toto.readme

@@ -8,7 +8,7 @@
 [-] 成本統計,計算純利潤
 
 2025-06-06
-[ ] 链上买入失败
+[-] 链上买入失败
 [ ] 解密HASH進行鑒權
 [ ] json用pprint美化后輸出
 [ ] 查询交易所到账状态时发生错误:'balances'