ci: fix lint baseline and stabilize failing main tests
This commit is contained in:
@@ -11,8 +11,9 @@ Order is fixed:
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
from collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Awaitable, Callable
|
||||
from typing import Any
|
||||
|
||||
StepCallable = Callable[[], Any | Awaitable[Any]]
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from src.markets.schedule import MarketInfo
|
||||
_LOW_LIQUIDITY_SESSIONS = {"NXT_AFTER", "US_PRE", "US_DAY", "US_AFTER"}
|
||||
|
||||
|
||||
class OrderPolicyRejected(Exception):
|
||||
class OrderPolicyRejectedError(Exception):
|
||||
"""Raised when an order violates session policy."""
|
||||
|
||||
def __init__(self, message: str, *, session_id: str, market_code: str) -> None:
|
||||
@@ -61,7 +61,9 @@ def classify_session_id(market: MarketInfo, now: datetime | None = None) -> str:
|
||||
|
||||
def get_session_info(market: MarketInfo, now: datetime | None = None) -> SessionInfo:
|
||||
session_id = classify_session_id(market, now)
|
||||
return SessionInfo(session_id=session_id, is_low_liquidity=session_id in _LOW_LIQUIDITY_SESSIONS)
|
||||
return SessionInfo(
|
||||
session_id=session_id, is_low_liquidity=session_id in _LOW_LIQUIDITY_SESSIONS
|
||||
)
|
||||
|
||||
|
||||
def validate_order_policy(
|
||||
@@ -76,7 +78,7 @@ def validate_order_policy(
|
||||
|
||||
is_market_order = price <= 0
|
||||
if info.is_low_liquidity and is_market_order:
|
||||
raise OrderPolicyRejected(
|
||||
raise OrderPolicyRejectedError(
|
||||
f"Market order is forbidden in low-liquidity session ({info.session_id})",
|
||||
session_id=info.session_id,
|
||||
market_code=market.code,
|
||||
@@ -84,10 +86,14 @@ def validate_order_policy(
|
||||
|
||||
# Guard against accidental unsupported actions.
|
||||
if order_type not in {"BUY", "SELL"}:
|
||||
raise OrderPolicyRejected(
|
||||
raise OrderPolicyRejectedError(
|
||||
f"Unsupported order_type={order_type}",
|
||||
session_id=info.session_id,
|
||||
market_code=market.code,
|
||||
)
|
||||
|
||||
return info
|
||||
|
||||
|
||||
# Backward compatibility alias
|
||||
OrderPolicyRejected = OrderPolicyRejectedError
|
||||
|
||||
@@ -28,9 +28,7 @@ class PriorityTask:
|
||||
# Task data not used in comparison
|
||||
task_id: str = field(compare=False)
|
||||
task_data: dict[str, Any] = field(compare=False, default_factory=dict)
|
||||
callback: Callable[[], Coroutine[Any, Any, Any]] | None = field(
|
||||
compare=False, default=None
|
||||
)
|
||||
callback: Callable[[], Coroutine[Any, Any, Any]] | None = field(compare=False, default=None)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -25,7 +25,7 @@ class CircuitBreakerTripped(SystemExit):
|
||||
)
|
||||
|
||||
|
||||
class FatFingerRejected(Exception):
|
||||
class FatFingerRejectedError(Exception):
|
||||
"""Raised when an order exceeds the maximum allowed proportion of cash."""
|
||||
|
||||
def __init__(self, order_amount: float, total_cash: float, max_pct: float) -> None:
|
||||
@@ -61,7 +61,7 @@ class RiskManager:
|
||||
def check_fat_finger(self, order_amount: float, total_cash: float) -> None:
|
||||
"""Reject orders that exceed the maximum proportion of available cash."""
|
||||
if total_cash <= 0:
|
||||
raise FatFingerRejected(order_amount, total_cash, self._ff_max_pct)
|
||||
raise FatFingerRejectedError(order_amount, total_cash, self._ff_max_pct)
|
||||
|
||||
ratio_pct = (order_amount / total_cash) * 100
|
||||
if ratio_pct > self._ff_max_pct:
|
||||
@@ -69,7 +69,7 @@ class RiskManager:
|
||||
"Fat finger check failed",
|
||||
extra={"order_amount": order_amount},
|
||||
)
|
||||
raise FatFingerRejected(order_amount, total_cash, self._ff_max_pct)
|
||||
raise FatFingerRejectedError(order_amount, total_cash, self._ff_max_pct)
|
||||
|
||||
def validate_order(
|
||||
self,
|
||||
@@ -81,3 +81,7 @@ class RiskManager:
|
||||
self.check_circuit_breaker(current_pnl_pct)
|
||||
self.check_fat_finger(order_amount, total_cash)
|
||||
logger.info("Order passed risk validation")
|
||||
|
||||
|
||||
# Backward compatibility alias
|
||||
FatFingerRejected = FatFingerRejectedError
|
||||
|
||||
Reference in New Issue
Block a user