浏览代码

一些调整,还有很多bug。

skyfffire 5 月之前
父节点
当前提交
9d838dbd72
共有 5 个文件被更改,包括 35 次插入20 次删除
  1. 13 0
      arbitrage_process.py
  2. 4 4
      as.py
  3. 13 13
      mexc_client.py
  4. 3 3
      price_checker_ok.py
  5. 2 0
      submit_process_demo.py

+ 13 - 0
arbitrage_process.py

@@ -178,6 +178,7 @@ class ArbitrageProcess:
         logging.info(msg)
         add_state_flow_entry(self.process_item, self.current_state, msg, "pending")
         try:
+            # 交易所套保余额判断
             balances = mexc.trade.get_account_info()['balances']
             for balance in balances:
                 if balance['asset'] == self.coin:
@@ -192,6 +193,18 @@ class ArbitrageProcess:
                         logging.info(msg)
                         add_state_flow_entry(self.process_item, self.current_state, msg, "success")
                         break
+            
+            # 链上余额判断
+            from_token_balance = web3.get_erc20_balance(self.from_token_addr, self.user_wallet)
+            
+            if from_token_balance < self.arbitrage_details["chain_usdt_use"]:
+                msg = f"链上剩余{self.base_coin}: {from_token_balance}, 需要使用:{self.arbitrage_details["chain_usdt_use"]}, 余额不足,不能触发交易。"
+                logging.info(msg)
+                add_state_flow_entry(self.process_item, self.current_state, msg, "fail")
+                return
+            msg = f"链上剩余{self.base_coin}: {from_token_balance}, 需要使用:{self.arbitrage_details["chain_usdt_use"]}, 余额充足。"
+            logging.info(msg)
+            add_state_flow_entry(self.process_item, self.current_state, msg, "success")
                 
             self.arbitrage_details["chain_amount_before_trade"] = web3.get_erc20_balance(self.to_token_addr, self.user_exchange_wallet)
             # 调用链上客户端执行买入交易

+ 4 - 4
as.py

@@ -80,7 +80,7 @@ def move_completed_process_to_history(process_id_to_move: str) -> bool:
             item_to_move = processing_list.pop(found_index) # 从 processing_list 中移除并获取它
             
             # 假设在 item_to_move 中,其 currentState 已经被 arbitrage_process_flow 更新为 COMPLETED 或 FAILED
-            arbitrage_process.add_state_flow_entry(item_to_move, "MOVED_TO_HISTORY", f"流程处理完毕,移至历史记录。最终状态: {item_to_move.get('currentState', 'N/A')}", "info")
+            # arbitrage_process.add_state_flow_entry(item_to_move, "MOVED_TO_HISTORY", f"流程处理完毕,移至历史记录。最终状态: {item_to_move.get('currentState', 'N/A')}", "info")
             
             history_process_list.append(item_to_move) # 添加到 history_process_list
             logging.info(f"已将 process_id: {process_id_to_move} 从 processing_list 移动到 history_process_list。")
@@ -110,11 +110,11 @@ def arbitrage_process_flow(process_item):
 
     gas_price_multiplier = 1
     if profit > 2:
-        gas_price_multiplier = 1.2
+        gas_price_multiplier = 1.1
     elif profit > 5:
-        gas_price_multiplier = 2
+        gas_price_multiplier = 1.5
     elif profit > 10:
-        gas_price_multiplier = 3
+        gas_price_multiplier = 2
 
     ap = arbitrage_process.ArbitrageProcess(tx, 2, gas_price_multiplier, 
                                                            FROM_TOKEN, TO_TOKEN, 

+ 13 - 13
mexc_client.py

@@ -560,21 +560,21 @@ if __name__ == '__main__':
             }
             '''
 
-            # print("\n提币测试...")
-            # withdraw_params = {
-            #     'coin': 'USDT',
-            #     'netWork': 'ETH',
-            #     'address': '0xb1f33026db86a86372493a3b124d7123e9045bb4',
-            #     'amount': 10
-            # }
-            # withdraw_rst = client.wallet.post_withdraw(withdraw_params)
-            # print(f"  提笔响应:{withdraw_rst}")
+            print("\n提币测试...")
+            withdraw_params = {
+                'coin': 'USDT',
+                'netWork': 'ETH',
+                'address': '0xb1f33026db86a86372493a3b124d7123e9045bb4',
+                'amount': 700
+            }
+            withdraw_rst = client.wallet.post_withdraw(withdraw_params)
+            print(f"  提笔响应:{withdraw_rst}")
 
 
-            # print("\n获取提币历史信息...")
-            # withdraw_list = client.wallet.get_withdraw_list()
-            # print("历史信息:")
-            # print(f"  {withdraw_list}")
+            print("\n获取提币历史信息...")
+            withdraw_list = client.wallet.get_withdraw_list()
+            print("历史信息:")
+            print(f"  {withdraw_list}")
         except requests.exceptions.RequestException as e:
             print(f"  私有 API 请求期间出错: {e}")
             if e.response is not None:

+ 3 - 3
price_checker_ok.py

@@ -18,14 +18,14 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
 ARB_EXECUTOR_URL = "http://localhost:5002/submit_process"
 
 # --- 配置部分 ---
-IN_AMOUNT_TO_QUERY = decimal.Decimal('20')
-PROFIT_LIMIT = 0.02                 # 2%利润才触发交易,稳妥模式
+IN_AMOUNT_TO_QUERY = decimal.Decimal('350')
+PROFIT_LIMIT = 0.015                 # 1.5%利润才触发交易,稳妥模式
 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 = 1
+SLIPPAGE = 0.25
 MEXC_TARGET_PAIR_USDT = 'RATO_USDT' # MEXC 现货交易对
 CHAIN_ID = 1
 

+ 2 - 0
submit_process_demo.py

@@ -31,6 +31,8 @@ def create_mock_arbitrage_data():
                                 USER_EXCHANGE_WALLET,  # 这里直接把交易所地址当收款方,省去transfer的流程!!!
                                 )
 
+    print(data)
+
     d = data['data'][0]
     tx = d['tx']
     router_result = d['routerResult']