refactor(V2): IBKR final review fixes — WS shutdown, conid match, clock note
Final code-review fixes: - __main__: lifespan stops IBKRWebSocket singletons before registry close - close_position: resolve symbol→conid first, match positions on conid (was matching contractDesc which is a long display string, not ticker) - close_all_positions: prefer ticker field, fallback to contractDesc - get_clock: explicit approximate=true + note about US holidays/half-days Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ Boot:
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Literal, cast
|
||||
|
||||
@@ -54,6 +55,11 @@ def _make_app(settings: Settings) -> FastAPI:
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
# Stop any IBKR WebSocket singletons before closing client registry
|
||||
ibkr_ws_dict = getattr(app.state, "ibkr_ws", {}) or {}
|
||||
for ws in ibkr_ws_dict.values():
|
||||
with contextlib.suppress(Exception):
|
||||
await ws.stop()
|
||||
await app.state.registry.aclose()
|
||||
|
||||
app.router.lifespan_context = lifespan
|
||||
|
||||
Reference in New Issue
Block a user