Hide manual trade by default, block open while running, auto-refresh auth token.

Also fix flat-side reconcile to check both long and short residuals; document in 更新说明.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-26 22:43:38 +08:00
parent 0cf3756b09
commit 16efa44ffb
13 changed files with 304 additions and 38 deletions
+12 -5
View File
@@ -76,12 +76,19 @@ def assert_safe_to_open_live(executor) -> tuple[bool, str]:
return False, "无法核对交易所持仓"
perp_inst = resolve_perp_inst_id(executor.db)
perp_side = str(pos.get("perp_side") or "long")
ex_sz = exchange_perp_abs_size(client, ex_name or "", perp_inst, perp_side)
if ex_sz is None:
return False, "无法核对交易所持仓"
# flat/opening:两侧都查,避免只查默认 long 漏掉 short 残留
if st in ("flat", "", "opening"):
sides = ("long", "short")
else:
sides = (str(pos.get("perp_side") or "long"),)
total = 0.0
for side in sides:
ex_sz = exchange_perp_abs_size(client, ex_name or "", perp_inst, side)
if ex_sz is None:
return False, "无法核对交易所持仓"
total += float(ex_sz)
if ex_sz > _PERP_EPS and st in ("flat", "", "opening"):
if total > _PERP_EPS and st in ("flat", "", "opening"):
return (
False,
"交易所有永续仓但本地无持仓,禁止新开,请人工核对",