Harden strategy SoT: fail-closed funds gate, shared open pipeline, LIVE switch guards.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -103,3 +103,24 @@ def test_reserve_perp_margin() -> None:
|
||||
|
||||
assert r["acted"] is True
|
||||
assert wallets.convert.call_args.kwargs["amount"] == 50.0
|
||||
|
||||
|
||||
def test_force_does_not_bypass_cooldown() -> None:
|
||||
import app.strategy.auto_usdc as m
|
||||
import time
|
||||
|
||||
m._last_attempt_ts = time.time()
|
||||
cap = {
|
||||
"option_need_usdc": 100.0,
|
||||
"option_have_usdc": 0.0,
|
||||
"perp_need_usdt": 10.0,
|
||||
"perp_have_usdt": 500.0,
|
||||
"option_can_open": False,
|
||||
}
|
||||
with (
|
||||
patch("app.strategy.auto_usdc._is_okx", return_value=True),
|
||||
patch("app.strategy.auto_usdc.assess_open_capacity", return_value=cap),
|
||||
):
|
||||
r = ensure_okx_trading_usdc(db=MagicMock(), cap=cap, force=True)
|
||||
assert r["acted"] is False
|
||||
assert "冷却" in r["detail"]
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
"""资金门 fail-closed 测试。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.strategy.open_capacity import funds_gate_blocks
|
||||
|
||||
|
||||
def test_funds_gate_blocks_none() -> None:
|
||||
blocked, msg = funds_gate_blocks(
|
||||
{
|
||||
"perp_can_open": True,
|
||||
"option_can_open": None,
|
||||
"perp_label": "a",
|
||||
"option_label": "b",
|
||||
}
|
||||
)
|
||||
assert blocked is True
|
||||
assert "未知" in msg or "拒绝" in msg
|
||||
|
||||
|
||||
def test_funds_gate_blocks_false() -> None:
|
||||
blocked, msg = funds_gate_blocks(
|
||||
{
|
||||
"perp_can_open": True,
|
||||
"option_can_open": False,
|
||||
"perp_label": "永续可开",
|
||||
"option_label": "期权不可开",
|
||||
"perp_need_usdt": 1,
|
||||
"perp_have_usdt": 10,
|
||||
"option_need_usdc": 100,
|
||||
"option_have_usdc": 1,
|
||||
}
|
||||
)
|
||||
assert blocked is True
|
||||
assert "不可开" in msg or "不足" in msg
|
||||
|
||||
|
||||
def test_funds_gate_ok_only_when_both_true() -> None:
|
||||
blocked, _ = funds_gate_blocks(
|
||||
{
|
||||
"perp_can_open": True,
|
||||
"option_can_open": True,
|
||||
"perp_label": "永续可开",
|
||||
"option_label": "期权可开",
|
||||
}
|
||||
)
|
||||
assert blocked is False
|
||||
Reference in New Issue
Block a user