60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
|
|
"""Tests for Divergence strategy."""
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from decimal import Decimal
|
||
|
|
from src.strategies.technical.divergence_strategy import DivergenceStrategy
|
||
|
|
from src.strategies.base import SignalType
|
||
|
|
|
||
|
|
|
||
|
|
class TestDivergenceStrategy:
|
||
|
|
"""Tests for DivergenceStrategy."""
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def strategy(self):
|
||
|
|
"""Create Divergence strategy instance."""
|
||
|
|
return DivergenceStrategy(
|
||
|
|
name="test_divergence",
|
||
|
|
parameters={
|
||
|
|
'indicator_type': 'rsi',
|
||
|
|
'rsi_period': 14,
|
||
|
|
'lookback': 20,
|
||
|
|
'min_swings': 2,
|
||
|
|
'min_confidence': 0.5
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_initialization(self, strategy):
|
||
|
|
"""Test strategy initialization."""
|
||
|
|
assert strategy.indicator_type == 'rsi'
|
||
|
|
assert strategy.rsi_period == 14
|
||
|
|
assert strategy.lookback == 20
|
||
|
|
assert strategy.min_swings == 2
|
||
|
|
assert strategy.min_confidence == 0.5
|
||
|
|
|
||
|
|
def test_on_tick_insufficient_data(self, strategy):
|
||
|
|
"""Test that strategy returns None with insufficient data."""
|
||
|
|
signal = strategy.on_tick(
|
||
|
|
symbol="BTC/USD",
|
||
|
|
price=Decimal("50000"),
|
||
|
|
timeframe="1h",
|
||
|
|
data={'volume': 1000}
|
||
|
|
)
|
||
|
|
assert signal is None
|
||
|
|
|
||
|
|
def test_indicator_type_selection(self, strategy):
|
||
|
|
"""Test indicator type selection."""
|
||
|
|
assert strategy.indicator_type == 'rsi'
|
||
|
|
|
||
|
|
# Test MACD indicator type
|
||
|
|
macd_strategy = DivergenceStrategy(
|
||
|
|
name="test_divergence_macd",
|
||
|
|
parameters={'indicator_type': 'macd'}
|
||
|
|
)
|
||
|
|
assert macd_strategy.indicator_type == 'macd'
|
||
|
|
|
||
|
|
def test_strategy_metadata(self, strategy):
|
||
|
|
"""Test strategy metadata."""
|
||
|
|
assert strategy.name == "test_divergence"
|
||
|
|
assert strategy.enabled is False
|
||
|
|
|