Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
HttpQuery
HttpQuery_Go
Dial
Mail
Mail_Go
Storage
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Sends an Http request. It is the asynchronous version of the HttpQuery function.

HttpQuery_Go(url)
HttpQuery_Go(url, options)

Examples

Asynchronously access the public interfaces of exchanges to obtain aggregated market data.

javascript
function main() { // Create the first asynchronous thread var r1 = HttpQuery_Go("https://www.okx.com/api/v5/market/tickers?instType=SPOT") // Create the second asynchronous thread var r2 = HttpQuery_Go("https://api.huobi.pro/market/tickers") // Get the return value of the first asynchronous thread call var tickers1 = r1.wait() // Get the return value of the second asynchronous thread call var tickers2 = r2.wait() // Print the results Log("tickers1:", tickers1) Log("tickers2:", tickers2) }
python
def main(): # Create the first asynchronous request r1 = HttpQuery_Go("https://www.okx.com/api/v5/market/tickers?instType=SPOT") # Create the second asynchronous request r2 = HttpQuery_Go("https://api.huobi.pro/market/tickers") # Get the return value of the first asynchronous request tickers1 = r1.wait() # Get the return value of the second asynchronous request tickers2 = r2.wait() # Print the results Log("tickers1:", tickers1) Log("tickers2:", tickers2)
rust
fn main() { // Create the first asynchronous request; the arguments are the same as HttpQuery (None when there are no options) let r1 = HttpQuery_Go("https://www.okx.com/api/v5/market/tickers?instType=SPOT", None); // Create the second asynchronous request let r2 = HttpQuery_Go("https://api.huobi.pro/market/tickers", None); // Get the return value of the first asynchronous request; wait(0) waits until the request completes (JS: wait() with no argument) // The type annotation picks the Body string (String) or the full response (HttpRet) let tickers1: String = r1.wait(0).unwrap_or_default(); // Get the return value of the second asynchronous request let tickers2: String = r2.wait(0).unwrap_or_default(); // Print the results Log!("tickers1:", tickers1); Log!("tickers2:", tickers2); }

Returns

TypeDescription

object

Returns a concurrent object at once; get the result with its wait method. The result, including the value for a failed request, is the same as the return value of HttpQuery. See the remarks for the timeout and repeated calls of wait.

Arguments

NameTypeRequiredDescription

url

string

Yes

The URL of the Http request.

options

object

No

Request settings, all optional, the same as the options of HttpQuery (see HttpQuery-options); with debug true the full response is returned, and timeout is in milliseconds.

See Also

Remarks

The HttpQuery_Go() function supports the JavaScript, Python and Rust languages. The HttpQuery_Go() function is mainly used to access exchange interfaces that do not require a signature, such as public interfaces for market data. The backtesting system does not support the HttpQuery_Go function.

The wait method takes a timeout in milliseconds: omitted or 0 waits until the request completes, -1 does not wait, and a positive number waits at most that long. While the request is still running JavaScript returns undefined and Python returns None, and wait can be called again later; once the result has been taken, another wait throws routine N already finished in JavaScript, while Python logs that error and returns None.

In Rust, wait returns a Result and the type annotation picks the result type (String for the response Body, HttpRet for the full response); while the request is still running it returns Err (routine N not finished) and wait can be called again; once the result has been taken, another wait returns Err (routine N already finished).