refactor(V2): IBKR client — remove dead whitelist + max_cycles test

Code review polish (commit b9c58a3):
- Remove unused _AUTO_CONFIRM_WHITELIST (was scaffolding, never wired)
- Replace with policy comment documenting auto-confirm behavior
- New test: test_place_order_too_many_confirmations

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-05-03 20:37:37 +00:00
parent b9c58a376f
commit 12002642e5
2 changed files with 28 additions and 3 deletions
+3 -3
View File
@@ -278,9 +278,9 @@ class IBKRClient:
# ── Order writes ────────────────────────────────────────────
_AUTO_CONFIRM_WHITELIST = (
"outside RTH", "no market data", "you are submitting", "the contract",
)
# Auto-confirm policy: any IBKR warning that is NOT in _CRITICAL_WARNINGS
# is auto-confirmed up to _AUTO_CONFIRM_MAX_CYCLES times. Hardening to a
# strict whitelist (allow-list) is deferred — V1 trades safety for UX.
_CRITICAL_WARNINGS = (
"margin", "suitability", "credit", "rejected", "insufficient",
)
+25
View File
@@ -205,3 +205,28 @@ async def test_cancel_order(httpx_mock: HTTPXMock, client):
)
res = await client.cancel_order("OID42")
assert res["canceled"] is True
@pytest.mark.asyncio
async def test_place_order_too_many_confirmations(httpx_mock: HTTPXMock, client):
httpx_mock.add_response(url=re.compile(r".*/tickle"), json={})
httpx_mock.add_response(
url=re.compile(r".*/trsrv/secdef/search"),
json=[{"conid": 265598, "symbol": "AAPL", "secType": "STK"}],
)
# Initial place + 3 reply cycles all return new warnings — should fail at MAX_CYCLES
httpx_mock.add_response(
url=re.compile(r".*/iserver/account/DU1234/orders$"),
method="POST",
json=[{"id": "msg1", "message": ["outside RTH"]}],
)
for n in range(2, 5):
httpx_mock.add_response(
url=re.compile(rf".*/iserver/reply/msg{n-1}$"),
method="POST",
json=[{"id": f"msg{n}", "message": ["outside RTH"]}],
)
with pytest.raises(IBKRError, match="IBKR_ORDER_TOO_MANY_CONFIRMATIONS"):
await client.place_order(
symbol="AAPL", side="buy", qty=1, order_type="market",
)