fix: close broker uncertainty audit gaps
This commit is contained in:
@@ -43,6 +43,16 @@ _SUBMISSION_LOOKUP_GRACE_SECONDS = 90.0
|
||||
_SUPPORTED_ORDER_VENUES = frozenset({"AUTO", "KRX", "NXT", "SOR"})
|
||||
|
||||
|
||||
def _balance_http_error_code(status: Optional[int]) -> str:
|
||||
if status == 401:
|
||||
return "authentication_failed"
|
||||
if status == 403:
|
||||
return "authorization_failed"
|
||||
if status in {408, 425, 429} or (status is not None and status >= 500):
|
||||
return "transport_failed"
|
||||
return "broker_rejected"
|
||||
|
||||
|
||||
def resolve_order_venue(venue: str, at: datetime) -> str:
|
||||
"""Resolve AUTO to the venue that accepts domestic-stock orders at `at`.
|
||||
|
||||
@@ -161,7 +171,8 @@ class KISBroker:
|
||||
def account_scope_hash(self) -> str:
|
||||
"""Stable non-secret identity for account-scoped persisted state."""
|
||||
cano, product = self._account()
|
||||
return hashlib.sha256(f"{cano}|{product}".encode()).hexdigest()
|
||||
material = f"{self._base_url}|{cano}|{product}|{self._app_key}"
|
||||
return hashlib.sha256(material.encode()).hexdigest()
|
||||
|
||||
# --- credential hot-swap (dcy-036 / REQ-113 AC-2 / REQ-115 AC-1) ----------
|
||||
def reinitialize(self, credential) -> None:
|
||||
@@ -658,12 +669,7 @@ class KISBroker:
|
||||
payload = resp.json()
|
||||
except httpx.HTTPStatusError as exc:
|
||||
status = exc.response.status_code if exc.response is not None else None
|
||||
code = (
|
||||
"authentication_failed"
|
||||
if status == 401
|
||||
else ("authorization_failed" if status == 403 else "transport_failed")
|
||||
)
|
||||
raise BrokerBalanceError(code) from None
|
||||
raise BrokerBalanceError(_balance_http_error_code(status)) from None
|
||||
except httpx.HTTPError:
|
||||
raise BrokerBalanceError("transport_failed") from None
|
||||
except (ValueError, TypeError):
|
||||
@@ -721,12 +727,7 @@ class KISBroker:
|
||||
raise
|
||||
except httpx.HTTPStatusError as exc:
|
||||
status = exc.response.status_code if exc.response is not None else None
|
||||
code = (
|
||||
"authentication_failed"
|
||||
if status == 401
|
||||
else ("authorization_failed" if status == 403 else "transport_failed")
|
||||
)
|
||||
raise BrokerBalanceError(code) from None
|
||||
raise BrokerBalanceError(_balance_http_error_code(status)) from None
|
||||
except httpx.HTTPError:
|
||||
raise BrokerBalanceError("transport_failed") from None
|
||||
except (KeyError, TypeError, ValueError):
|
||||
|
||||
Reference in New Issue
Block a user