diff options
Diffstat (limited to 'services/strategy-engine')
3 files changed, 25 insertions, 11 deletions
diff --git a/services/strategy-engine/src/strategy_engine/main.py b/services/strategy-engine/src/strategy_engine/main.py index fabd755..9f3b3c9 100644 --- a/services/strategy-engine/src/strategy_engine/main.py +++ b/services/strategy-engine/src/strategy_engine/main.py @@ -43,7 +43,9 @@ async def run() -> None: engine = StrategyEngine(broker=broker, strategies=strategies) - health = HealthCheckServer("strategy-engine", port=config.health_port + 1, auth_token=config.metrics_auth_token) + health = HealthCheckServer( + "strategy-engine", port=config.health_port + 1, auth_token=config.metrics_auth_token + ) health.register_check("redis", broker.ping) await health.start() metrics.service_up.labels(service="strategy-engine").set(1) diff --git a/services/strategy-engine/strategies/combined_strategy.py b/services/strategy-engine/strategies/combined_strategy.py index e99dfdf..507ef5b 100644 --- a/services/strategy-engine/strategies/combined_strategy.py +++ b/services/strategy-engine/strategies/combined_strategy.py @@ -1,6 +1,6 @@ """Combined strategy that aggregates signals from multiple sub-strategies.""" + from decimal import Decimal -from typing import Optional from shared.models import Candle, Signal, OrderSide from strategies.base import BaseStrategy @@ -12,6 +12,7 @@ class CombinedStrategy(BaseStrategy): Each sub-strategy votes BUY (+weight), SELL (-weight), or HOLD (0). The combined signal fires when the weighted sum exceeds a threshold. """ + name: str = "combined" def __init__(self) -> None: diff --git a/services/strategy-engine/tests/test_combined_strategy.py b/services/strategy-engine/tests/test_combined_strategy.py index b860dca..3408a89 100644 --- a/services/strategy-engine/tests/test_combined_strategy.py +++ b/services/strategy-engine/tests/test_combined_strategy.py @@ -1,6 +1,8 @@ """Tests for Combined strategy.""" + import sys from pathlib import Path + sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from decimal import Decimal @@ -24,9 +26,12 @@ class AlwaysBuyStrategy(BaseStrategy): def on_candle(self, candle: Candle) -> Signal | None: return Signal( - strategy=self.name, symbol=candle.symbol, - side=OrderSide.BUY, price=candle.close, - quantity=Decimal("0.01"), reason="always buy", + strategy=self.name, + symbol=candle.symbol, + side=OrderSide.BUY, + price=candle.close, + quantity=Decimal("0.01"), + reason="always buy", ) @@ -42,9 +47,12 @@ class AlwaysSellStrategy(BaseStrategy): def on_candle(self, candle: Candle) -> Signal | None: return Signal( - strategy=self.name, symbol=candle.symbol, - side=OrderSide.SELL, price=candle.close, - quantity=Decimal("0.01"), reason="always sell", + strategy=self.name, + symbol=candle.symbol, + side=OrderSide.SELL, + price=candle.close, + quantity=Decimal("0.01"), + reason="always sell", ) @@ -64,10 +72,13 @@ class NeutralStrategy(BaseStrategy): def _candle(price=100.0): return Candle( - symbol="BTCUSDT", timeframe="1m", + symbol="BTCUSDT", + timeframe="1m", open_time=datetime(2025, 1, 1, tzinfo=timezone.utc), - open=Decimal(str(price)), high=Decimal(str(price+10)), - low=Decimal(str(price-10)), close=Decimal(str(price)), + open=Decimal(str(price)), + high=Decimal(str(price + 10)), + low=Decimal(str(price - 10)), + close=Decimal(str(price)), volume=Decimal("10"), ) |
