fix(execution): cancel SQL nullable type error, KIS child cancel detection, worker exception logging
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
2b412fd786
commit
f0ac909958
@@ -130,3 +130,114 @@ def test_full_fill_unaffected_by_cancel_flag(monkeypatch):
|
||||
f"06010:{ODNO}", side="sell", symbol="005930", order_date="20260608"
|
||||
)
|
||||
assert fs.is_filled and fs.filled_qty == 10 and not fs.is_partial_cancel
|
||||
|
||||
|
||||
# ── Regression: KIS child cancel row (orgn_odno) ─────────────────────────────
|
||||
|
||||
def _payload_with_child_cancel(parent_odno: str, child_odno: str, ord_qty: str = "89"):
|
||||
"""Simulate KIS returning original row (cncl_yn='') + separate cancel child."""
|
||||
parent = {
|
||||
"odno": parent_odno,
|
||||
"orgn_odno": "",
|
||||
"ord_qty": ord_qty,
|
||||
"tot_ccld_qty": "0",
|
||||
"avg_prvs": "0",
|
||||
"cncl_yn": "",
|
||||
"rjct_qty": "0",
|
||||
"rmn_qty": "0",
|
||||
"ord_dt": "20260901",
|
||||
"ord_gno_brno": "06010",
|
||||
}
|
||||
child = {
|
||||
"odno": child_odno,
|
||||
"orgn_odno": parent_odno,
|
||||
"ord_qty": ord_qty,
|
||||
"tot_ccld_qty": "0",
|
||||
"avg_prvs": "0",
|
||||
"cncl_yn": "Y",
|
||||
"rjct_qty": "0",
|
||||
"rmn_qty": "0",
|
||||
"ord_dt": "20260901",
|
||||
"ord_gno_brno": "06010",
|
||||
}
|
||||
return {"rt_cd": "0", "output1": [parent, child]}
|
||||
|
||||
|
||||
def test_child_cancel_row_orgn_odno_maps_to_cancelled(monkeypatch):
|
||||
"""KIS child row with orgn_odno=<original> + cncl_yn=Y → full cancel."""
|
||||
payload = _payload_with_child_cancel(ODNO, "0000123457")
|
||||
monkeypatch.setattr(kis_mod.httpx, "get", _fake_get(payload))
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="buy", symbol="225190", order_date="20260901"
|
||||
)
|
||||
assert fs.state == "cancelled", f"expected cancelled, got {fs.state}"
|
||||
assert fs.is_terminal_reject
|
||||
|
||||
|
||||
def test_correction_child_row_not_misclassified_as_cancel(monkeypatch):
|
||||
"""Correction child (cncl_yn='N') must not be treated as a cancel."""
|
||||
parent = {
|
||||
"odno": ODNO,
|
||||
"orgn_odno": "",
|
||||
"ord_qty": "10",
|
||||
"tot_ccld_qty": "0",
|
||||
"avg_prvs": "0",
|
||||
"cncl_yn": "",
|
||||
"rjct_qty": "0",
|
||||
"ord_dt": "20260901",
|
||||
"ord_gno_brno": "06010",
|
||||
}
|
||||
correction_child = {
|
||||
"odno": "0000123458",
|
||||
"orgn_odno": ODNO,
|
||||
"ord_qty": "10",
|
||||
"tot_ccld_qty": "0",
|
||||
"avg_prvs": "0",
|
||||
"cncl_yn": "N", # correction, not cancel
|
||||
"rjct_qty": "0",
|
||||
"ord_dt": "20260901",
|
||||
"ord_gno_brno": "06010",
|
||||
}
|
||||
monkeypatch.setattr(
|
||||
kis_mod.httpx, "get", _fake_get({"rt_cd": "0", "output1": [parent, correction_child]})
|
||||
)
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="buy", symbol="225190", order_date="20260901"
|
||||
)
|
||||
# Correction child must not infer cancellation; original has no fill evidence
|
||||
assert fs.state == "accepted", f"expected accepted, got {fs.state}"
|
||||
|
||||
|
||||
def test_partial_fill_with_child_cancel_row(monkeypatch):
|
||||
"""Partial fill on parent + cancel child → partial_cancel."""
|
||||
parent = {
|
||||
"odno": ODNO,
|
||||
"orgn_odno": "",
|
||||
"ord_qty": "10",
|
||||
"tot_ccld_qty": "4",
|
||||
"avg_prvs": "70000",
|
||||
"cncl_yn": "",
|
||||
"rjct_qty": "0",
|
||||
"ord_dt": "20260901",
|
||||
"ord_gno_brno": "06010",
|
||||
}
|
||||
child = {
|
||||
"odno": "0000123459",
|
||||
"orgn_odno": ODNO,
|
||||
"ord_qty": "6",
|
||||
"tot_ccld_qty": "0",
|
||||
"avg_prvs": "0",
|
||||
"cncl_yn": "Y",
|
||||
"rjct_qty": "0",
|
||||
"ord_dt": "20260901",
|
||||
"ord_gno_brno": "06010",
|
||||
}
|
||||
monkeypatch.setattr(
|
||||
kis_mod.httpx, "get", _fake_get({"rt_cd": "0", "output1": [parent, child]})
|
||||
)
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="sell", symbol="225190", order_date="20260901"
|
||||
)
|
||||
assert fs.state == "partially_filled"
|
||||
assert fs.cancelled and fs.is_partial_cancel
|
||||
assert fs.filled_qty == 4
|
||||
|
||||
Reference in New Issue
Block a user