NetSettings
exchange.SetBase
The exchange.SetBase() function is used to set the base address of the exchange API interface configured in the exchange exchange object.
exchange.SetBase(s)Examples
javascript
function main() {
// 使用默认基地址
Log(exchange.GetTicker())
// 切换为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())
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
Switching exchange API base addresses is not supported in the backtesting system, as the backtesting system is a sandbox simulation environment and does not actually access the exchange's API interfaces.
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())
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 set the proxy configuration for the exchange exchange object.
exchange.SetProxy(proxy)Examples
-
Configure
socks5proxy forexchangeexchange object:javascriptfunction main() { exchange.SetProxy("socks5://192.168.1.10:8080") // 如果访问不到交易所行情接口,设置一个可用的ss5代理,就可以访问到行情接口了 Log(exchange.GetTicker()) }pythondef main(): exchange.SetProxy("socks5://192.168.1.10:8080") Log(exchange.GetTicker())c++void main() { exchange.SetProxy("socks5://192.168.1.10:8080"); Log(exchange.GetTicker()); } -
In addition to **globally specifying** the IP address for requests sent by the
exchangeexchange object, it also supports specifying IP addresses based onexchange:javascriptfunction main(){ exchange.SetProxy("ip://10.0.3.15") // 发出的请求IP地址为10.0.3.15 exchange.GetTicker() }pythondef main(): exchange.SetProxy("ip://10.0.3.15") exchange.GetTicker()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 null.
The proxy setting functionality of the exchange.SetProxy() function only supports the rest protocol. Each exchange exchange object can set one proxy. After setting the proxy, all access to the exchange interface bound to the exchange exchange object will be accessed through the proxy.
Supports setting socks5 proxy, taking the first added exchange object exchange (i.e., exchanges[0]) as an example:
-
Set proxy (no username, no password):
exchange.SetProxy("socks5://127.0.0.1:8889"). -
Set proxy (with username and password):
exchange.SetProxy("socks5://username:[email protected]:8889"). Whereusernameis the username andpasswordis the password. -
Switch to normal mode (without proxy):
exchange.SetProxy("").
Supports setting the IP address for requests sent by the exchange exchange object, global specification.
exchange.SetTimeout
The exchange.SetTimeout() function is used to set the rest request timeout for 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())
c++
void main() {
exchange.SetTimeout(3000);
Log(exchange.GetTicker());
}Arguments
| Name | Type | Required | Description |
timeout | number | Yes | The |
See Also
Remarks
The parameter timeout is a value in milliseconds, where 1000 milliseconds equals 1 second. It 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 for 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, a timeout will occur, and the function call that times out will return a null value.
SetTimeout() is not a global function, but a method of the exchange exchange object.