fix(gate): align fund transfer between gate and gate_bot

- Extract shared gate_transfer_lib and global transfer form on all pages

- Block auto-transfer when trend pullback plans have open positions

- Redirect manual transfer back to the current page after submit

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-07 10:01:32 +08:00
parent bee9539852
commit 67cc084347
8 changed files with 159 additions and 73 deletions
+20 -19
View File
@@ -2610,23 +2610,17 @@ def get_exchange_capitals(force=False):
def execute_transfer_usdt(amount, from_account, to_account):
if amount <= 0:
return False, "划转金额必须大于0", None
ok_live, reason = ensure_exchange_live_ready()
if not ok_live:
return False, reason, None
try:
resp = exchange.transfer(TRANSFER_CCY, float(amount), from_account, to_account)
return True, "划转成功", resp
except Exception as e:
msg = str(e)
if "INVALID_KEY" in msg or "Invalid key" in msg:
msg += (
"。常见原因:① GATE_API_SECRET 错误或 .env 里多了空格/换行;② IP 白名单未包含当前服务器出口 IP;"
"③ Gate「交易账户」类 API Key 若不支持钱包接口则无法走账户内划转 POST /wallet/transfers(需在官网确认该 Key 类型是否开放划转);"
"④ Key 已重置或权限变更。你已勾选现货/统一账户仍报错时,优先核对 Secret 与白名单。"
)
return False, msg, None
from gate_transfer_lib import execute_transfer_usdt as _gate_execute_transfer_usdt
return _gate_execute_transfer_usdt(
exchange,
amount,
from_account,
to_account,
transfer_ccy=TRANSFER_CCY,
ensure_live_ready=ensure_exchange_live_ready,
ensure_markets_loaded=ensure_markets_loaded,
)
def get_account_usdt_total(account_type):
@@ -2648,6 +2642,12 @@ def get_account_usdt_total(account_type):
return None
def _auto_transfer_active_count(conn):
from gate_transfer_lib import count_auto_transfer_blockers
return count_auto_transfer_blockers(conn, count_order_monitors=get_active_position_count)
def auto_transfer_once_per_day():
run_auto_transfer_once_per_day(
enabled=AUTO_TRANSFER_ENABLED,
@@ -2657,7 +2657,7 @@ def auto_transfer_once_per_day():
to_account=AUTO_TRANSFER_TO,
funds_decimals=2,
get_db=get_db,
get_active_position_count=get_active_position_count,
get_active_position_count=_auto_transfer_active_count,
get_account_usdt_total=get_account_usdt_total,
execute_transfer_usdt=execute_transfer_usdt,
send_wechat_msg=send_wechat_msg,
@@ -5697,6 +5697,7 @@ def render_main_page(page="trade"):
auto_transfer_from=AUTO_TRANSFER_FROM,
auto_transfer_to=AUTO_TRANSFER_TO,
auto_transfer_bj_hour=AUTO_TRANSFER_BJ_HOUR,
transfer_amount_fmt=format_money_usdt(AUTO_TRANSFER_AMOUNT),
full_margin_buffer_ratio=FULL_MARGIN_BUFFER_RATIO,
price_refresh_seconds=PRICE_REFRESH_SECONDS,
active_count=active_count,
@@ -8020,7 +8021,7 @@ def manual_transfer():
flash(f"手动划转成功:{amount}U {from_account}->{to_account}")
else:
flash(f"手动划转失败:{msg}")
return redirect("/")
return redirect(request.referrer or "/trade")
def _journal_ai_chart_builder(row):