Files
crypto_trading/backend/tests/test_indicators.py
T
matitos 9c3bee87ac
CI/CD / backend (push) Successful in 5m18s
CI/CD / frontend (push) Successful in 5m2s
CI/CD / build (push) Successful in 34s
CI/CD / cleanup (push) Successful in 6s
CI/CD / deploy (push) Successful in 22s
Crypto trading bot: engine, brokers, backtester, dashboard, deploy
FastAPI backend with a single-strategy async engine, paper and Binance
brokers, pure-python indicators, a backtester that shares the engine's
portfolio math, and a Vue dashboard with a live WebSocket feed. Adds the
Gitea Actions CI/CD workflow that deploys to Traefik via docker_default.
2026-09-18 17:02:33 +00:00

41 lines
1009 B
Python

from __future__ import annotations
import pytest
from app.engine.indicators import atr, ema, rolling_std, rsi, sma
from app.schemas import Candle
def candle(high: float, low: float, close: float, open_: float | None = None) -> Candle:
return Candle(
ts=0,
open=open_ if open_ is not None else close,
high=high,
low=low,
close=close,
volume=1,
)
def test_sma() -> None:
assert sma([1, 2, 3, 4, 5], 3) == [None, None, 2.0, 3.0, 4.0]
def test_ema() -> None:
assert ema([1, 2, 3, 4, 5], 3) == [None, None, 2.0, 3.0, 4.0]
def test_rsi_monotonic_is_100() -> None:
values = [float(i) for i in range(1, 20)]
assert rsi(values, 14)[-1] == pytest.approx(100.0)
def test_atr_flat_market_is_zero() -> None:
candles = [candle(100, 100, 100) for _ in range(20)]
assert atr(candles, 5)[-1] == pytest.approx(0.0)
def test_rolling_std() -> None:
result = rolling_std([1, 1, 1, 1], 2)
assert result[-1] == pytest.approx(0.0)