diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 17:28:14 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 17:28:14 +0900 |
| commit | 72d29b4798f2594465f384982f0fc932a1f6c880 (patch) | |
| tree | a140c639f8595f9631e49f30f38996044b9d3f5f /services/order-executor/src/order_executor | |
| parent | 23e60d37f8f55386ab7c1378a50db11a9c386dc6 (diff) | |
fix: lint cleanup for API, combined strategy, and formatting
Diffstat (limited to 'services/order-executor/src/order_executor')
| -rw-r--r-- | services/order-executor/src/order_executor/main.py | 4 | ||||
| -rw-r--r-- | services/order-executor/src/order_executor/risk_manager.py | 13 |
2 files changed, 14 insertions, 3 deletions
diff --git a/services/order-executor/src/order_executor/main.py b/services/order-executor/src/order_executor/main.py index 32470f6..1eeee7b 100644 --- a/services/order-executor/src/order_executor/main.py +++ b/services/order-executor/src/order_executor/main.py @@ -60,7 +60,9 @@ async def run() -> None: last_id = "$" stream = "signals" - health = HealthCheckServer("order-executor", port=config.health_port + 2, auth_token=config.metrics_auth_token) + health = HealthCheckServer( + "order-executor", port=config.health_port + 2, auth_token=config.metrics_auth_token + ) health.register_check("redis", broker.ping) await health.start() metrics.service_up.labels(service="order-executor").set(1) diff --git a/services/order-executor/src/order_executor/risk_manager.py b/services/order-executor/src/order_executor/risk_manager.py index 2b0a864..c3578a7 100644 --- a/services/order-executor/src/order_executor/risk_manager.py +++ b/services/order-executor/src/order_executor/risk_manager.py @@ -1,4 +1,5 @@ """Risk management for order execution.""" + from dataclasses import dataclass from decimal import Decimal from collections import deque @@ -16,6 +17,7 @@ class RiskCheckResult: @dataclass class TrailingStop: """Tracks trailing stop for a symbol.""" + symbol: str highest_price: Decimal stop_pct: Decimal # e.g. 5.0 for 5% @@ -86,7 +88,11 @@ class RiskManager: if not history or len(history) < 2: return None prices = list(history) - returns = [(prices[i] - prices[i-1]) / prices[i-1] for i in range(1, len(prices)) if prices[i-1] != 0] + returns = [ + (prices[i] - prices[i - 1]) / prices[i - 1] + for i in range(1, len(prices)) + if prices[i - 1] != 0 + ] if not returns: return None mean = sum(returns) / len(returns) @@ -153,7 +159,10 @@ class RiskManager: if position is not None: current_position_value = position.quantity * position.current_price - if balance > 0 and (current_position_value + order_cost) / balance > self.max_position_size: + if ( + balance > 0 + and (current_position_value + order_cost) / balance > self.max_position_size + ): return RiskCheckResult(allowed=False, reason="Position size exceeded") return RiskCheckResult(allowed=True, reason="OK") |
