diff --git a/backend_api_python/app/services/live_trading/binance.py b/backend_api_python/app/services/live_trading/binance.py
index 56e4b64..17618d7 100644
--- a/backend_api_python/app/services/live_trading/binance.py
+++ b/backend_api_python/app/services/live_trading/binance.py
@@ -19,7 +19,10 @@
class BinanceFuturesClient(BaseRestClient):
- def __init__(self, *, api_key: str, secret_key: str, base_url: str = "https://fapi.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-fapi.binance.com" if enable_demo_trading else "https://fapi.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()
diff --git a/backend_api_python/app/services/live_trading/binance_spot.py b/backend_api_python/app/services/live_trading/binance_spot.py
index 4288c41..f8ab3e8 100644
--- a/backend_api_python/app/services/live_trading/binance_spot.py
+++ b/backend_api_python/app/services/live_trading/binance_spot.py
@@ -16,7 +16,10 @@
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()
diff --git a/backend_api_python/app/services/live_trading/factory.py b/backend_api_python/app/services/live_trading/factory.py
index fb956a4..21cfebb 100644
--- a/backend_api_python/app/services/live_trading/factory.py
+++ b/backend_api_python/app/services/live_trading/factory.py
@@ -59,12 +59,18 @@ def create_client(exchange_config: Dict[str, Any], *, market_type: str = "swap")
mt = "swap"
if exchange_id == "binance":
+ # 检查是否启用模拟交易,支持布尔值和字符串
+ enable_demo = exchange_config.get("enable_demo_trading") or exchange_config.get("enableDemoTrading")
+ is_demo = bool(enable_demo) if isinstance(enable_demo, bool) else str(enable_demo).lower() in ("true", "1", "yes")
+
if mt == "spot":
- base_url = _get(exchange_config, "base_url", "baseUrl") or "https://api.binance.com"
- return BinanceSpotClient(api_key=api_key, secret_key=secret_key, base_url=base_url)
- # Default to USDT-M futures
- base_url = _get(exchange_config, "base_url", "baseUrl") or "https://fapi.binance.com"
- return BinanceFuturesClient(api_key=api_key, secret_key=secret_key, base_url=base_url)
+ default_url = "https://demo-api.binance.com" if is_demo else "https://api.binance.com"
+ base_url = _get(exchange_config, "base_url", "baseUrl") or default_url
+ return BinanceSpotClient(api_key=api_key, secret_key=secret_key, base_url=base_url, enable_demo_trading=is_demo)
+ # Default to USDT-M futures
+ default_url = "https://demo-fapi.binance.com" if is_demo else "https://fapi.binance.com"
+ base_url = _get(exchange_config, "base_url", "baseUrl") or default_url
+ return BinanceFuturesClient(api_key=api_key, secret_key=secret_key, base_url=base_url, enable_demo_trading=is_demo)
if exchange_id == "okx":
base_url = _get(exchange_config, "base_url", "baseUrl") or "https://www.okx.com"
return OkxClient(api_key=api_key, secret_key=secret_key, passphrase=passphrase, base_url=base_url)
diff --git a/quantdinger_vue/src/views/trading-assistant/index.vue b/quantdinger_vue/src/views/trading-assistant/index.vue
index a4936dc..5d1c280 100644
--- a/quantdinger_vue/src/views/trading-assistant/index.vue
+++ b/quantdinger_vue/src/views/trading-assistant/index.vue
@@ -22,18 +22,15 @@