@@ -59,12 +59,18 @@ def create_client(exchange_config: Dict[str, Any], *, market_type: str = "swap")
5959 mt = "swap"
6060
6161 if exchange_id == "binance" :
62+ # 检查是否启用模拟交易,支持布尔值和字符串
63+ enable_demo = exchange_config .get ("enable_demo_trading" ) or exchange_config .get ("enableDemoTrading" )
64+ is_demo = bool (enable_demo ) if isinstance (enable_demo , bool ) else str (enable_demo ).lower () in ("true" , "1" , "yes" )
65+
6266 if mt == "spot" :
63- base_url = _get (exchange_config , "base_url" , "baseUrl" ) or "https://api.binance.com"
64- return BinanceSpotClient (api_key = api_key , secret_key = secret_key , base_url = base_url )
65- # Default to USDT-M futures
66- base_url = _get (exchange_config , "base_url" , "baseUrl" ) or "https://fapi.binance.com"
67- return BinanceFuturesClient (api_key = api_key , secret_key = secret_key , base_url = base_url )
67+ default_url = "https://demo-api.binance.com" if is_demo else "https://api.binance.com"
68+ base_url = _get (exchange_config , "base_url" , "baseUrl" ) or default_url
69+ return BinanceSpotClient (api_key = api_key , secret_key = secret_key , base_url = base_url , enable_demo_trading = is_demo )
70+ # Default to USDT-M futures
71+ default_url = "https://demo-fapi.binance.com" if is_demo else "https://fapi.binance.com"
72+ base_url = _get (exchange_config , "base_url" , "baseUrl" ) or default_url
73+ return BinanceFuturesClient (api_key = api_key , secret_key = secret_key , base_url = base_url , enable_demo_trading = is_demo )
6874 if exchange_id == "okx" :
6975 base_url = _get (exchange_config , "base_url" , "baseUrl" ) or "https://www.okx.com"
7076 return OkxClient (api_key = api_key , secret_key = secret_key , passphrase = passphrase , base_url = base_url )
0 commit comments