fix: reconcile ambiguous KIS order submissions

This commit is contained in:
jordan
2026-07-28 11:17:06 +09:00
parent b72bf9f394
commit 24c42d1c92
11 changed files with 1420 additions and 191 deletions
+18 -6
View File
@@ -4,6 +4,7 @@ inquire-daily-ccld marks a cancelled order with cncl_yn="Y". These tests stub
the HTTP layer (token pre-seeded, httpx.get faked) and assert the FillStatus
mapping for full cancel / partial-fill-then-cancel / not-cancelled.
"""
from __future__ import annotations
from datetime import datetime, timedelta, timezone
@@ -17,7 +18,8 @@ ODNO = "0000123456"
def _broker():
b = KISBroker(
"12345678-01",
app_key="k", app_secret="s",
app_key="k",
app_secret="s",
base_url="https://openapivts.koreainvestment.com:29443", # mock endpoint
)
b._token = "tok"
@@ -36,14 +38,22 @@ class _Resp:
def _fake_get(payload):
def _get(*a, **k):
return _Resp(payload)
return _get
def _row(**kw):
base = {"odno": ODNO, "ord_qty": "10", "tot_ccld_qty": "0",
"avg_prvs": "0", "cncl_yn": "N", "ord_dt": "20260608", "ord_gno_brno": "06010"}
base = {
"odno": ODNO,
"ord_qty": "10",
"tot_ccld_qty": "0",
"avg_prvs": "0",
"cncl_yn": "N",
"ord_dt": "20260608",
"ord_gno_brno": "06010",
}
base.update(kw)
return {"output1": [base]}
return {"rt_cd": "0", "output1": [base]}
def test_full_external_cancel_maps_to_cancelled(monkeypatch):
@@ -60,7 +70,8 @@ def test_zero_fill_not_cancelled_stays_accepted(monkeypatch):
def test_partial_fill_then_cancel_flags_partial_cancel(monkeypatch):
monkeypatch.setattr(
kis_mod.httpx, "get",
kis_mod.httpx,
"get",
_fake_get(_row(ord_qty="10", tot_ccld_qty="4", avg_prvs="70000", cncl_yn="Y")),
)
fs = _broker().poll_fill(f"06010:{ODNO}", side="sell", symbol="005930")
@@ -72,7 +83,8 @@ def test_partial_fill_then_cancel_flags_partial_cancel(monkeypatch):
def test_full_fill_unaffected_by_cancel_flag(monkeypatch):
monkeypatch.setattr(
kis_mod.httpx, "get",
kis_mod.httpx,
"get",
_fake_get(_row(ord_qty="10", tot_ccld_qty="10", avg_prvs="70000", cncl_yn="N")),
)
fs = _broker().poll_fill(f"06010:{ODNO}", side="sell", symbol="005930")