Add 永期半自动: human arm, machine open/close, then stop.

Settings toggle, Plan panel, Fleet monitor, exit locks and armed TOCTOU gates; docs and dual audits.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-08 11:20:11 +08:00
parent bf3441537e
commit 4585dba3c3
22 changed files with 1147 additions and 44 deletions
+75
View File
@@ -0,0 +1,75 @@
"""半自动出场与参数。"""
from __future__ import annotations
from app.strategy.semi_auto import REASON_PERP_NET, REASON_POINTS, check_semi_exits
def test_semi_points_long_needs_net_positive() -> None:
# 到点但净利≤0 → 不平
d = check_semi_exits(
net_pnl=-1.0,
entry_index=1800,
index_px=1850,
view_side="long",
option_move_points=50,
perp_exit_unit=5,
risk_k=1,
)
assert d.should_close is False
assert "净利≤0" in d.detail
d2 = check_semi_exits(
net_pnl=1.0,
entry_index=1800,
index_px=1850,
view_side="long",
option_move_points=50,
perp_exit_unit=5,
risk_k=1,
)
assert d2.should_close is True
assert d2.reason == REASON_POINTS
def test_semi_points_short() -> None:
d = check_semi_exits(
net_pnl=2.0,
entry_index=1800,
index_px=1750,
view_side="short",
option_move_points=50,
perp_exit_unit=5,
risk_k=1,
)
assert d.should_close is True
assert d.reason == REASON_POINTS
def test_semi_net_exit_with_k() -> None:
# 未到点,但净利 ≥ 5×2=10
d = check_semi_exits(
net_pnl=10.0,
entry_index=1800,
index_px=1810,
view_side="long",
option_move_points=50,
perp_exit_unit=5,
risk_k=2,
)
assert d.should_close is True
assert d.reason == REASON_PERP_NET
assert d.net_target == 10.0
def test_semi_not_yet() -> None:
d = check_semi_exits(
net_pnl=3.0,
entry_index=1800,
index_px=1820,
view_side="long",
option_move_points=50,
perp_exit_unit=5,
risk_k=1,
)
assert d.should_close is False