fix: harden post-stop reentry lockdown
This commit is contained in:
@@ -20,6 +20,7 @@ from hypothesis import given, settings, HealthCheck, strategies as st
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.benchmark_price import BenchmarkPrice
|
||||
from app.models.ohlcv import OHLCVRecord
|
||||
from app.models.paper_trade import PaperTrade
|
||||
from app.models.signal_context_snapshot import SignalContextSnapshot
|
||||
@@ -625,21 +626,37 @@ async def test_get_trade_setups_applies_five_session_initial_stop_lockdown(
|
||||
db_session.add_all([blocked, released, trailing])
|
||||
await db_session.flush()
|
||||
|
||||
# Six synthetic stored market sessions D0..D5. A stop on D0 has five
|
||||
# later sessions and is released; a stop on D1 has only four and is not.
|
||||
market_sessions = [today - timedelta(days=offset) for offset in range(5, -1, -1)]
|
||||
# Six SPY sessions D0..D5 form the canonical market calendar. A stop on
|
||||
# D0 has five later sessions and is released; a stop on D1 has only four.
|
||||
market_sessions = [
|
||||
today - timedelta(days=8),
|
||||
today - timedelta(days=7),
|
||||
today - timedelta(days=6),
|
||||
today - timedelta(days=3),
|
||||
today - timedelta(days=2),
|
||||
today - timedelta(days=1),
|
||||
]
|
||||
for market_date in market_sessions:
|
||||
db_session.add(
|
||||
OHLCVRecord(
|
||||
ticker_id=blocked.id,
|
||||
BenchmarkPrice(
|
||||
symbol="SPY",
|
||||
date=market_date,
|
||||
open=100.0,
|
||||
high=101.0,
|
||||
low=99.0,
|
||||
close=100.0,
|
||||
volume=1_000,
|
||||
close=400.0,
|
||||
)
|
||||
)
|
||||
# A bar from an unrelated/scanner-specific calendar must not release the
|
||||
# ticker one session early. The old universe-wide DISTINCT query did.
|
||||
db_session.add(
|
||||
OHLCVRecord(
|
||||
ticker_id=blocked.id,
|
||||
date=today,
|
||||
open=100.0,
|
||||
high=101.0,
|
||||
low=99.0,
|
||||
close=100.0,
|
||||
volume=1_000,
|
||||
)
|
||||
)
|
||||
|
||||
for ticker in (blocked, released, trailing):
|
||||
db_session.add(
|
||||
@@ -699,6 +716,14 @@ async def test_get_trade_setups_applies_five_session_initial_stop_lockdown(
|
||||
assert "STOP4" not in available_symbols
|
||||
assert {"STOP5", "TRAILQ"}.issubset(available_symbols)
|
||||
|
||||
annotated = await get_trade_setups(
|
||||
db_session,
|
||||
symbol="STOP4",
|
||||
include_reentry_lockdown=True,
|
||||
)
|
||||
assert len(annotated) == 1
|
||||
assert annotated[0]["reentry_lockdown_remaining_sessions"] == 1
|
||||
|
||||
|
||||
async def _seed_stale_setup_with_current_scores(db_session: AsyncSession) -> TradeSetup:
|
||||
"""Stored setup frozen at scan time (conf 82, neutral) vs. current context
|
||||
|
||||
Reference in New Issue
Block a user