Send an Http request.
Returns the response data of the request. If the return value is a JSON
string, it can be parsed by the JSON.parse()
function in the JavaScript
language strategy, and by the json::parse()
function in the C++
language strategy. If debug is set to true in the options structure, the return value is an object (JSON); if debug is set to false, the return value is a string.
string, object
HttpQuery(url) HttpQuery(url, options)
Http request url. url true string Http request-related settings, for example, can be structured as follows:
{
method: "POST",
body: "a=10&b=20&c=30",
charset: "UTF-8",
cookie: "session_id=12345; lang=en",
profile: "chrome_103",
debug: false,
headers: {"TEST-HTTP-QUERY": "123"},
timeout: 1000
}
tls
fingerprints.
The supported settings include the following options:
chrome_:"chrome_103"
, "chrome_104"
, "chrome_105"
, "chrome_106"
, "chrome_107"
, "chrome_108"
, "chrome_109"
, "chrome_110"
, "chrome_111"
, "chrome_112"
, "chrome_117"
,
safari_:"safari_15_6_1"
, "safari_16_0"
, "safari_ipad_15_6"
, "safari_ios_15_5"
, "safari_ios_15_6"
, "safari_ios_16_0"
,
firefox_:"firefox_102"
, "firefox_104"
, "firefox_105"
, "firefox_106"
, "firefox_108"
, "firefox_110"
, "firefox_117"
,
opera_:"opera_89"
, "opera_90"
, "opera_91"
,
zalando_:"zalando_android_mobile"
, "zalando_ios_mobile"
,
nike_:"nike_ios_mobile"
, "nike_android_mobile"
,
cloudscraper:"cloudscraper"
,
mms_:"mms_ios"
,
mesh_:"mesh_ios"
, "mesh_ios_1"
, "mesh_ios_2"
, "mesh_android"
, "mesh_android_1"
, "mesh_android_2"
,
confirmed_:"confirmed_ios"
, "confirmed_android"
,
okhttp4_:"okhttp4_android_7"
, "okhttp4_android_8"
, "okhttp4_android_9"
, "okhttp4_android_10"
, "okhttp4_android_11"
, "okhttp4_android_12"
, "okhttp4_android_13"
,true
, the HttpQuery
function call returns the full reply message. When it’s set to false
, only the data in the Body
of the reply message is returned.profile
field can be left out.options false object
function main(){
// An example of GET access without parameters
var info = JSON.parse(HttpQuery("https://www.okx.com/api/v5/public/time"))
Log(info)
// An example of GET access with parameters
var ticker = JSON.parse(HttpQuery("https://www.okx.com/api/v5/market/books?instId=BTC-USDT"))
Log(ticker)
}
import 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)
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 accessing the OKX public ticker API interface.
function main() {
// Setting proxy and sending an http request for this time, no username, no password, this http request will be sent through the proxy
HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/")
// Setting proxy and sending an http request for this time, enter the user name and password, only the current call to HttpQuery takes effect, and then call HttpQuery again ("http://www.baidu.com") so that the proxy will not be used.
HttpQuery("socks5://username:password@127.0.0.1:8889/http://www.baidu.com/")
}
# HttpQuery does not support Python, you can use the urllib/urllib2 library instead
void main() {
HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/");
HttpQuery("socks5://username:password@127.0.0.1:8889/http://www.baidu.com/");
}
The HttpQuery function uses proxy settings.
The HttpQuery()
function only supports JavaScript
, C++
language, Python
language can use the urllib
library to send Http requests directly. The HttpQuery()
is mainly used to access the interfaces of the exchange that do not require a signature, such as public interfaces like ticker information. The HttpQuery()
can be used in the backtesting system to send requests (only GET
requests are supported) to obtain data. Backtesting is limited to using 20 visits to different URLs
, and HttpQuery()
visits will cache data. When the same URL
is accessed a second time, the HttpQuery()
function returns the cached data and no more actual network requests occur.
{@fun/Global/HttpQuery_Go HttpQuery_Go}
Dial HttpQuery_Go