HttpQuery
Sends an HTTP request.
HttpQuery(url)
HttpQuery(url, options)Examples
-
An example of accessing the OKX public market data API interface.
javascriptfunction main(){ // An example of a GET request without parameters var info = JSON.parse(HttpQuery("https://www.okx.com/api/v5/public/time")) Log(info) // An example of a GET request with parameters var ticker = JSON.parse(HttpQuery("https://www.okx.com/api/v5/market/books?instId=BTC-USDT")) Log(ticker) }pythonimport json import urllib.request def main(): # HttpQuery does not support Python; you can use the urllib/urllib2 library instead info = json.loads(urllib.request.urlopen("https://www.okx.com/api/v5/public/time").read().decode('utf-8')) Log(info) ticker = json.loads(urllib.request.urlopen("https://www.okx.com/api/v5/market/books?instId=BTC-USDT").read().decode('utf-8')) Log(ticker)rustfn main() { // An example of a GET request without parameters; in Rust, the return value type annotation determines whether the Body string (String) or the complete response (HttpRet) is returned let body: String = HttpQuery("https://www.okx.com/api/v5/public/time", None); let info = JSONParse(&body).unwrap(); Log!(info); // An example of a GET request with parameters let body2: String = HttpQuery("https://www.okx.com/api/v5/market/books?instId=BTC-USDT", None); let ticker = JSONParse(&body2).unwrap(); Log!(ticker); }c++void main() { auto info = json::parse(HttpQuery("https://www.okx.com/api/v5/public/time")); Log(info); auto ticker = json::parse(HttpQuery("https://www.okx.com/api/v5/market/books?instId=BTC-USDT")); Log(ticker); } -
An example of using proxy settings with the HttpQuery function.
javascriptfunction main() { // This sets a proxy and sends an HTTP request, with no username and no password; this HTTP request will be sent through the proxy HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/") // This sets a proxy and sends an HTTP request, providing a username and password, effective only for the current call to HttpQuery; subsequent calls to HttpQuery("http://www.baidu.com") will not use the proxy HttpQuery("socks5://username:[email protected]:8889/http://www.baidu.com/") }python# HttpQuery does not support Python; you can use Python's urllib2 libraryrustfn main() { // This sets a proxy and sends an HTTP request, with no username and no password; this HTTP request will be sent through the proxy let ret1: String = HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/", None); // This sets a proxy and sends an HTTP request, providing a username and password, effective only for the current call to HttpQuery; subsequent calls to HttpQuery("http://www.baidu.com") will not use the proxy let ret2: String = HttpQuery("socks5://username:[email protected]:8889/http://www.baidu.com/", None); }c++void main() { HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/"); HttpQuery("socks5://username:[email protected]:8889/http://www.baidu.com/"); }
Returns
| Type | Description |
string / object | Returns the response data of the request. If the return value is a |
Arguments
| Name | Type | Required | Description |
url | string | Yes | The URL of the HTTP request. |
options | object | No | Settings related to the HTTP request, for example the following structure:
All fields in this structure are optional; for example, the |
See Also
Remarks
The HttpQuery() function only supports the JavaScript and C++ languages; in Python, you can use the urllib library to send HTTP requests directly. HttpQuery() is mainly used to access exchange interfaces that do not require signing, such as public interfaces like market data.
In the backtesting system, HttpQuery() can be used to send requests (only GET requests are supported) to obtain data. During backtesting, the number of times different URLs can be accessed is limited to 20, and HttpQuery() caches the accessed data; on the second access to the same URL, the HttpQuery() function returns the cached data instead of making an actual network request.