Browse Source

區分策略

skyfffire 5 months ago
parent
commit
9ae8dc9520
5 changed files with 39 additions and 34 deletions
  1. 4 2
      as.py
  2. 27 0
      as_utils.py
  3. 5 29
      erc20_to_mexc_first_sell.py
  4. 1 1
      mexc_client.py
  5. 2 2
      signal001/submit_process_demo.py

+ 4 - 2
as.py

@@ -15,6 +15,8 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
 from flask import Flask, request, jsonify
 from flask_cors import CORS # 导入
 from web3_py_client import EthClient # 你特定的客户端
+from as_utils import get_formatted_timestamp
+from as_utils import add_state_flow_entry
 
 
 web3 = EthClient() 
@@ -175,7 +177,7 @@ def handle_submit_process():
         process_id = str(uuid.uuid4()) # 生成唯一流程ID
         process_item = {
             "id": process_id,
-            "creationTime": arbitrage_process.get_formatted_timestamp(), # 创建时间
+            "creationTime": get_formatted_timestamp(), # 创建时间
             "tx": data['tx'], # 交易详情,应包含 rawTransaction
             "profit": str(profit), # 利润 (字符串存储)
             "profitLimit": str(profit_limit), # 利润阈值 (字符串存储)
@@ -192,7 +194,7 @@ def handle_submit_process():
             "currentState": "PENDING_START", # 当前状态
         }
         # 初始状态更新
-        arbitrage_process.add_state_flow_entry(process_item, "RECEIVED", f"流程已接收。利润 {profit} >= 利润阈值 {profit_limit}。开始套利。", "success")
+        add_state_flow_entry(process_item, "RECEIVED", f"流程已接收。利润 {profit} >= 利润阈值 {profit_limit}。开始套利。", "success")
 
         with list_lock:
             processing_list.append(process_item)

+ 27 - 0
as_utils.py

@@ -0,0 +1,27 @@
+import datetime
+
+def get_formatted_timestamp():
+    """
+    获取指定格式的时间戳: YYYY-MM-DD HH:MM:SS,ms
+    例如: 2025-05-16 14:44:09,324
+    """
+    now = datetime.datetime.now()
+    # 格式化日期和时间部分
+    timestamp_str = now.strftime("%Y-%m-%d %H:%M:%S")
+    # 获取毫秒部分,并格式化为3位数字
+    milliseconds = now.microsecond // 1000
+    milliseconds_str = f"{milliseconds:03d}"
+    # 组合最终格式
+    return f"{timestamp_str},{milliseconds_str}"
+
+def add_state_flow_entry(process_item, state_name, msg, status_val="pending"):
+    """辅助函数,用于向 stateFlow 列表添加条目。"""
+    entry = {
+        "stateName": state_name, # 状态名称
+        "timestamp": get_formatted_timestamp(), # 时间戳
+        "msg": msg, # 消息
+        "status": status_val # 状态值: "pending", "success", "fail", "skipped"
+    }
+    process_item["stateFlow"].append(entry)
+    process_item["currentState"] = state_name # 更新整体状态
+    # logging.info(f"[流程 {process_item.get('id', 'N/A')}][{state_name}]: {msg} (状态: {status_val})")

+ 5 - 29
erc20_to_mexc_first_sell.py

@@ -1,9 +1,9 @@
 import time
 import logging
-import datetime
 from web3_py_client import EthClient
 from mexc_client import MexcClient
 from decimal import Decimal, ROUND_DOWN
+from as_utils import add_state_flow_entry
 
 web3 = EthClient()
 mexc = MexcClient()
@@ -11,33 +11,6 @@ mexc = MexcClient()
 # 配置日志
 logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
-
-def get_formatted_timestamp():
-    """
-    获取指定格式的时间戳: YYYY-MM-DD HH:MM:SS,ms
-    例如: 2025-05-16 14:44:09,324
-    """
-    now = datetime.datetime.now()
-    # 格式化日期和时间部分
-    timestamp_str = now.strftime("%Y-%m-%d %H:%M:%S")
-    # 获取毫秒部分,并格式化为3位数字
-    milliseconds = now.microsecond // 1000
-    milliseconds_str = f"{milliseconds:03d}"
-    # 组合最终格式
-    return f"{timestamp_str},{milliseconds_str}"
-
-def add_state_flow_entry(process_item, state_name, msg, status_val="pending"):
-    """辅助函数,用于向 stateFlow 列表添加条目。"""
-    entry = {
-        "stateName": state_name, # 状态名称
-        "timestamp": get_formatted_timestamp(), # 时间戳
-        "msg": msg, # 消息
-        "status": status_val # 状态值: "pending", "success", "fail", "skipped"
-    }
-    process_item["stateFlow"].append(entry)
-    process_item["currentState"] = state_name # 更新整体状态
-    # logging.info(f"[流程 {process_item.get('id', 'N/A')}][{state_name}]: {msg} (状态: {status_val})")
-
 class ArbitrageProcess:
     def __init__(self, tx, gas_limit_multiplier, gas_price_multiplier, 
                  from_token, to_token, 
@@ -591,9 +564,12 @@ class ArbitrageProcess:
                     for balance in balances:
                         if balance['asset'] == self.coin:
                             asset_balance = Decimal(balance['free'])
+
+                    # 交易所賣出餘額
+                    exchange_out_amount = self.arbitrage_details["exchange_out_amount"]
                     
                     # 最終判斷
-                    if asset_balance > pending_amount:
+                    if exchange_out_amount + asset_balance > pending_amount:
                         msg = f"【flash】资产可以進行快速提現。{last_deposit_state}"
                         logging.info(msg)
                         add_state_flow_entry(self.process_item, self.current_state, msg, "success")

+ 1 - 1
mexc_client.py

@@ -594,7 +594,7 @@ if __name__ == '__main__':
             #     # "endTime":"1747274400000"
             # }
             # deposit_list = client.wallet.get_deposit_list(params)
-            # for deposit in deposit_list[0:10]:
+            # for deposit in deposit_list[0:5]:
             #     print(f"  {deposit}")
         except requests.exceptions.RequestException as e:
             print(f"  私有 API 请求期间出错: {e}")

+ 2 - 2
signal001/submit_process_demo.py

@@ -19,8 +19,8 @@ def create_mock_arbitrage_data():
     CHAIN_ID = 1
     IN_TOKEN_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7' # USDT on Ethereum
     IN_TOKEN_DECIMALS = 6
-    EXCHANGE_OUT_AMOUNT = Decimal('200000000')
-    IN_AMOUNT_TO_QUERY = Decimal('300s')
+    EXCHANGE_OUT_AMOUNT = Decimal('2640000')
+    IN_AMOUNT_TO_QUERY = Decimal('42')
     OUT_TOKEN_ADDRESS = '0xf816507E690f5Aa4E29d164885EB5fa7a5627860' # RATO on Ethereum
     USER_WALLET = '0xb1f33026Db86a86372493a3B124d7123e9045Bb4'
     USER_EXCHANGE_WALLET = '0xc71835a042F4d870B0F4296cc89cAeb921a9f3DA'