diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 17:57:43 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 17:57:43 +0900 |
| commit | 61b2a193e79d74783bb1ad4c3a8ccb6ead0f24c0 (patch) | |
| tree | 374ad93df6d393715809192ff40b1754d56de39b | |
| parent | 13a9b2c80bb3eb1353cf2d49bdbf7d0dbd858ccc (diff) | |
fix: lint cleanup after medium priority tasks
| -rw-r--r-- | cli/tests/test_cli_backtest.py | 1 | ||||
| -rw-r--r-- | cli/tests/test_cli_portfolio.py | 1 | ||||
| -rw-r--r-- | cli/tests/test_cli_service.py | 1 | ||||
| -rw-r--r-- | cli/tests/test_cli_strategy.py | 7 | ||||
| -rw-r--r-- | services/api/tests/test_orders_router.py | 3 | ||||
| -rw-r--r-- | services/api/tests/test_portfolio_router.py | 4 | ||||
| -rw-r--r-- | services/order-executor/src/order_executor/main.py | 12 | ||||
| -rw-r--r-- | services/portfolio-manager/src/portfolio_manager/main.py | 9 | ||||
| -rw-r--r-- | services/portfolio-manager/tests/test_portfolio.py | 112 | ||||
| -rw-r--r-- | shared/src/shared/broker.py | 4 | ||||
| -rw-r--r-- | shared/tests/test_broker.py | 18 |
11 files changed, 99 insertions, 73 deletions
diff --git a/cli/tests/test_cli_backtest.py b/cli/tests/test_cli_backtest.py index 84227a9..80f516c 100644 --- a/cli/tests/test_cli_backtest.py +++ b/cli/tests/test_cli_backtest.py @@ -1,4 +1,5 @@ """Tests for backtest CLI commands.""" + from click.testing import CliRunner from trading_cli.main import cli diff --git a/cli/tests/test_cli_portfolio.py b/cli/tests/test_cli_portfolio.py index 351b49f..19be0cb 100644 --- a/cli/tests/test_cli_portfolio.py +++ b/cli/tests/test_cli_portfolio.py @@ -1,4 +1,5 @@ """Tests for portfolio CLI commands.""" + from click.testing import CliRunner from trading_cli.main import cli diff --git a/cli/tests/test_cli_service.py b/cli/tests/test_cli_service.py index 08cd396..dbc5889 100644 --- a/cli/tests/test_cli_service.py +++ b/cli/tests/test_cli_service.py @@ -1,4 +1,5 @@ """Tests for service CLI commands.""" + from click.testing import CliRunner from trading_cli.main import cli diff --git a/cli/tests/test_cli_strategy.py b/cli/tests/test_cli_strategy.py index 3c89477..cf3057b 100644 --- a/cli/tests/test_cli_strategy.py +++ b/cli/tests/test_cli_strategy.py @@ -1,4 +1,5 @@ """Tests for strategy CLI commands.""" + from unittest.mock import patch, MagicMock from click.testing import CliRunner from trading_cli.main import cli @@ -44,4 +45,8 @@ def test_strategy_info_unknown(): runner = CliRunner() result = runner.invoke(cli, ["strategy", "info", "--name", "nonexistent"]) # Should handle gracefully (exit 0 or 1 with message) - assert "not found" in result.output.lower() or result.exit_code != 0 or "nonexistent" in result.output + assert ( + "not found" in result.output.lower() + or result.exit_code != 0 + or "nonexistent" in result.output + ) diff --git a/services/api/tests/test_orders_router.py b/services/api/tests/test_orders_router.py index 899fb27..0658619 100644 --- a/services/api/tests/test_orders_router.py +++ b/services/api/tests/test_orders_router.py @@ -1,7 +1,6 @@ """Tests for orders API router.""" + import pytest -from decimal import Decimal -from datetime import datetime, timezone from unittest.mock import AsyncMock, MagicMock from fastapi.testclient import TestClient from fastapi import FastAPI diff --git a/services/api/tests/test_portfolio_router.py b/services/api/tests/test_portfolio_router.py index 0993923..f2584ea 100644 --- a/services/api/tests/test_portfolio_router.py +++ b/services/api/tests/test_portfolio_router.py @@ -1,8 +1,8 @@ """Tests for portfolio API router.""" + import pytest from decimal import Decimal -from datetime import datetime, timezone -from unittest.mock import AsyncMock, MagicMock, patch +from unittest.mock import AsyncMock, MagicMock from fastapi.testclient import TestClient from fastapi import FastAPI diff --git a/services/order-executor/src/order_executor/main.py b/services/order-executor/src/order_executor/main.py index 930517e..3fe4c12 100644 --- a/services/order-executor/src/order_executor/main.py +++ b/services/order-executor/src/order_executor/main.py @@ -90,21 +90,15 @@ async def run() -> None: "processing_pending_signal", signal_id=str(signal.id), symbol=signal.symbol ) await executor.execute(signal) - metrics.events_processed.labels( - service="order-executor", event_type="signal" - ).inc() + metrics.events_processed.labels(service="order-executor", event_type="signal").inc() await broker.ack(stream, GROUP, msg_id) except Exception as exc: log.error("pending_process_failed", error=str(exc), msg_id=msg_id) - metrics.errors_total.labels( - service="order-executor", error_type="processing" - ).inc() + metrics.errors_total.labels(service="order-executor", error_type="processing").inc() try: while True: - messages = await broker.read_group( - stream, GROUP, CONSUMER, count=10, block=5000 - ) + messages = await broker.read_group(stream, GROUP, CONSUMER, count=10, block=5000) for msg_id, msg in messages: try: event = Event.from_dict(msg) diff --git a/services/portfolio-manager/src/portfolio_manager/main.py b/services/portfolio-manager/src/portfolio_manager/main.py index 87e4c64..a6823ae 100644 --- a/services/portfolio-manager/src/portfolio_manager/main.py +++ b/services/portfolio-manager/src/portfolio_manager/main.py @@ -1,7 +1,6 @@ """Portfolio Manager Service entry point.""" import asyncio -from decimal import Decimal from shared.broker import RedisBroker from shared.db import Database @@ -111,15 +110,11 @@ async def run() -> None: await broker.ack(ORDERS_STREAM, GROUP, msg_id) except Exception as exc: log.error("pending_process_failed", error=str(exc), msg_id=msg_id) - metrics.errors_total.labels( - service="portfolio-manager", error_type="processing" - ).inc() + metrics.errors_total.labels(service="portfolio-manager", error_type="processing").inc() try: while True: - messages = await broker.read_group( - ORDERS_STREAM, GROUP, CONSUMER, count=10, block=1000 - ) + messages = await broker.read_group(ORDERS_STREAM, GROUP, CONSUMER, count=10, block=1000) for msg_id, msg in messages: try: event = Event.from_dict(msg) diff --git a/services/portfolio-manager/tests/test_portfolio.py b/services/portfolio-manager/tests/test_portfolio.py index 5a7ac64..768e071 100644 --- a/services/portfolio-manager/tests/test_portfolio.py +++ b/services/portfolio-manager/tests/test_portfolio.py @@ -63,19 +63,31 @@ def test_realized_pnl_on_sell() -> None: tracker = PortfolioTracker() # Buy at 50000 - tracker.apply_order(Order( - signal_id="s1", symbol="BTCUSDT", side=OrderSide.BUY, - type=OrderType.MARKET, price=Decimal("50000"), - quantity=Decimal("0.1"), status=OrderStatus.FILLED, - )) + tracker.apply_order( + Order( + signal_id="s1", + symbol="BTCUSDT", + side=OrderSide.BUY, + type=OrderType.MARKET, + price=Decimal("50000"), + quantity=Decimal("0.1"), + status=OrderStatus.FILLED, + ) + ) assert tracker.realized_pnl == Decimal("0") # Sell at 55000 — profit of 500 - tracker.apply_order(Order( - signal_id="s2", symbol="BTCUSDT", side=OrderSide.SELL, - type=OrderType.MARKET, price=Decimal("55000"), - quantity=Decimal("0.1"), status=OrderStatus.FILLED, - )) + tracker.apply_order( + Order( + signal_id="s2", + symbol="BTCUSDT", + side=OrderSide.SELL, + type=OrderType.MARKET, + price=Decimal("55000"), + quantity=Decimal("0.1"), + status=OrderStatus.FILLED, + ) + ) assert tracker.realized_pnl == Decimal("500") @@ -83,16 +95,28 @@ def test_realized_pnl_on_loss() -> None: """Selling at a loss should track negative realized PnL.""" tracker = PortfolioTracker() - tracker.apply_order(Order( - signal_id="s1", symbol="BTCUSDT", side=OrderSide.BUY, - type=OrderType.MARKET, price=Decimal("50000"), - quantity=Decimal("0.1"), status=OrderStatus.FILLED, - )) - tracker.apply_order(Order( - signal_id="s2", symbol="BTCUSDT", side=OrderSide.SELL, - type=OrderType.MARKET, price=Decimal("45000"), - quantity=Decimal("0.1"), status=OrderStatus.FILLED, - )) + tracker.apply_order( + Order( + signal_id="s1", + symbol="BTCUSDT", + side=OrderSide.BUY, + type=OrderType.MARKET, + price=Decimal("50000"), + quantity=Decimal("0.1"), + status=OrderStatus.FILLED, + ) + ) + tracker.apply_order( + Order( + signal_id="s2", + symbol="BTCUSDT", + side=OrderSide.SELL, + type=OrderType.MARKET, + price=Decimal("45000"), + quantity=Decimal("0.1"), + status=OrderStatus.FILLED, + ) + ) assert tracker.realized_pnl == Decimal("-500") @@ -101,24 +125,42 @@ def test_realized_pnl_accumulates() -> None: tracker = PortfolioTracker() # Buy 0.2 at 50000 - tracker.apply_order(Order( - signal_id="s1", symbol="BTCUSDT", side=OrderSide.BUY, - type=OrderType.MARKET, price=Decimal("50000"), - quantity=Decimal("0.2"), status=OrderStatus.FILLED, - )) + tracker.apply_order( + Order( + signal_id="s1", + symbol="BTCUSDT", + side=OrderSide.BUY, + type=OrderType.MARKET, + price=Decimal("50000"), + quantity=Decimal("0.2"), + status=OrderStatus.FILLED, + ) + ) # Sell 0.1 at 55000 -> +500 - tracker.apply_order(Order( - signal_id="s2", symbol="BTCUSDT", side=OrderSide.SELL, - type=OrderType.MARKET, price=Decimal("55000"), - quantity=Decimal("0.1"), status=OrderStatus.FILLED, - )) + tracker.apply_order( + Order( + signal_id="s2", + symbol="BTCUSDT", + side=OrderSide.SELL, + type=OrderType.MARKET, + price=Decimal("55000"), + quantity=Decimal("0.1"), + status=OrderStatus.FILLED, + ) + ) # Sell 0.1 at 60000 -> +1000 - tracker.apply_order(Order( - signal_id="s3", symbol="BTCUSDT", side=OrderSide.SELL, - type=OrderType.MARKET, price=Decimal("60000"), - quantity=Decimal("0.1"), status=OrderStatus.FILLED, - )) + tracker.apply_order( + Order( + signal_id="s3", + symbol="BTCUSDT", + side=OrderSide.SELL, + type=OrderType.MARKET, + price=Decimal("60000"), + quantity=Decimal("0.1"), + status=OrderStatus.FILLED, + ) + ) assert tracker.realized_pnl == Decimal("1500") diff --git a/shared/src/shared/broker.py b/shared/src/shared/broker.py index c060c24..fbe4576 100644 --- a/shared/src/shared/broker.py +++ b/shared/src/shared/broker.py @@ -63,9 +63,7 @@ class RedisBroker: count: int = 10, ) -> list[tuple[str, dict[str, Any]]]: """Read pending (unacknowledged) messages for this consumer.""" - results = await self._redis.xreadgroup( - group, consumer, {stream: "0"}, count=count - ) + results = await self._redis.xreadgroup(group, consumer, {stream: "0"}, count=count) messages = [] if results: for _stream, entries in results: diff --git a/shared/tests/test_broker.py b/shared/tests/test_broker.py index c33f6ec..9be84b0 100644 --- a/shared/tests/test_broker.py +++ b/shared/tests/test_broker.py @@ -109,9 +109,7 @@ async def test_broker_read_group(): mock_redis = AsyncMock() mock_redis.xreadgroup = AsyncMock( - return_value=[ - (b"stream", [(b"1-0", {b"payload": b'{"type": "test"}'})]) - ] + return_value=[(b"stream", [(b"1-0", {b"payload": b'{"type": "test"}'})])] ) broker = RedisBroker.__new__(RedisBroker) broker._redis = mock_redis @@ -142,9 +140,7 @@ async def test_broker_read_pending(): mock_redis = AsyncMock() mock_redis.xreadgroup = AsyncMock( - return_value=[ - (b"stream", [(b"1-0", {b"payload": b'{"type": "pending"}'})]) - ] + return_value=[(b"stream", [(b"1-0", {b"payload": b'{"type": "pending"}'})])] ) broker = RedisBroker.__new__(RedisBroker) broker._redis = mock_redis @@ -154,9 +150,7 @@ async def test_broker_read_pending(): assert messages[0][0] == "1-0" assert messages[0][1] == {"type": "pending"} # Verify it uses "0" (not ">") to read pending - mock_redis.xreadgroup.assert_called_once_with( - "group", "consumer", {"stream": "0"}, count=10 - ) + mock_redis.xreadgroup.assert_called_once_with("group", "consumer", {"stream": "0"}, count=10) @pytest.mark.asyncio @@ -165,11 +159,7 @@ async def test_broker_read_pending_skips_empty_fields(): from shared.broker import RedisBroker mock_redis = AsyncMock() - mock_redis.xreadgroup = AsyncMock( - return_value=[ - (b"stream", [(b"1-0", {})]) - ] - ) + mock_redis.xreadgroup = AsyncMock(return_value=[(b"stream", [(b"1-0", {})])]) broker = RedisBroker.__new__(RedisBroker) broker._redis = mock_redis |
