exchange.SetProxy
The exchange.SetProxy() function is used to configure the proxy settings of the exchange exchange object.
exchange.SetProxy(proxy)Examples
-
Configure a
socks5proxy for theexchangeexchange object:javascriptfunction main() { exchange.SetProxy("socks5://192.168.1.10:8080") // If the exchange market data interface cannot be accessed, set an available socks5 proxy to access the market data interface Log(exchange.GetTicker()) }pythondef main(): exchange.SetProxy("socks5://192.168.1.10:8080") Log(exchange.GetTicker())rustfn main() { exchange.SetProxy("socks5://192.168.1.10:8080"); // If the exchange market data interface cannot be accessed, set an available socks5 proxy to access the market data interface Log!(exchange.GetTicker(None)); }c++void main() { exchange.SetProxy("socks5://192.168.1.10:8080"); Log(exchange.GetTicker()); } -
In addition to **globally specifying** the IP address used by the
exchangeexchange object to send requests, specifying the IP address individually based on theexchangeis also supported:javascriptfunction main(){ exchange.SetProxy("ip://10.0.3.15") // The IP address used to send requests is 10.0.3.15 exchange.GetTicker() }pythondef main(): exchange.SetProxy("ip://10.0.3.15") exchange.GetTicker()rustfn main() { exchange.SetProxy("ip://10.0.3.15"); // The IP address used to send requests is 10.0.3.15 let _ = exchange.GetTicker(None); }c++void main() { exchange.SetProxy("ip://10.0.3.15"); exchange.GetTicker(); }
Arguments
| Name | Type | Required | Description |
proxy | string | Yes | The |
See Also
Remarks
If the proxy setting fails, calling the exchange.SetProxy() function will return a null value.
The proxy setting feature of the exchange.SetProxy() function only supports the rest protocol. Each exchange exchange object can be assigned one proxy. Once a proxy is set, all access to the exchange interface bound to that exchange exchange object will go through this proxy.
Setting a socks5 proxy is supported. Taking the first added exchange object exchange (i.e. exchanges[0]) as an example:
-
Set a proxy with no username and no password:
exchange.SetProxy("socks5://127.0.0.1:8889"). -
Set a proxy with a specified username and password:
exchange.SetProxy("socks5://username:[email protected]:8889"), whereusernameis the username andpasswordis the password. -
Switch back to normal mode without using a proxy:
exchange.SetProxy("").
Specifying the IP address used by the exchange exchange object to send requests is supported. For details, see Global specification.