blackout: enforce bounded oldest-drop queue policy on overflow (#371) #384
15
src/main.py
15
src/main.py
@@ -1031,19 +1031,10 @@ def _maybe_queue_order_intent(
|
|||||||
price: float,
|
price: float,
|
||||||
source: str,
|
source: str,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
def _coerce_nonnegative_int(value: Any) -> int:
|
|
||||||
try:
|
|
||||||
parsed = int(value)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
return 0
|
|
||||||
return max(0, parsed)
|
|
||||||
|
|
||||||
if not BLACKOUT_ORDER_MANAGER.in_blackout():
|
if not BLACKOUT_ORDER_MANAGER.in_blackout():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
before_overflow_drops = _coerce_nonnegative_int(
|
before_overflow_drops = BLACKOUT_ORDER_MANAGER.overflow_drop_count
|
||||||
getattr(BLACKOUT_ORDER_MANAGER, "overflow_drop_count", 0)
|
|
||||||
)
|
|
||||||
queued = BLACKOUT_ORDER_MANAGER.enqueue(
|
queued = BLACKOUT_ORDER_MANAGER.enqueue(
|
||||||
_build_queued_order_intent(
|
_build_queued_order_intent(
|
||||||
market=market,
|
market=market,
|
||||||
@@ -1055,9 +1046,7 @@ def _maybe_queue_order_intent(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
if queued:
|
if queued:
|
||||||
after_overflow_drops = _coerce_nonnegative_int(
|
after_overflow_drops = BLACKOUT_ORDER_MANAGER.overflow_drop_count
|
||||||
getattr(BLACKOUT_ORDER_MANAGER, "overflow_drop_count", 0)
|
|
||||||
)
|
|
||||||
logger.warning(
|
logger.warning(
|
||||||
(
|
(
|
||||||
"Blackout active: queued order intent %s %s (%s) "
|
"Blackout active: queued order intent %s %s (%s) "
|
||||||
|
|||||||
@@ -6502,6 +6502,7 @@ async def test_blackout_queues_order_and_skips_submission() -> None:
|
|||||||
blackout_manager.in_blackout.return_value = True
|
blackout_manager.in_blackout.return_value = True
|
||||||
blackout_manager.enqueue.return_value = True
|
blackout_manager.enqueue.return_value = True
|
||||||
blackout_manager.pending_count = 1
|
blackout_manager.pending_count = 1
|
||||||
|
blackout_manager.overflow_drop_count = 0
|
||||||
|
|
||||||
with patch("src.main.BLACKOUT_ORDER_MANAGER", blackout_manager):
|
with patch("src.main.BLACKOUT_ORDER_MANAGER", blackout_manager):
|
||||||
await trading_cycle(
|
await trading_cycle(
|
||||||
|
|||||||
Reference in New Issue
Block a user