feat: revalidate blackout recovery orders by price/session context (#328)
This commit is contained in:
@@ -6340,6 +6340,7 @@ async def test_process_blackout_recovery_executes_valid_intents() -> None:
|
||||
"""Recovery must execute queued intents that pass revalidation."""
|
||||
db_conn = init_db(":memory:")
|
||||
broker = MagicMock()
|
||||
broker.get_current_price = AsyncMock(return_value=(100.0, 0.0, 0.0))
|
||||
broker.send_order = AsyncMock(return_value={"rt_cd": "0", "msg1": "OK"})
|
||||
overseas_broker = MagicMock()
|
||||
|
||||
@@ -6394,6 +6395,7 @@ async def test_process_blackout_recovery_drops_policy_rejected_intent() -> None:
|
||||
"""Policy-rejected queued intents must not be requeued."""
|
||||
db_conn = init_db(":memory:")
|
||||
broker = MagicMock()
|
||||
broker.get_current_price = AsyncMock(return_value=(100.0, 0.0, 0.0))
|
||||
broker.send_order = AsyncMock(return_value={"rt_cd": "0", "msg1": "OK"})
|
||||
overseas_broker = MagicMock()
|
||||
|
||||
@@ -6437,6 +6439,55 @@ async def test_process_blackout_recovery_drops_policy_rejected_intent() -> None:
|
||||
blackout_manager.requeue.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_blackout_recovery_drops_intent_on_excessive_price_drift() -> None:
|
||||
"""Queued intent is dropped when current market price drift exceeds threshold."""
|
||||
db_conn = init_db(":memory:")
|
||||
broker = MagicMock()
|
||||
broker.get_current_price = AsyncMock(return_value=(106.0, 0.0, 0.0))
|
||||
broker.send_order = AsyncMock(return_value={"rt_cd": "0", "msg1": "OK"})
|
||||
overseas_broker = MagicMock()
|
||||
|
||||
market = MagicMock()
|
||||
market.code = "KR"
|
||||
market.exchange_code = "KRX"
|
||||
market.is_domestic = True
|
||||
|
||||
intent = MagicMock()
|
||||
intent.market_code = "KR"
|
||||
intent.stock_code = "005930"
|
||||
intent.order_type = "BUY"
|
||||
intent.quantity = 1
|
||||
intent.price = 100.0
|
||||
intent.source = "test"
|
||||
intent.attempts = 0
|
||||
|
||||
blackout_manager = MagicMock()
|
||||
blackout_manager.pop_recovery_batch.return_value = [intent]
|
||||
|
||||
with (
|
||||
patch("src.main.BLACKOUT_ORDER_MANAGER", blackout_manager),
|
||||
patch("src.main.MARKETS", {"KR": market}),
|
||||
patch("src.main.get_open_position", return_value=None),
|
||||
patch("src.main.validate_order_policy") as validate_policy,
|
||||
):
|
||||
await process_blackout_recovery_orders(
|
||||
broker=broker,
|
||||
overseas_broker=overseas_broker,
|
||||
db_conn=db_conn,
|
||||
settings=Settings(
|
||||
KIS_APP_KEY="k",
|
||||
KIS_APP_SECRET="s",
|
||||
KIS_ACCOUNT_NO="12345678-01",
|
||||
GEMINI_API_KEY="g",
|
||||
BLACKOUT_RECOVERY_MAX_PRICE_DRIFT_PCT=5.0,
|
||||
),
|
||||
)
|
||||
|
||||
broker.send_order.assert_not_called()
|
||||
validate_policy.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_trigger_emergency_kill_switch_executes_operational_steps() -> None:
|
||||
"""Emergency kill switch should execute cancel/refresh/reduce/notify callbacks."""
|
||||
|
||||
Reference in New Issue
Block a user