chore: gate-only force-close policy and deploy pull script
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -50,12 +50,26 @@ SHARED_DEFAULTS: dict[str, str] = {
|
||||
"RECONCILE_STARTUP_GRACE_SEC": "90",
|
||||
"RECONCILE_FLAT_CONFIRM_POLLS": "3",
|
||||
"FULL_MARGIN_BUFFER_RATIO": "0.98",
|
||||
"FORCE_CLOSE_BJ_HOUR": "0",
|
||||
"FORCE_CLOSE_ENABLED": "false",
|
||||
"WECHAT_TIMEOUT_SECONDS": "10",
|
||||
"AI_TIMEOUT_SECONDS": "120",
|
||||
}
|
||||
|
||||
# 仅 Gate 启用 0 点强制清仓;币安/OKX 须保持关闭
|
||||
FORCE_CLOSE_POLICY: dict[str, dict[str, str]] = {
|
||||
"crypto_monitor_gate": {
|
||||
"FORCE_CLOSE_ENABLED": "true",
|
||||
"FORCE_CLOSE_BJ_HOUR": "0",
|
||||
},
|
||||
"crypto_monitor_binance": {
|
||||
"FORCE_CLOSE_ENABLED": "false",
|
||||
"FORCE_CLOSE_BJ_HOUR": "0",
|
||||
},
|
||||
"crypto_monitor_okx": {
|
||||
"FORCE_CLOSE_ENABLED": "false",
|
||||
"FORCE_CLOSE_BJ_HOUR": "0",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _parse_env(path: str) -> list[str]:
|
||||
if not os.path.isfile(path):
|
||||
@@ -116,10 +130,44 @@ def sync_one(dir_name: str, *, dry_run: bool, force: bool) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def apply_force_close_policy(*, dry_run: bool) -> bool:
|
||||
"""Gate 开启强制清仓;币安/OKX 强制关闭(覆盖已有值)。"""
|
||||
any_changed = False
|
||||
for dir_name, values in FORCE_CLOSE_POLICY.items():
|
||||
path = os.path.join(REPO, dir_name, ".env")
|
||||
if not os.path.isfile(path):
|
||||
print(f"skip (no .env): {dir_name}")
|
||||
continue
|
||||
lines = _parse_env(path)
|
||||
changed_keys: list[str] = []
|
||||
for key, val in values.items():
|
||||
cur = _env_get(lines, key)
|
||||
if cur != val:
|
||||
lines = _upsert(lines, key, val)
|
||||
changed_keys.append(key)
|
||||
if not changed_keys:
|
||||
print(f"ok (force-close policy): {dir_name}")
|
||||
continue
|
||||
any_changed = True
|
||||
print(f"force-close policy: {dir_name}")
|
||||
for key in changed_keys:
|
||||
print(f" = {key}={values[key]}")
|
||||
if not dry_run:
|
||||
text = "\n".join(lines).rstrip() + "\n"
|
||||
with open(path, "w", encoding="utf-8", newline="\n") as f:
|
||||
f.write(text)
|
||||
return any_changed
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser(description="同步币安/OKX 共用 trading env(缺失项追加)")
|
||||
ap.add_argument("--dry-run", action="store_true")
|
||||
ap.add_argument("--force", action="store_true", help="覆盖已有值(慎用)")
|
||||
ap.add_argument(
|
||||
"--apply-force-close-policy",
|
||||
action="store_true",
|
||||
help="Gate 开启 0 点强制清仓,币安/OKX 强制关闭",
|
||||
)
|
||||
ap.add_argument(
|
||||
"--instances",
|
||||
nargs="+",
|
||||
@@ -133,6 +181,9 @@ def main() -> None:
|
||||
for inst in instances:
|
||||
if sync_one(inst, dry_run=args.dry_run, force=args.force):
|
||||
any_changed = True
|
||||
if args.apply_force_close_policy:
|
||||
if apply_force_close_policy(dry_run=args.dry_run):
|
||||
any_changed = True
|
||||
if args.dry_run and any_changed:
|
||||
print("(dry-run, 未写入)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user