Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

Sends an HTTP request.

HttpQuery(url)
HttpQuery(url, options)

Examples

  • An example of accessing the OKX public market data API interface.

    javascript
    function 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) }
    python
    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)
    rust
    fn 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.

    javascript
    function 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 library
    rust
    fn 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

TypeDescription

string / object

Returns the response data of the request. If the return value is a JSON string, it can be parsed using the JSON.parse() function in JavaScript strategies, and the json::parse() function in C++ strategies. In the options parameter structure, if debug is set to true, the return value is an object (JSON); if debug is set to false, the return value is a string.

Arguments

NameTypeRequiredDescription

url

string

Yes

The URL of the HTTP request.

options

object

No

Settings related to the HTTP request, for example the following structure:

json
{ method: "POST", body: "a=10&b=20&c=30", charset: "UTF-8", cookie: "session_id=12345; lang=en", debug: false, headers: {"TEST-HTTP-QUERY": "123"}, timeout: 1000 }
  • method: Used to set the request method.
  • body: Used to set the request body content, typically used for requests such as POST and PUT.
  • cookie: Used to set the Cookie in the request, typically used to carry authentication information or session identifiers.
  • headers: Used to set the request header information, which can be used to specify the content type, authentication information, etc.
  • debug: When set to true, this HttpQuery function call returns the complete response message; when set to false, it returns only the data in the response message Body.
  • timeout: Timeout setting; setting it to 1000 means the timeout is 1 second.
  • charset: Supports transcoding the response data of the request, for example: GB18030, supporting common encodings.

All fields in this structure are optional; for example, the headers field may be omitted.

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.