feat: show max-hold session countdown
This commit is contained in:
@@ -56,6 +56,72 @@ async def test_create_and_list_open(session):
|
||||
assert row["symbol"] == "AAA"
|
||||
assert row["status"] == "open"
|
||||
assert row["current_price"] == 110.0 # marked to the latest close
|
||||
assert row["sessions_held"] == 0
|
||||
assert row["sessions_remaining"] == 30
|
||||
|
||||
|
||||
async def test_list_open_counts_post_entry_sessions_for_max_hold(session):
|
||||
await svc.set_exit_policy(session, mode="atr_trailing", hold_days=5)
|
||||
ticker_id = await _seed(session, "COUNT", close=110.0)
|
||||
trade = await svc.create_trade(
|
||||
session,
|
||||
1,
|
||||
symbol="COUNT",
|
||||
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]
|
||||
# Two added bars plus today's seeded bar; skipped calendar dates do not count.
|
||||
assert row["sessions_held"] == 3
|
||||
assert row["sessions_remaining"] == 2
|
||||
|
||||
|
||||
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)
|
||||
await svc.create_trade(
|
||||
session,
|
||||
1,
|
||||
symbol="NOHOLD",
|
||||
direction="long",
|
||||
entry_price=100.0,
|
||||
shares=10,
|
||||
stop_loss=95.0,
|
||||
target=120.0,
|
||||
)
|
||||
|
||||
row = (await svc.list_trades(session, 1, status="open"))[0]
|
||||
assert row["sessions_held"] is None
|
||||
assert row["sessions_remaining"] is None
|
||||
|
||||
|
||||
async def test_create_trade_enforces_post_stop_gate_reset_at_service_boundary(session):
|
||||
|
||||
Reference in New Issue
Block a user