feat: 添加 Binance 模拟交易支持

在 BinanceFuturesClient 和 BinanceSpotClient 中添加 enable_demo_trading 参数

根据 enable_demo_trading 自动设置正确的 demo base_url

Futures: https://demo-fapi.binance.com

Spot: https://demo-api.binance.com

在 factory.py 中从 exchange_config 读取 enable_demo_trading 配置并传递给客户端
This commit is contained in:
XSX-Milan
2026-01-27 19:28:34 +08:00
parent 0bf4bb5bd9
commit bc1c991645
4 changed files with 197 additions and 251 deletions
@@ -16,7 +16,10 @@ from app.services.live_trading.symbols import to_binance_futures_symbol
class BinanceSpotClient(BaseRestClient):
def __init__(self, *, api_key: str, secret_key: str, base_url: str = "https://api.binance.com", timeout_sec: float = 15.0):
def __init__(self, *, api_key: str, secret_key: str, base_url: str = None, enable_demo_trading: bool = False, timeout_sec: float = 15.0):
if not base_url:
base_url = "https://demo-api.binance.com" if enable_demo_trading else "https://api.binance.com"
super().__init__(base_url=base_url, timeout_sec=timeout_sec)
self.api_key = (api_key or "").strip()
self.secret_key = (secret_key or "").strip()