Browse Source

鏈上交易是否成功由okx的api説了算。

skyfffire 5 months ago
parent
commit
e93a58d0ae
3 changed files with 16 additions and 13 deletions
  1. 5 7
      erc20_to_mexc.py
  2. 4 3
      toto.readme
  3. 7 3
      web3_py_client.py

+ 5 - 7
erc20_to_mexc.py

@@ -370,10 +370,9 @@ class ArbitrageProcess:
                 self.tx['nonce'] = self.core_data['nonce']
             
             # 调用链上客户端执行买入交易
-            self.chain_tx_hash = web3._sign_and_send_transaction(
-                self.tx,
-                self.gas_limit_multiplier
-            )
+            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)
 
             # 交易成功后刷新全局nonce
             with self.core_lock:
@@ -392,12 +391,11 @@ class ArbitrageProcess:
             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}"
+            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_EXCHANGE_ROLLBACK)
+            self._set_state(self.STATE_WAITING_CHAIN_CONFIRM)
 
             traceback.print_exc()
 

+ 4 - 3
toto.readme

@@ -6,12 +6,13 @@
 [-] 緊急檢修ok api超頻問題
 [-] 日志輸出到文件
 [-] 成本統計,計算純利潤
-[ ] 解密HASH進行鑒權
 
-2025-06-05
+2025-06-06
+[ ] 链上买入失败
+[ ] 解密HASH進行鑒權
 [ ] json用pprint美化后輸出
 [ ] 查询交易所到账状态时发生错误:'balances'
-[ ] 做另一個方向之前,需要先整理策略層架構,當前架構如何兼容多策略
 
 2025-06-07
+[ ] 做另一個方向之前,需要先整理策略層架構,當前架構如何兼容多策略
 [ ] 另一個方向

+ 7 - 3
web3_py_client.py

@@ -450,7 +450,7 @@ if __name__ == "__main__":
             'msg': ''
         }
         '''
-        pprint(ok_chain_client.history(CHAIN_ID, '0x344d2d0a9efdfb46b6130a58a40e117bb3bf6181b03b09b65b4d6cc8256f1e2f'))
+        # pprint(ok_chain_client.history(CHAIN_ID, '0x344d2d0a9efdfb46b6130a58a40e117bb3bf6181b03b09b65b4d6cc8256f1e2f'))
 
         # pprint(ok_chain_client.gas_limit(CHAIN_ID, tx['from'], tx['to'], tx['value']))
 
@@ -467,8 +467,12 @@ if __name__ == "__main__":
         # logger.info(f"{tx_hash} 交易已确认! Status: {'Success' if receipt.status == 1 else 'Failed'}")
 
 
-        # # ok api發交易測試
-        # signed_tx = client._sign(tx)
+        # ok api發交易測試
+        signed_tx = client._sign(tx)
+        pprint(signed_tx)
+        tx_hash = client.w3.to_hex(signed_tx.hash)
+        pprint(tx_hash)
+        # client.w3.eth.send_raw_transaction(signed_tx.raw_transaction)
         # raw_transaction = client.w3.to_hex(signed_tx.raw_transaction)
         # broadcast_rst = ok_chain_client.broadcast(CHAIN_ID, USER_WALLET, raw_transaction)