feat: resolve and persist actual order venue
This commit is contained in:
@@ -185,13 +185,22 @@ class InMemorySlotRepository:
|
||||
]
|
||||
return out[:limit]
|
||||
|
||||
def mark_dispatched(self, slot_id: UUID, broker_order_id: str) -> bool:
|
||||
"""Atomically set broker_order_id iff still undispatched (idempotency guard)."""
|
||||
def mark_dispatched(
|
||||
self,
|
||||
slot_id: UUID,
|
||||
broker_order_id: str,
|
||||
*,
|
||||
venue: Optional[str] = None,
|
||||
) -> bool:
|
||||
"""Atomically persist dispatch identity and the actual broker venue."""
|
||||
s = self._slots.get(slot_id)
|
||||
if s is None or s.broker_order_id is not None:
|
||||
return False
|
||||
self._slots[slot_id] = replace(
|
||||
s, broker_order_id=broker_order_id, updated_at=datetime.now(tz=timezone.utc)
|
||||
s,
|
||||
broker_order_id=broker_order_id,
|
||||
venue=venue if venue is not None else s.venue,
|
||||
updated_at=datetime.now(tz=timezone.utc),
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
@@ -215,10 +215,15 @@ class SlotService:
|
||||
new_limit_price = limit_price if limit_price is not None else slot.limit_price
|
||||
new_timeout_sec = timeout_sec if timeout_sec is not None else slot.timeout_sec
|
||||
new_slippage_pct = slippage_pct if slippage_pct is not None else slot.slippage_pct
|
||||
new_venue = venue if venue is not None else slot.venue
|
||||
else: # HOLDING / ERROR — pending order policy no longer applies.
|
||||
new_limit_price = None
|
||||
new_timeout_sec = None
|
||||
new_slippage_pct = None
|
||||
# A completed order's venue must not leak into a later autonomous
|
||||
# sell. The next order starts session-aware unless its intent
|
||||
# explicitly chooses KRX/NXT/SOR.
|
||||
new_venue = "AUTO" if to_state is SlotState.HOLDING else slot.venue
|
||||
|
||||
# occupancy_seq (dcy-028/REQ-081): bump when a slot begins a new
|
||||
# occupancy (inactive→pending_buy). Stable across the rest of the
|
||||
@@ -271,7 +276,7 @@ class SlotService:
|
||||
timeout_sec=new_timeout_sec,
|
||||
slippage_pct=new_slippage_pct,
|
||||
occupancy_seq=new_occupancy_seq,
|
||||
venue=venue if venue is not None else slot.venue,
|
||||
venue=new_venue,
|
||||
updated_at=datetime.now(tz=timezone.utc),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user