NetSettings
exchange.SetBase
The exchange.SetBase() function is used to set the base URL of the exchange API interface used by the exchange exchange object.
exchange.SetBase(s)Examples
javascript
function main() {
// Use the default base URL
Log(exchange.GetTicker())
// Switch to https://aws.okx.com
exchange.SetBase("https://aws.okx.com")
Log(exchange.GetTicker())
}
python
def main():
Log(exchange.GetTicker())
exchange.SetBase("https://aws.okx.com")
Log(exchange.GetTicker())
rust
fn main() {
// Use the default base URL
Log!(exchange.GetTicker(None));
// Switch to https://aws.okx.com
exchange.SetBase("https://aws.okx.com");
Log!(exchange.GetTicker(None));
}
c++
void main() {
Log(exchange.GetTicker());
exchange.SetBase("https://aws.okx.com");
Log(exchange.GetTicker());
}Arguments
| Name | Type | Required | Description |
s | string | Yes | The |
See Also
Remarks
The backtesting system does not support switching the base URL of the exchange API interface, because the backtesting system is a sandbox simulation environment and does not actually access the exchange's API interface.
exchange.GetBase
The exchange.GetBase() function is used to get the base address of the current exchange API interface.
exchange.GetBase()Examples
javascript
function main() {
Log(exchange.GetBase())
}
python
def main():
Log(exchange.GetBase())
rust
fn main() {
Log!(exchange.GetBase());
}
c++
void main() {
Log(exchange.GetBase());
}Returns
| Type | Description |
string | The base address of the current exchange API interface. |
See Also
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.
exchange.SetTimeout
The exchange.SetTimeout() function is used to set the timeout for rest requests of the exchange exchange object.
exchange.SetTimeout(timeout)Examples
javascript
function main() {
exchange.SetTimeout(3000)
Log(exchange.GetTicker())
}
python
def main():
exchange.SetTimeout(3000)
Log(exchange.GetTicker())
rust
fn main() {
exchange.SetTimeout(3000);
Log!(exchange.GetTicker(None));
}
c++
void main() {
exchange.SetTimeout(3000);
Log(exchange.GetTicker());
}Arguments
| Name | Type | Required | Description |
timeout | number | Yes | The |
See Also
Remarks
The timeout parameter is a value in milliseconds, where 1000 milliseconds equals 1 second. This setting only applies to the rest protocol and is used to set the timeout for rest requests; it only needs to be set once to take effect. For example: exchange.SetTimeout(3000) sets the rest request timeout of the exchange exchange object to 3 seconds; when calling functions that involve network requests such as exchange.GetTicker(), if no response is received within 3 seconds, it is determined to be a timeout, and the timed-out function call will return a null value.
SetTimeout() is not a global function, but a method of the exchange exchange object.