fix(execution): fail closed on unresolved orders
This commit is contained in:
@@ -376,6 +376,14 @@ class KISBroker:
|
||||
) -> FillStatus:
|
||||
if broker_order_id.startswith(_SUBMISSION_UNKNOWN_PREFIX):
|
||||
return self._poll_unknown_submission(broker_order_id, side=side, symbol=symbol)
|
||||
if order_date is None:
|
||||
# A legacy pending row has no authoritative date anchor. ODNO is
|
||||
# reusable, so querying today's rows could attach another order's
|
||||
# terminal evidence to this slot. Never invent an inquiry date.
|
||||
return FillStatus(
|
||||
state="unknown",
|
||||
raw={"reason": "order_reconciliation_metadata_unknown"},
|
||||
)
|
||||
now = monotonic()
|
||||
if now < self._fill_poll_not_before.get(broker_order_id, 0.0):
|
||||
return FillStatus(
|
||||
@@ -386,7 +394,7 @@ class KISBroker:
|
||||
# open duplicate KIS inquiries for the same order.
|
||||
self._fill_poll_not_before[broker_order_id] = now + _FILL_POLL_MIN_INTERVAL_SECONDS
|
||||
odno = broker_order_id.split(":")[-1]
|
||||
inquiry_date = order_date or self._clock().astimezone(_KST).strftime("%Y%m%d")
|
||||
inquiry_date = order_date
|
||||
tr_id, params = self._daily_fill_request(inquiry_date, order_number=odno)
|
||||
try:
|
||||
resp = httpx.get(
|
||||
|
||||
@@ -270,6 +270,14 @@ class ExecutionService:
|
||||
for slot in self._repo.list_dispatched_pending(self._instance_key):
|
||||
side = "buy" if slot.status is SlotState.PENDING_BUY else "sell"
|
||||
set_correlation_id(str(slot.slot_id)) # REQ-084: same key as submit
|
||||
if not str(slot.broker_order_id or "").startswith("submission-unknown:") and (
|
||||
slot.order_submitted_at is None or slot.order_date is None
|
||||
):
|
||||
# Legacy rows cannot be tied safely to an authoritative KIS
|
||||
# inquiry date. Do not poll: a reused ODNO on today's date
|
||||
# could otherwise drive a false terminal transition.
|
||||
self._emit_order_metadata_unknown_alarm(slot)
|
||||
continue
|
||||
fs = self._poll_fill(slot, side)
|
||||
resolved_order_id = (
|
||||
fs.raw.get("resolved_broker_order_id") if isinstance(fs.raw, dict) else None
|
||||
@@ -589,6 +597,11 @@ class ExecutionService:
|
||||
CancelState.REJECTED.value,
|
||||
CancelState.UNKNOWN.value,
|
||||
}
|
||||
if slot.cancel_state == CancelState.REQUESTED.value:
|
||||
reason = fs.raw.get("reason") if isinstance(fs.raw, dict) else None
|
||||
if fs.state == "unknown" or reason == "order_not_visible_unresolved":
|
||||
self._emit_unresolved_cancel_alarm(slot)
|
||||
return
|
||||
if slot.cancel_state is not None and not is_retry:
|
||||
return
|
||||
if is_retry:
|
||||
|
||||
Reference in New Issue
Block a user