57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from llm_trade_bot.config import ConfigError, load_config
|
|
|
|
CONFIG = """
|
|
[deepseek]
|
|
api_key = "deepseek-key"
|
|
[bybit]
|
|
api_key = "bybit-key"
|
|
api_secret = "bybit-secret"
|
|
[telegram]
|
|
api_id = 123
|
|
api_hash = "api-hash"
|
|
bot_token = "bot-token"
|
|
admin_user_ids = [42]
|
|
[brave]
|
|
api_key = "brave-key"
|
|
[schedule]
|
|
timezone = "Europe/Warsaw"
|
|
times = ["09:00", "21:00"]
|
|
[scanner]
|
|
categories = ["spot", "linear"]
|
|
[risk]
|
|
max_risk_per_trade_pct = 2
|
|
max_total_exposure_pct = 40
|
|
max_positions = 5
|
|
max_leverage = 3
|
|
[storage]
|
|
database_path = "state.db"
|
|
"""
|
|
|
|
|
|
def test_loads_and_resolves_database_path(tmp_path: Path):
|
|
path = tmp_path / "config.toml"
|
|
path.write_text(CONFIG, encoding="utf-8")
|
|
config = load_config(path)
|
|
assert config.deepseek.model == "deepseek-flash"
|
|
assert config.telegram.admin_user_ids == frozenset({42})
|
|
assert config.storage.database_path == tmp_path / "state.db"
|
|
|
|
|
|
def test_rejects_risk_above_hard_limit(tmp_path: Path):
|
|
path = tmp_path / "config.toml"
|
|
path.write_text(CONFIG.replace("max_leverage = 3", "max_leverage = 4"), encoding="utf-8")
|
|
with pytest.raises(ConfigError, match="max_leverage"):
|
|
load_config(path)
|
|
|
|
|
|
def test_rejects_non_official_deepseek_endpoint(tmp_path: Path):
|
|
path = tmp_path / "config.toml"
|
|
changed = CONFIG.replace("api_key = \"deepseek-key\"", 'api_key = "deepseek-key"\nbase_url = "https://example.com"', 1)
|
|
path.write_text(changed, encoding="utf-8")
|
|
with pytest.raises(ConfigError, match="base_url"):
|
|
load_config(path)
|