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