summaryrefslogtreecommitdiff
path: root/services/data-collector/tests/test_binance_rest.py
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-01 15:56:35 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2026-04-01 15:56:35 +0900
commit33b14aaa2344b0fd95d1629627c3d135b24ae102 (patch)
tree90b214758bc3b076baa7711226a1a1be6268e72e /services/data-collector/tests/test_binance_rest.py
parent9360f1a800aa29b40399a2f3bfbfcf215a04e279 (diff)
feat: initial trading platform implementation
Binance spot crypto trading platform with microservices architecture: - shared: Pydantic models, Redis Streams broker, asyncpg DB layer - data-collector: Binance WebSocket/REST market data collection - strategy-engine: Plugin-based strategy execution (RSI, Grid) - order-executor: Order execution with risk management - portfolio-manager: Position tracking and PnL calculation - backtester: Historical strategy testing with simulator - cli: Click-based CLI for all operations - Docker Compose orchestration with Redis and PostgreSQL - 24 test files covering all modules
Diffstat (limited to 'services/data-collector/tests/test_binance_rest.py')
-rw-r--r--services/data-collector/tests/test_binance_rest.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/services/data-collector/tests/test_binance_rest.py b/services/data-collector/tests/test_binance_rest.py
new file mode 100644
index 0000000..695dcf9
--- /dev/null
+++ b/services/data-collector/tests/test_binance_rest.py
@@ -0,0 +1,53 @@
+"""Tests for binance_rest module."""
+import pytest
+from decimal import Decimal
+from unittest.mock import AsyncMock, MagicMock
+from datetime import datetime, timezone
+
+from data_collector.binance_rest import fetch_historical_candles
+
+
+@pytest.mark.asyncio
+async def test_fetch_historical_candles_parses_response():
+ """Verify that OHLCV rows are correctly parsed into Candle models."""
+ ts = 1700000000000 # milliseconds
+ mock_exchange = MagicMock()
+ mock_exchange.fetch_ohlcv = AsyncMock(
+ return_value=[
+ [ts, 30000.0, 30100.0, 29900.0, 30050.0, 1.5],
+ [ts + 60000, 30050.0, 30200.0, 30000.0, 30150.0, 2.0],
+ ]
+ )
+
+ candles = await fetch_historical_candles(
+ mock_exchange, "BTC/USDT", "1m", since=ts, limit=500
+ )
+
+ assert len(candles) == 2
+
+ c = candles[0]
+ assert c.symbol == "BTCUSDT"
+ assert c.timeframe == "1m"
+ assert c.open_time == datetime.fromtimestamp(ts / 1000, tz=timezone.utc)
+ assert c.open == Decimal("30000.0")
+ assert c.high == Decimal("30100.0")
+ assert c.low == Decimal("29900.0")
+ assert c.close == Decimal("30050.0")
+ assert c.volume == Decimal("1.5")
+
+ mock_exchange.fetch_ohlcv.assert_called_once_with(
+ "BTC/USDT", "1m", since=ts, limit=500
+ )
+
+
+@pytest.mark.asyncio
+async def test_fetch_historical_candles_empty_response():
+ """Verify that an empty exchange response returns an empty list."""
+ mock_exchange = MagicMock()
+ mock_exchange.fetch_ohlcv = AsyncMock(return_value=[])
+
+ candles = await fetch_historical_candles(
+ mock_exchange, "BTC/USDT", "1m", since=1700000000000
+ )
+
+ assert candles == []