HttpQuery
Send HTTP request.
HttpQuery(url)
HttpQuery(url, options)Examples
-
Example of accessing OKX public market API endpoints.
javascriptfunction main(){ // 一个不带参数的GET请求示例 var info = JSON.parse(HttpQuery("https://www.okx.com/api/v5/public/time")) Log(info) // 一个带参数的GET请求示例 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不支持Python,可以使用urllib/urllib2库替代 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)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); } -
Example of using proxy settings with HttpQuery function.
javascriptfunction main() { // 本次设置代理并发送HTTP请求,无用户名、无密码,此次HTTP请求将通过代理发送 HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/") // 本次设置代理并发送HTTP请求,包含用户名和密码,仅对当前HttpQuery调用生效,后续调用HttpQuery("http://www.baidu.com")将不会使用代理 HttpQuery("socks5://username:[email protected]:8889/http://www.baidu.com/") }python# HttpQuery不支持Python,可以使用Python的urllib2库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 | URL address for the HTTP request. |
options | object | No | HTTP request configuration parameters, can use the following structure:
All fields in this structure are optional, for example, the |
See Also
Remarks
The HttpQuery() function only supports JavaScript and C++ languages. Python language can use the urllib library to send HTTP requests directly. HttpQuery() is mainly used to access exchange interfaces that do not require signatures, 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, access to different URLs is limited to a maximum of 20 times, and HttpQuery() access will cache data. When the same URL is accessed for the second time, the HttpQuery() function returns cached data without initiating an actual network request.