feat(V2): IBKR settings + env-specific credentials
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
@@ -155,3 +157,58 @@ def test_deribit_credentials_missing_raises(monkeypatch, tmp_path):
|
||||
s = Settings()
|
||||
with pytest.raises(ValueError, match="not configured for env=mainnet"):
|
||||
s.deribit.credentials("mainnet")
|
||||
|
||||
|
||||
def test_ibkr_settings_prefer_testnet_specific(monkeypatch, tmp_path):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
for k in list(os.environ):
|
||||
if k.startswith("IBKR_"):
|
||||
monkeypatch.delenv(k, raising=False)
|
||||
|
||||
monkeypatch.setenv("IBKR_CONSUMER_KEY", "base_consumer")
|
||||
monkeypatch.setenv("IBKR_CONSUMER_KEY_TESTNET", "paper_consumer")
|
||||
monkeypatch.setenv("IBKR_ACCESS_TOKEN_TESTNET", "paper_token")
|
||||
monkeypatch.setenv("IBKR_ACCESS_TOKEN_SECRET_TESTNET", "paper_secret")
|
||||
monkeypatch.setenv("IBKR_SIGNATURE_KEY_PATH_TESTNET", "/secrets/sig_paper.pem")
|
||||
monkeypatch.setenv("IBKR_ENCRYPTION_KEY_PATH_TESTNET", "/secrets/enc_paper.pem")
|
||||
monkeypatch.setenv("IBKR_ACCOUNT_ID_TESTNET", "DU1234567")
|
||||
monkeypatch.setenv("IBKR_DH_PRIME", "ffff")
|
||||
|
||||
from cerbero_mcp.settings import IBKRSettings
|
||||
s = IBKRSettings()
|
||||
creds = s.credentials("testnet")
|
||||
assert creds["consumer_key"] == "paper_consumer"
|
||||
assert creds["access_token"] == "paper_token"
|
||||
assert creds["account_id"] == "DU1234567"
|
||||
|
||||
|
||||
def test_ibkr_settings_fallback_to_base(monkeypatch, tmp_path):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
for k in list(os.environ):
|
||||
if k.startswith("IBKR_"):
|
||||
monkeypatch.delenv(k, raising=False)
|
||||
|
||||
monkeypatch.setenv("IBKR_CONSUMER_KEY", "base_consumer")
|
||||
monkeypatch.setenv("IBKR_ACCESS_TOKEN", "base_token")
|
||||
monkeypatch.setenv("IBKR_ACCESS_TOKEN_SECRET", "base_secret")
|
||||
monkeypatch.setenv("IBKR_SIGNATURE_KEY_PATH", "/secrets/sig.pem")
|
||||
monkeypatch.setenv("IBKR_ENCRYPTION_KEY_PATH", "/secrets/enc.pem")
|
||||
monkeypatch.setenv("IBKR_ACCOUNT_ID_TESTNET", "DU1234567")
|
||||
monkeypatch.setenv("IBKR_DH_PRIME", "ffff")
|
||||
|
||||
from cerbero_mcp.settings import IBKRSettings
|
||||
s = IBKRSettings()
|
||||
creds = s.credentials("testnet")
|
||||
assert creds["consumer_key"] == "base_consumer"
|
||||
|
||||
|
||||
def test_ibkr_settings_missing_raises(monkeypatch, tmp_path):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
for k in list(os.environ):
|
||||
if k.startswith("IBKR_"):
|
||||
monkeypatch.delenv(k, raising=False)
|
||||
|
||||
from cerbero_mcp.settings import IBKRSettings
|
||||
s = IBKRSettings()
|
||||
with pytest.raises(ValueError, match="IBKR credentials not configured"):
|
||||
s.credentials("testnet")
|
||||
|
||||
Reference in New Issue
Block a user