refactor(V2): alpaca client da alpaca-py a httpx puro (parità V1)

Riscrive `AlpacaClient` su `httpx.AsyncClient` rimuovendo ogni dipendenza
runtime da `alpaca-py`. 4 endpoint base distinti (trading paper/live,
stock data, crypto data, options data) gestiti via helper `_request`
con header `APCA-API-KEY-ID` / `APCA-API-SECRET-KEY`. Firma costruttore
e attributi pubblici (`paper`, `base_url`) invariati; `base_url` override
applica al solo trading endpoint. Nuovo `aclose()` per cleanup connessioni.

Test riscritti su `pytest-httpx` (29 test alpaca + leverage cap).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
AdrianoDev
2026-05-01 01:38:23 +02:00
parent 6097dde4e4
commit 44c7a18d3e
3 changed files with 705 additions and 273 deletions
+13 -29
View File
@@ -1,39 +1,23 @@
from __future__ import annotations
from unittest.mock import MagicMock
import pytest
from cerbero_mcp.exchanges.alpaca.client import AlpacaClient
@pytest.fixture
def mock_trading():
return MagicMock(name="alpaca_TradingClient")
async def client():
"""AlpacaClient paper su httpx mock (gestito da pytest-httpx)."""
c = AlpacaClient(api_key="test_key", secret_key="test_secret", paper=True)
try:
yield c
finally:
await c.aclose()
@pytest.fixture
def mock_stock():
return MagicMock(name="alpaca_StockHistoricalDataClient")
@pytest.fixture
def mock_crypto():
return MagicMock(name="alpaca_CryptoHistoricalDataClient")
@pytest.fixture
def mock_option():
return MagicMock(name="alpaca_OptionHistoricalDataClient")
@pytest.fixture
def client(mock_trading, mock_stock, mock_crypto, mock_option):
return AlpacaClient(
api_key="test_key",
secret_key="test_secret",
paper=True,
trading=mock_trading,
stock_data=mock_stock,
crypto_data=mock_crypto,
option_data=mock_option,
)
async def client_live():
c = AlpacaClient(api_key="test_key", secret_key="test_secret", paper=False)
try:
yield c
finally:
await c.aclose()