diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-02 10:26:52 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-02 10:26:52 +0900 |
| commit | 53cadcf7e34f05f77082e84f0696b56bcbcbae36 (patch) | |
| tree | e02650e10c4d5727bc1e32e27788c17327fa46f7 /shared/tests | |
| parent | f5521da2876a2c19afc24f370b3258f2be95f81a (diff) | |
refactor: remove all crypto/Binance code, update to US stock symbols
Diffstat (limited to 'shared/tests')
| -rw-r--r-- | shared/tests/test_db.py | 12 | ||||
| -rw-r--r-- | shared/tests/test_events.py | 10 | ||||
| -rw-r--r-- | shared/tests/test_models.py | 16 | ||||
| -rw-r--r-- | shared/tests/test_sentiment.py | 136 |
4 files changed, 37 insertions, 137 deletions
diff --git a/shared/tests/test_db.py b/shared/tests/test_db.py index d33dfe1..239ee64 100644 --- a/shared/tests/test_db.py +++ b/shared/tests/test_db.py @@ -10,7 +10,7 @@ def make_candle(): from shared.models import Candle return Candle( - symbol="BTCUSDT", + symbol="AAPL", timeframe="1m", open_time=datetime(2024, 1, 1, tzinfo=timezone.utc), open=Decimal("50000"), @@ -27,7 +27,7 @@ def make_signal(): return Signal( id="sig-1", strategy="ma_cross", - symbol="BTCUSDT", + symbol="AAPL", side=OrderSide.BUY, price=Decimal("50000"), quantity=Decimal("0.1"), @@ -42,7 +42,7 @@ def make_order(): return Order( id="ord-1", signal_id="sig-1", - symbol="BTCUSDT", + symbol="AAPL", side=OrderSide.BUY, type=OrderType.LIMIT, price=Decimal("50000"), @@ -228,7 +228,7 @@ class TestGetCandles: # Create a mock row that behaves like a SA result row mock_row = MagicMock() mock_row._mapping = { - "symbol": "BTCUSDT", + "symbol": "AAPL", "timeframe": "1m", "open_time": datetime(2024, 1, 1, tzinfo=timezone.utc), "open": Decimal("50000"), @@ -248,11 +248,11 @@ class TestGetCandles: db._session_factory = MagicMock(return_value=mock_session) - result = await db.get_candles("BTCUSDT", "1m", 500) + result = await db.get_candles("AAPL", "1m", 500) assert isinstance(result, list) assert len(result) == 1 - assert result[0]["symbol"] == "BTCUSDT" + assert result[0]["symbol"] == "AAPL" mock_session.execute.assert_awaited_once() diff --git a/shared/tests/test_events.py b/shared/tests/test_events.py index ab7792b..6077d93 100644 --- a/shared/tests/test_events.py +++ b/shared/tests/test_events.py @@ -8,7 +8,7 @@ def make_candle(): from shared.models import Candle return Candle( - symbol="BTCUSDT", + symbol="AAPL", timeframe="1m", open_time=datetime(2024, 1, 1, tzinfo=timezone.utc), open=Decimal("50000"), @@ -24,7 +24,7 @@ def make_signal(): return Signal( strategy="test", - symbol="BTCUSDT", + symbol="AAPL", side=OrderSide.BUY, price=Decimal("50000"), quantity=Decimal("0.01"), @@ -40,7 +40,7 @@ def test_candle_event_serialize(): event = CandleEvent(data=candle) d = event.to_dict() assert d["type"] == EventType.CANDLE - assert d["data"]["symbol"] == "BTCUSDT" + assert d["data"]["symbol"] == "AAPL" assert d["data"]["timeframe"] == "1m" @@ -53,7 +53,7 @@ def test_candle_event_deserialize(): d = event.to_dict() restored = CandleEvent.from_raw(d) assert restored.type == EventType.CANDLE - assert restored.data.symbol == "BTCUSDT" + assert restored.data.symbol == "AAPL" assert restored.data.close == Decimal("50500") @@ -65,7 +65,7 @@ def test_signal_event_serialize(): event = SignalEvent(data=signal) d = event.to_dict() assert d["type"] == EventType.SIGNAL - assert d["data"]["symbol"] == "BTCUSDT" + assert d["data"]["symbol"] == "AAPL" assert d["data"]["strategy"] == "test" diff --git a/shared/tests/test_models.py b/shared/tests/test_models.py index 2b8cd5e..04098ce 100644 --- a/shared/tests/test_models.py +++ b/shared/tests/test_models.py @@ -27,7 +27,7 @@ def test_candle_creation(): now = datetime.now(timezone.utc) candle = Candle( - symbol="BTCUSDT", + symbol="AAPL", timeframe="1m", open_time=now, open=Decimal("50000.00"), @@ -36,7 +36,7 @@ def test_candle_creation(): close=Decimal("50500.00"), volume=Decimal("100.5"), ) - assert candle.symbol == "BTCUSDT" + assert candle.symbol == "AAPL" assert candle.timeframe == "1m" assert candle.open == Decimal("50000.00") assert candle.high == Decimal("51000.00") @@ -51,14 +51,14 @@ def test_signal_creation(): signal = Signal( strategy="rsi_strategy", - symbol="BTCUSDT", + symbol="AAPL", side=OrderSide.BUY, price=Decimal("50000.00"), quantity=Decimal("0.01"), reason="RSI oversold", ) assert signal.strategy == "rsi_strategy" - assert signal.symbol == "BTCUSDT" + assert signal.symbol == "AAPL" assert signal.side == OrderSide.BUY assert signal.price == Decimal("50000.00") assert signal.quantity == Decimal("0.01") @@ -75,7 +75,7 @@ def test_order_creation(): signal_id = str(uuid.uuid4()) order = Order( signal_id=signal_id, - symbol="BTCUSDT", + symbol="AAPL", side=OrderSide.BUY, type=OrderType.MARKET, price=Decimal("50000.00"), @@ -94,7 +94,7 @@ def test_signal_conviction_default(): signal = Signal( strategy="rsi", - symbol="BTCUSDT", + symbol="AAPL", side=OrderSide.BUY, price=Decimal("50000"), quantity=Decimal("0.01"), @@ -111,7 +111,7 @@ def test_signal_with_stops(): signal = Signal( strategy="rsi", - symbol="BTCUSDT", + symbol="AAPL", side=OrderSide.BUY, price=Decimal("50000"), quantity=Decimal("0.01"), @@ -130,7 +130,7 @@ def test_position_unrealized_pnl(): from shared.models import Position position = Position( - symbol="BTCUSDT", + symbol="AAPL", quantity=Decimal("0.1"), avg_entry_price=Decimal("50000"), current_price=Decimal("51000"), diff --git a/shared/tests/test_sentiment.py b/shared/tests/test_sentiment.py index 2caa266..9bd8ea3 100644 --- a/shared/tests/test_sentiment.py +++ b/shared/tests/test_sentiment.py @@ -1,23 +1,34 @@ """Tests for market sentiment module.""" -import pytest -from unittest.mock import AsyncMock, MagicMock -from shared.sentiment import SentimentData, SentimentProvider +from shared.sentiment import SentimentData -# --- SentimentData tests --- +def test_sentiment_should_buy_default_no_data(): + s = SentimentData() + assert s.should_buy is True + assert s.should_block is False -def test_sentiment_should_buy_on_fear(): - s = SentimentData(fear_greed_value=15) # Extreme fear +def test_sentiment_should_buy_low_fear_greed(): + s = SentimentData(fear_greed_value=15) assert s.should_buy is True def test_sentiment_should_not_buy_on_greed(): - s = SentimentData(fear_greed_value=75) # Greed + s = SentimentData(fear_greed_value=75) + assert s.should_buy is False + + +def test_sentiment_should_not_buy_negative_news(): + s = SentimentData(news_sentiment=-0.4) assert s.should_buy is False +def test_sentiment_should_buy_positive_news(): + s = SentimentData(fear_greed_value=50, news_sentiment=0.3) + assert s.should_buy is True + + def test_sentiment_should_block_extreme_greed(): s = SentimentData(fear_greed_value=85) assert s.should_block is True @@ -31,114 +42,3 @@ def test_sentiment_should_block_very_negative_news(): def test_sentiment_no_block_on_neutral(): s = SentimentData(fear_greed_value=50, news_sentiment=0.0) assert s.should_block is False - - -def test_sentiment_should_buy_default_no_data(): - s = SentimentData() - assert s.should_buy is True - assert s.should_block is False - - -def test_sentiment_positive_news_allows_buy(): - s = SentimentData(fear_greed_value=50, news_sentiment=0.3) - assert s.should_buy is True - - -def test_sentiment_outflow_bullish(): - s = SentimentData(exchange_netflow=-100.0) # Outflow = bullish - assert s.should_buy is True - - -def test_sentiment_inflow_bearish(): - s = SentimentData(fear_greed_value=50, exchange_netflow=100.0) # Inflow = bearish - assert s.should_buy is False - - -# --- SentimentProvider tests --- - - -@pytest.mark.asyncio -async def test_provider_fetch_fear_greed(): - provider = SentimentProvider() - - mock_response = AsyncMock() - mock_response.status = 200 - mock_response.json = AsyncMock( - return_value={"data": [{"value": "25", "value_classification": "Extreme Fear"}]} - ) - mock_response.__aenter__ = AsyncMock(return_value=mock_response) - mock_response.__aexit__ = AsyncMock(return_value=False) - - mock_session = MagicMock() - mock_session.closed = False - mock_session.get = MagicMock(return_value=mock_response) - mock_session.close = AsyncMock() - provider._session = mock_session - - value, label = await provider.fetch_fear_greed() - assert value == 25 - assert label == "Extreme Fear" - - await provider.close() - - -@pytest.mark.asyncio -async def test_provider_fetch_fear_greed_failure(): - provider = SentimentProvider() - - mock_response = AsyncMock() - mock_response.status = 500 - mock_response.__aenter__ = AsyncMock(return_value=mock_response) - mock_response.__aexit__ = AsyncMock(return_value=False) - - mock_session = MagicMock() - mock_session.closed = False - mock_session.get = MagicMock(return_value=mock_response) - mock_session.close = AsyncMock() - provider._session = mock_session - - value, label = await provider.fetch_fear_greed() - assert value is None - - await provider.close() - - -@pytest.mark.asyncio -async def test_provider_news_disabled_without_key(): - provider = SentimentProvider(cryptopanic_api_key="") - score, count = await provider.fetch_news_sentiment() - assert score is None - assert count == 0 - - -@pytest.mark.asyncio -async def test_provider_netflow_disabled_without_key(): - provider = SentimentProvider(cryptoquant_api_key="") - result = await provider.fetch_exchange_netflow() - assert result is None - - -@pytest.mark.asyncio -async def test_provider_get_sentiment_aggregates(): - provider = SentimentProvider() - - mock_response = AsyncMock() - mock_response.status = 200 - mock_response.json = AsyncMock( - return_value={"data": [{"value": "20", "value_classification": "Extreme Fear"}]} - ) - mock_response.__aenter__ = AsyncMock(return_value=mock_response) - mock_response.__aexit__ = AsyncMock(return_value=False) - - mock_session = MagicMock() - mock_session.closed = False - mock_session.get = MagicMock(return_value=mock_response) - mock_session.close = AsyncMock() - provider._session = mock_session - - sentiment = await provider.get_sentiment("SOL") - assert sentiment.fear_greed_value == 20 - assert sentiment.fear_greed_label == "Extreme Fear" - assert provider.cached is sentiment - - await provider.close() |
