fix: tighten max-hold session countdown

This commit is contained in:
2026-08-04 08:07:10 +02:00
parent 4c0c0579f5
commit e0f3d43efb
3 changed files with 76 additions and 20 deletions
+44
View File
@@ -105,6 +105,50 @@ async def test_list_open_counts_post_entry_sessions_for_max_hold(session):
assert row["sessions_remaining"] == 2
async def test_list_open_exposes_past_max_hold_after_policy_is_shortened(session):
await svc.set_exit_policy(session, mode="time", hold_days=2)
ticker_id = await _seed(session, "OVERDUE", close=110.0)
trade = await svc.create_trade(
session,
1,
symbol="OVERDUE",
direction="long",
entry_price=100.0,
shares=10,
stop_loss=95.0,
target=120.0,
)
today = _today()
trade.opened_at = datetime.combine(
today - timedelta(days=5), datetime.min.time(), tzinfo=timezone.utc
)
session.add_all([
OHLCVRecord(
ticker_id=ticker_id,
date=today - timedelta(days=4),
open=101,
high=102,
low=100,
close=101,
volume=1,
),
OHLCVRecord(
ticker_id=ticker_id,
date=today - timedelta(days=2),
open=102,
high=103,
low=101,
close=102,
volume=1,
),
])
await session.commit()
row = (await svc.list_trades(session, 1, status="open"))[0]
assert row["sessions_held"] == 3
assert row["sessions_remaining"] == -1
async def test_list_open_omits_countdown_without_max_hold_policy(session):
await svc.set_exit_policy(session, mode="trailing")
await _seed(session, "NOHOLD", close=110.0)