diff options
Diffstat (limited to 'shared/src')
| -rw-r--r-- | shared/src/shared/broker.py | 5 | ||||
| -rw-r--r-- | shared/src/shared/config.py | 1 | ||||
| -rw-r--r-- | shared/src/shared/db.py | 5 | ||||
| -rw-r--r-- | shared/src/shared/events.py | 1 | ||||
| -rw-r--r-- | shared/src/shared/healthcheck.py | 1 | ||||
| -rw-r--r-- | shared/src/shared/logging.py | 1 | ||||
| -rw-r--r-- | shared/src/shared/metrics.py | 1 | ||||
| -rw-r--r-- | shared/src/shared/models.py | 1 | ||||
| -rw-r--r-- | shared/src/shared/notifier.py | 11 | ||||
| -rw-r--r-- | shared/src/shared/resilience.py | 2 | ||||
| -rw-r--r-- | shared/src/shared/sa_models.py | 16 |
11 files changed, 18 insertions, 27 deletions
diff --git a/shared/src/shared/broker.py b/shared/src/shared/broker.py index 0f87b06..9c6c4c6 100644 --- a/shared/src/shared/broker.py +++ b/shared/src/shared/broker.py @@ -1,4 +1,5 @@ """Redis Streams broker for the trading platform.""" + import json from typing import Any @@ -24,9 +25,7 @@ class RedisBroker: block: int = 0, ) -> list[dict[str, Any]]: """Read messages from a Redis stream.""" - results = await self._redis.xread( - {stream: last_id}, count=count, block=block - ) + results = await self._redis.xread({stream: last_id}, count=count, block=block) messages = [] if results: for _stream, entries in results: diff --git a/shared/src/shared/config.py b/shared/src/shared/config.py index 511654f..47bc2b1 100644 --- a/shared/src/shared/config.py +++ b/shared/src/shared/config.py @@ -1,4 +1,5 @@ """Shared configuration settings for the trading platform.""" + from pydantic_settings import BaseSettings diff --git a/shared/src/shared/db.py b/shared/src/shared/db.py index 95e487e..f9b7f56 100644 --- a/shared/src/shared/db.py +++ b/shared/src/shared/db.py @@ -1,4 +1,5 @@ """Database layer using SQLAlchemy 2.0 async ORM for the trading platform.""" + from datetime import datetime from typing import Optional @@ -107,9 +108,7 @@ class Database: await session.execute(stmt) await session.commit() - async def get_candles( - self, symbol: str, timeframe: str, limit: int = 500 - ) -> list[dict]: + async def get_candles(self, symbol: str, timeframe: str, limit: int = 500) -> list[dict]: """Retrieve candles ordered by open_time descending.""" stmt = ( select(CandleRow) diff --git a/shared/src/shared/events.py b/shared/src/shared/events.py index 1db2bee..72f8865 100644 --- a/shared/src/shared/events.py +++ b/shared/src/shared/events.py @@ -1,4 +1,5 @@ """Event types and serialization for the trading platform.""" + from enum import Enum from typing import Any diff --git a/shared/src/shared/healthcheck.py b/shared/src/shared/healthcheck.py index 8294294..be02712 100644 --- a/shared/src/shared/healthcheck.py +++ b/shared/src/shared/healthcheck.py @@ -1,4 +1,5 @@ """Health check HTTP server with Prometheus metrics endpoint.""" + from __future__ import annotations import time diff --git a/shared/src/shared/logging.py b/shared/src/shared/logging.py index b873eaf..9e42cdc 100644 --- a/shared/src/shared/logging.py +++ b/shared/src/shared/logging.py @@ -1,4 +1,5 @@ """Structured logging configuration using structlog.""" + from __future__ import annotations import logging diff --git a/shared/src/shared/metrics.py b/shared/src/shared/metrics.py index 3b00c5d..cd239f3 100644 --- a/shared/src/shared/metrics.py +++ b/shared/src/shared/metrics.py @@ -1,4 +1,5 @@ """Prometheus metrics for trading platform services.""" + from __future__ import annotations from prometheus_client import Counter, Gauge, Histogram, CollectorRegistry, REGISTRY diff --git a/shared/src/shared/models.py b/shared/src/shared/models.py index 4cb1081..0e8ca44 100644 --- a/shared/src/shared/models.py +++ b/shared/src/shared/models.py @@ -1,4 +1,5 @@ """Shared Pydantic models for the trading platform.""" + import uuid from decimal import Decimal from datetime import datetime, timezone diff --git a/shared/src/shared/notifier.py b/shared/src/shared/notifier.py index de86f87..f03919c 100644 --- a/shared/src/shared/notifier.py +++ b/shared/src/shared/notifier.py @@ -1,4 +1,5 @@ """Telegram notification service for the trading platform.""" + import asyncio import logging from decimal import Decimal @@ -63,9 +64,7 @@ class TelegramNotifier: body, ) except Exception: - logger.exception( - "Telegram send failed (attempt %d/%d)", attempt, MAX_RETRIES - ) + logger.exception("Telegram send failed (attempt %d/%d)", attempt, MAX_RETRIES) if attempt < MAX_RETRIES: await asyncio.sleep(attempt) @@ -96,11 +95,7 @@ class TelegramNotifier: async def send_error(self, error: str, service: str) -> None: """Format and send an error alert.""" - msg = ( - "<b>🚨 Error Alert</b>\n" - f"Service: <b>{service}</b>\n" - f"Error: {error}" - ) + msg = f"<b>🚨 Error Alert</b>\nService: <b>{service}</b>\nError: {error}" await self.send(msg) async def send_daily_summary( diff --git a/shared/src/shared/resilience.py b/shared/src/shared/resilience.py index d4e963b..e43fd21 100644 --- a/shared/src/shared/resilience.py +++ b/shared/src/shared/resilience.py @@ -35,7 +35,7 @@ def retry_with_backoff( except Exception as exc: last_exc = exc if attempt < max_retries: - delay = min(base_delay * (2 ** attempt), max_delay) + delay = min(base_delay * (2**attempt), max_delay) jitter = delay * random.uniform(0, 0.5) total_delay = delay + jitter logger.warning( diff --git a/shared/src/shared/sa_models.py b/shared/src/shared/sa_models.py index 0537846..8386ba8 100644 --- a/shared/src/shared/sa_models.py +++ b/shared/src/shared/sa_models.py @@ -41,17 +41,13 @@ class OrderRow(Base): __tablename__ = "orders" id: Mapped[str] = mapped_column(Text, primary_key=True) - signal_id: Mapped[str | None] = mapped_column( - Text, ForeignKey("signals.id") - ) + signal_id: Mapped[str | None] = mapped_column(Text, ForeignKey("signals.id")) symbol: Mapped[str] = mapped_column(Text, nullable=False) side: Mapped[str] = mapped_column(Text, nullable=False) type: Mapped[str] = mapped_column(Text, nullable=False) price: Mapped[Decimal] = mapped_column(Numeric, nullable=False) quantity: Mapped[Decimal] = mapped_column(Numeric, nullable=False) - status: Mapped[str] = mapped_column( - Text, nullable=False, server_default="PENDING" - ) + status: Mapped[str] = mapped_column(Text, nullable=False, server_default="PENDING") created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False) filled_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True)) @@ -60,16 +56,12 @@ class TradeRow(Base): __tablename__ = "trades" id: Mapped[str] = mapped_column(Text, primary_key=True) - order_id: Mapped[str | None] = mapped_column( - Text, ForeignKey("orders.id") - ) + order_id: Mapped[str | None] = mapped_column(Text, ForeignKey("orders.id")) symbol: Mapped[str] = mapped_column(Text, nullable=False) side: Mapped[str] = mapped_column(Text, nullable=False) price: Mapped[Decimal] = mapped_column(Numeric, nullable=False) quantity: Mapped[Decimal] = mapped_column(Numeric, nullable=False) - fee: Mapped[Decimal] = mapped_column( - Numeric, nullable=False, server_default="0" - ) + fee: Mapped[Decimal] = mapped_column(Numeric, nullable=False, server_default="0") traded_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False) |
