fix(execution): fail closed on unresolved orders
This commit is contained in:
@@ -143,7 +143,9 @@ def test_poll_fill_uses_current_all_market_contract(monkeypatch):
|
||||
|
||||
monkeypatch.setattr("trex_core.adapters.broker.kis.httpx.get", fake_get)
|
||||
|
||||
status = broker.poll_fill("91258:1234", side="buy", symbol="005930")
|
||||
status = broker.poll_fill(
|
||||
"91258:1234", side="buy", symbol="005930", order_date="20260608"
|
||||
)
|
||||
|
||||
assert status.state == "accepted"
|
||||
assert seen["tr_id"] == "VTTC0081R"
|
||||
@@ -578,8 +580,12 @@ def test_fill_poll_transport_failure_uses_backoff(monkeypatch):
|
||||
|
||||
monkeypatch.setattr("trex_core.adapters.broker.kis.httpx.get", fail)
|
||||
|
||||
first = b.poll_fill("91258:1234", side="buy", symbol="005930")
|
||||
immediate = b.poll_fill("91258:1234", side="buy", symbol="005930")
|
||||
first = b.poll_fill(
|
||||
"91258:1234", side="buy", symbol="005930", order_date="20260608"
|
||||
)
|
||||
immediate = b.poll_fill(
|
||||
"91258:1234", side="buy", symbol="005930", order_date="20260608"
|
||||
)
|
||||
|
||||
assert first.state == "unknown"
|
||||
assert immediate.state == "accepted"
|
||||
@@ -587,6 +593,8 @@ def test_fill_poll_transport_failure_uses_backoff(monkeypatch):
|
||||
assert len(calls) == 1
|
||||
|
||||
clock[0] += 31
|
||||
again = b.poll_fill("91258:1234", side="buy", symbol="005930")
|
||||
again = b.poll_fill(
|
||||
"91258:1234", side="buy", symbol="005930", order_date="20260608"
|
||||
)
|
||||
assert again.state == "unknown"
|
||||
assert len(calls) == 2
|
||||
|
||||
@@ -59,13 +59,17 @@ def _row(**kw):
|
||||
|
||||
def test_full_external_cancel_maps_to_cancelled(monkeypatch):
|
||||
monkeypatch.setattr(kis_mod.httpx, "get", _fake_get(_row(tot_ccld_qty="0", cncl_yn="Y")))
|
||||
fs = _broker().poll_fill(f"06010:{ODNO}", side="sell", symbol="005930")
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="sell", symbol="005930", order_date="20260608"
|
||||
)
|
||||
assert fs.state == "cancelled" and fs.is_terminal_reject and not fs.is_partial_cancel
|
||||
|
||||
|
||||
def test_zero_fill_not_cancelled_stays_accepted(monkeypatch):
|
||||
monkeypatch.setattr(kis_mod.httpx, "get", _fake_get(_row(tot_ccld_qty="0", cncl_yn="N")))
|
||||
fs = _broker().poll_fill(f"06010:{ODNO}", side="sell", symbol="005930")
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="sell", symbol="005930", order_date="20260608"
|
||||
)
|
||||
assert fs.state == "accepted" and not fs.is_terminal_reject
|
||||
|
||||
|
||||
@@ -83,7 +87,9 @@ def test_zero_fill_full_rejection_maps_to_rejected(monkeypatch):
|
||||
)
|
||||
),
|
||||
)
|
||||
fs = _broker().poll_fill(f"06010:{ODNO}", side="buy", symbol="005930")
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="buy", symbol="005930", order_date="20260608"
|
||||
)
|
||||
assert fs.state == "rejected" and fs.is_terminal_reject
|
||||
|
||||
|
||||
@@ -93,7 +99,9 @@ def test_zero_fill_partial_rejection_does_not_infer_terminal(monkeypatch):
|
||||
"get",
|
||||
_fake_get(_row(ord_qty="10", tot_ccld_qty="0", rjct_qty="4", cncl_yn="")),
|
||||
)
|
||||
fs = _broker().poll_fill(f"06010:{ODNO}", side="buy", symbol="005930")
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="buy", symbol="005930", order_date="20260608"
|
||||
)
|
||||
assert fs.state == "accepted" and not fs.is_terminal_reject
|
||||
|
||||
|
||||
@@ -103,7 +111,9 @@ def test_partial_fill_then_cancel_flags_partial_cancel(monkeypatch):
|
||||
"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")
|
||||
fs = _broker().poll_fill(
|
||||
f"06010:{ODNO}", side="sell", symbol="005930", order_date="20260608"
|
||||
)
|
||||
assert fs.state == "partially_filled"
|
||||
assert fs.cancelled and fs.is_partial_cancel
|
||||
assert fs.filled_qty == 4 and fs.avg_price == 70000.0
|
||||
@@ -116,5 +126,7 @@ def test_full_fill_unaffected_by_cancel_flag(monkeypatch):
|
||||
"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")
|
||||
fs = _broker().poll_fill(
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user