Skip to content

Add WebSocket proxy support for Binance data client #3937

@huangqingchi

Description

@huangqingchi

Problem

BinanceDataClientConfig.proxy_url works for Binance REST requests, for example loading instruments from:

https://fapi.binance.com/fapi/v1/exchangeInfo

However, Binance WebSocket market streams still connect directly to:

wss://fstream.binance.com/...

This causes failures in proxy-only network environments.

Observed behavior

With proxy_url="http://127.0.0.1:9999":

  • REST instrument loading succeeds.
  • DataClient-BINANCE: Connected is logged.
  • subscribe_trade_ticks() then fails when opening the WebSocket connection.

Example error:

WebSocketClientError(IO error: connection attempt failed / os error 10060)                                                                                                                                                                                           
                                                                                                                                                                                                                                                                     
### Expected behavior                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                     
Binance WebSocket clients should support an explicit WebSocket proxy configuration, for example:                                                                                                                                                                     
                                                                                                                                                                                                                                                                     
BinanceDataClientConfig(                                                                                                                                                                                                                                             
    proxy_url="http://127.0.0.1:9999",      # REST                                                                                                                                                                                                                   
    ws_proxy_url="http://127.0.0.1:9999",   # WebSocket                                                                                                                                                                                                              
)                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                     
or another adapter-level config field consistent with the existing config style.                                                                                                                                                                                     
                                                                                                                                                                                                                                                                     
### Why this matters                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                     
In some regions or deployment environments, Binance REST and WebSocket endpoints are only reachable through an HTTP/SOCKS proxy. Currently REST can be proxied, but WebSocket market data cannot.                                                                    
                                                                                                                                                                                                                                                                     
### Verification                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                     
A direct Python websockets.connect(..., proxy="http://127.0.0.1:9999") call can successfully receive Binance Futures aggTrade data from:                                                                                                                             
                                                                                                                                                                                                                                                                     
The failure only occurs through NautilusTrader's Binance WebSocket client because the adapter does not expose or pass a WebSocket proxy option.

### Related issue

Possibly related to:

- https://github.com/nautechsystems/nautilus_trader/issues/3124

That issue added/wired proxy_url for HTTP adapters, but Binance WebSocket market streams still appear to connect directly.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions