Files
crypto_trader/tests/unit/strategies/test_moving_avg_strategy.py

46 lines
1.3 KiB
Python

"""Tests for Moving Average strategy."""
import pytest
import pandas as pd
from src.strategies.technical.moving_avg_strategy import MovingAverageStrategy
class TestMovingAverageStrategy:
"""Tests for MovingAverageStrategy."""
@pytest.fixture
def strategy(self):
"""Create Moving Average strategy instance."""
return MovingAverageStrategy(
strategy_id=1,
name="test_ma",
symbol="BTC/USD",
timeframe="1h",
parameters={
"short_period": 10,
"long_period": 30,
"ma_type": "SMA"
}
)
@pytest.mark.asyncio
async def test_ma_strategy_initialization(self, strategy):
"""Test Moving Average strategy initialization."""
assert strategy.short_period == 10
assert strategy.long_period == 30
assert strategy.ma_type == "SMA"
@pytest.mark.asyncio
async def test_generate_signal(self, strategy):
"""Test signal generation."""
# Create data with trend
data = pd.DataFrame({
'close': [100 + i * 0.5 for i in range(50)]
})
strategy.current_data = data
signal = await strategy.generate_signal()
assert "signal" in signal
assert signal["signal"] in ["buy", "sell", "hold"]