fix: preserve SOR execution venue separately
This commit is contained in:
@@ -573,6 +573,27 @@ class KISBroker:
|
||||
delta = (ordered_at - submitted_at).total_seconds()
|
||||
return -5.0 <= delta <= 120.0
|
||||
|
||||
@staticmethod
|
||||
def _execution_venue_from_row(row: dict) -> str | None:
|
||||
"""Parse broker-authoritative KRX/NXT without time inference."""
|
||||
notice_code = str(row.get("ord_exg_gb") or row.get("ORD_EXG_GB") or "").strip()
|
||||
notice_map = {"1": "KRX", "2": "NXT", "3": "KRX", "4": "NXT"}
|
||||
if notice_code in notice_map:
|
||||
return notice_map[notice_code]
|
||||
for key in (
|
||||
"excg_id_dvsn_cd",
|
||||
"excg_id_dvsn_Cd",
|
||||
"EXCG_ID_DVSN_CD",
|
||||
"execution_venue",
|
||||
):
|
||||
value = str(row.get(key) or "").strip().upper()
|
||||
if value in {"KRX", "SOR-KRX"}:
|
||||
return "KRX"
|
||||
if value in {"NXT", "SOR-NXT"}:
|
||||
return "NXT"
|
||||
# SOR is routing provenance, not an execution exchange.
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _fill_status_from_row(
|
||||
row: dict,
|
||||
@@ -581,6 +602,7 @@ class KISBroker:
|
||||
today: str,
|
||||
fallback_odno: str,
|
||||
) -> FillStatus:
|
||||
execution_venue = KISBroker._execution_venue_from_row(row)
|
||||
ord_qty = _safe_int(row.get("ord_qty")) or 0
|
||||
ccld_qty = _safe_int(row.get("tot_ccld_qty")) or 0
|
||||
rejected_qty = _safe_int(row.get("rjct_qty")) or 0
|
||||
@@ -623,6 +645,7 @@ class KISBroker:
|
||||
execution_id=execution_id,
|
||||
fee=fee,
|
||||
tax=tax,
|
||||
execution_venue=execution_venue,
|
||||
raw=row,
|
||||
)
|
||||
# 0 < ccld_qty < ord_qty
|
||||
@@ -646,6 +669,7 @@ class KISBroker:
|
||||
execution_id=execution_id,
|
||||
fee=fee,
|
||||
tax=tax,
|
||||
execution_venue=execution_venue,
|
||||
cancelled=True,
|
||||
raw=row,
|
||||
)
|
||||
@@ -653,6 +677,7 @@ class KISBroker:
|
||||
state="partially_filled",
|
||||
filled_qty=ccld_qty,
|
||||
avg_price=float(avg) if avg else None,
|
||||
execution_venue=execution_venue,
|
||||
raw=row,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user