feat(V2): URL exchange configurabili da .env (DERIBIT_URL_*, BYBIT_URL_*, ecc.)

This commit is contained in:
AdrianoDev
2026-04-30 20:36:31 +02:00
parent b71c66917c
commit 436dfd6f5a
6 changed files with 141 additions and 13 deletions
+90
View File
@@ -148,6 +148,96 @@ async def test_build_client_sentiment_no_env_distinction(monkeypatch):
assert c_test.lunarcrush_key == c_live.lunarcrush_key
@pytest.mark.asyncio
async def test_deribit_url_from_env_overrides_default(monkeypatch):
"""DERIBIT_URL_TESTNET custom nel .env → builder lo passa al client."""
from tests.unit.test_settings import _minimal_env
env = _minimal_env(DERIBIT_URL_TESTNET="https://custom-test.example.com/api/v2")
for k, v in env.items():
monkeypatch.setenv(k, v)
from cerbero_mcp.exchanges import build_client
from cerbero_mcp.settings import Settings
s = Settings()
c = await build_client(s, "deribit", "testnet")
assert c.base_url == "https://custom-test.example.com/api/v2"
assert "custom-test.example.com" in c.base_url
@pytest.mark.asyncio
async def test_deribit_url_live_from_env_overrides_default(monkeypatch):
from tests.unit.test_settings import _minimal_env
env = _minimal_env(DERIBIT_URL_LIVE="https://custom-live.example.com/api/v2")
for k, v in env.items():
monkeypatch.setenv(k, v)
from cerbero_mcp.exchanges import build_client
from cerbero_mcp.settings import Settings
s = Settings()
c = await build_client(s, "deribit", "mainnet")
assert c.base_url == "https://custom-live.example.com/api/v2"
@pytest.mark.asyncio
async def test_hyperliquid_url_from_env_overrides_default(monkeypatch):
from tests.unit.test_settings import _minimal_env
env = _minimal_env(HYPERLIQUID_URL_TESTNET="https://hl-custom.example.com")
for k, v in env.items():
monkeypatch.setenv(k, v)
from cerbero_mcp.exchanges import build_client
from cerbero_mcp.settings import Settings
s = Settings()
c = await build_client(s, "hyperliquid", "testnet")
assert c.base_url == "https://hl-custom.example.com"
# SDK override deve essere disponibile per init lazy
assert c._base_url_override == "https://hl-custom.example.com"
@pytest.mark.asyncio
async def test_bybit_url_from_env_overrides_default(monkeypatch):
"""Bybit: pybit non accetta `endpoint` come kwarg, ma setting di
`_http.endpoint` post-init rispecchia l'override."""
from tests.unit.test_settings import _minimal_env
env = _minimal_env(BYBIT_URL_TESTNET="https://bybit-custom.example.com")
for k, v in env.items():
monkeypatch.setenv(k, v)
from cerbero_mcp.exchanges import build_client
from cerbero_mcp.settings import Settings
s = Settings()
c = await build_client(s, "bybit", "testnet")
assert c.base_url == "https://bybit-custom.example.com"
# override applicato all'istanza pybit HTTP via attributo `endpoint`
assert getattr(c._http, "endpoint", None) == "https://bybit-custom.example.com"
@pytest.mark.asyncio
async def test_alpaca_url_from_env_overrides_default(monkeypatch):
"""Alpaca: TradingClient supporta url_override per trading API.
Data clients (Stock/Crypto/Option) non supportano override sul costruttore."""
from tests.unit.test_settings import _minimal_env
env = _minimal_env(ALPACA_URL_TESTNET="https://alpaca-custom.example.com")
for k, v in env.items():
monkeypatch.setenv(k, v)
from cerbero_mcp.exchanges import build_client
from cerbero_mcp.settings import Settings
s = Settings()
c = await build_client(s, "alpaca", "testnet")
assert c.base_url == "https://alpaca-custom.example.com"
@pytest.mark.asyncio
async def test_build_client_unknown_exchange_raises(monkeypatch):
from tests.unit.test_settings import _minimal_env