38e1d64437
CI / lint-test-build (push) Successful in 2m31s
- Introduced backtesting page and fragment in the dashboard for running backtests and viewing recent reports. - Implemented backtest run logic with configuration options including event path, starting balances, trade capital, and fee profiles. - Added recent backtest reports storage and retrieval. - Created a new strategy module for statistical arbitrage experiments with validation on configuration parameters. - Updated settings to include parameters for the statistical arbitrage strategy. - Enhanced dashboard controls to support the new strategy mode. - Added unit tests for backtesting functionality and strategy validation. - Updated templates for backtesting UI integration.
73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from arbitrade.config.settings import Settings
|
|
|
|
|
|
def test_dashboard_auth_requires_both_fields() -> None:
|
|
with pytest.raises(ValidationError):
|
|
Settings(_env_file=None, DASHBOARD_AUTH_USERNAME="admin")
|
|
|
|
|
|
def test_kraken_api_auth_requires_key_and_secret() -> None:
|
|
with pytest.raises(ValidationError):
|
|
Settings(
|
|
_env_file=None,
|
|
KRAKEN_API_KEY="key-only",
|
|
KRAKEN_API_SECRET="",
|
|
)
|
|
|
|
|
|
def test_kraken_permissions_require_query_and_trade() -> None:
|
|
with pytest.raises(ValidationError):
|
|
Settings(
|
|
_env_file=None,
|
|
KRAKEN_API_KEY="k",
|
|
KRAKEN_API_SECRET="s",
|
|
KRAKEN_API_KEY_PERMISSIONS="query",
|
|
)
|
|
|
|
|
|
def test_kraken_permissions_forbid_withdrawal_scope() -> None:
|
|
with pytest.raises(ValidationError):
|
|
Settings(
|
|
_env_file=None,
|
|
KRAKEN_API_KEY="k",
|
|
KRAKEN_API_SECRET="s",
|
|
KRAKEN_API_KEY_PERMISSIONS="query,trade,withdraw",
|
|
)
|
|
|
|
|
|
def test_alert_min_severity_is_validated() -> None:
|
|
with pytest.raises(ValidationError):
|
|
Settings(_env_file=None, ALERT_MIN_SEVERITY="nope")
|
|
|
|
|
|
def test_valid_security_configuration_passes() -> None:
|
|
settings = Settings(
|
|
_env_file=None,
|
|
KRAKEN_API_KEY="k",
|
|
KRAKEN_API_SECRET="s",
|
|
KRAKEN_API_KEY_PERMISSIONS="query,trade",
|
|
ALERT_MIN_SEVERITY="warning",
|
|
)
|
|
|
|
assert settings.kraken_api_key_permissions == "query,trade"
|
|
|
|
|
|
def test_stat_arb_entry_zscore_must_exceed_exit_zscore() -> None:
|
|
with pytest.raises(ValidationError):
|
|
Settings(
|
|
_env_file=None,
|
|
STRATEGY_STAT_ARB_ENTRY_ZSCORE="0.5",
|
|
STRATEGY_STAT_ARB_EXIT_ZSCORE="0.5",
|
|
)
|
|
|
|
|
|
def test_stat_arb_lookback_window_must_be_at_least_two() -> None:
|
|
with pytest.raises(ValidationError):
|
|
Settings(
|
|
_env_file=None,
|
|
STRATEGY_STAT_ARB_LOOKBACK_WINDOW="1",
|
|
)
|