4585dba3c3
Settings toggle, Plan panel, Fleet monitor, exit locks and armed TOCTOU gates; docs and dual audits. Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
1.7 KiB
Python
76 lines
1.7 KiB
Python
"""半自动出场与参数。"""
|
||
|
||
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
|