exchange.SetProxy
Sets the proxy configuration of the exchange object.
exchange.SetProxy(proxy)Examples
Configure a socks5 proxy for the exchange object.
javascript
function main() {
exchange.SetProxy("socks5://192.168.1.10:8080")
// If the exchange market data API is unreachable, set a working socks5 proxy to reach it
Log(exchange.GetTicker())
}
python
def main():
exchange.SetProxy("socks5://192.168.1.10:8080")
Log(exchange.GetTicker())
rust
fn main() {
exchange.SetProxy("socks5://192.168.1.10:8080");
// If the exchange market data API is unreachable, set a working socks5 proxy to reach it
Log!(exchange.GetTicker(None));
}Returns
| Type | Description |
bool / null value | Returns |
Arguments
| Name | Type | Required | Description |
proxy | string | Yes | Proxy configuration in the form |
See Also
Remarks
Each exchange object can have one proxy. Once set, the exchange object's network requests to the exchange (REST requests and the WebSocket connections opened by the exchange connector) go through the proxy.
Supported proxy schemes: http://, https://, socks5://, socks5h:// (domain names resolved by the proxy server) and ssocks5:// (socks5 over TLS), all of which can carry a username and password. Taking the first added exchange object exchange, i.e. exchanges[0], as an example:
- Set a proxy without username or password:
exchange.SetProxy("socks5://127.0.0.1:8889"). - Set a proxy with username and password:
exchange.SetProxy("socks5://username:[email protected]:8889"), whereusernameis the username andpasswordis the password. - Switch back to normal mode without a proxy:
exchange.SetProxy("").
Specifying the source IP address of requests per exchange object (the legacy ip:// form) is not supported. To specify the outgoing IP, set it globally with the -I command-line option when starting the docker.