Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
exchange.IO
exchange.IO("api", ...)
exchange.IO("currency", ...)
exchange.IO("base", ...)
exchange.IO(mode, value)
exchange.IO("rate", ...)
Network
Storage
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Calls a raw REST endpoint of the exchange that has no wrapper function; the platform signs the request. On a Web3 exchange object the command of the same name calls smart contracts, see exchange.IO("api", ...).

exchange.IO(k, httpMethod, resource)
exchange.IO(k, httpMethod, resource, params)
exchange.IO(k, httpMethod, resource, params, raw)

Examples

  • Use the api mode to call the Futures_OKCoin (OKX futures) batch order placement interface, and pass the JSON-formatted order data via the raw parameter.

    javascript
    function main() { var arrOrders = [ {"instId":"BTC-USDT-SWAP","tdMode":"cross","side":"buy","ordType":"limit","px":"16000","sz":"1","posSide":"long"}, {"instId":"BTC-USDT-SWAP","tdMode":"cross","side":"buy","ordType":"limit","px":"16000","sz":"2","posSide":"long"} ] // Call exchange.IO to directly access the exchange's batch order placement interface var ret = exchange.IO("api", "POST", "/api/v5/trade/batch-orders", "", JSON.stringify(arrOrders)) Log(ret) }
    python
    import json def main(): arrOrders = [ {"instId":"BTC-USDT-SWAP","tdMode":"cross","side":"buy","ordType":"limit","px":"16000","sz":"1","posSide":"long"}, {"instId":"BTC-USDT-SWAP","tdMode":"cross","side":"buy","ordType":"limit","px":"16000","sz":"2","posSide":"long"} ] ret = exchange.IO("api", "POST", "/api/v5/trade/batch-orders", "", json.dumps(arrOrders)) Log(ret)
    rust
    fn main() { // Rust has no JSON serialization; construct the order array directly using a raw string let arrOrders = r#"[ {"instId":"BTC-USDT-SWAP","tdMode":"cross","side":"buy","ordType":"limit","px":"16000","sz":"1","posSide":"long"}, {"instId":"BTC-USDT-SWAP","tdMode":"cross","side":"buy","ordType":"limit","px":"16000","sz":"2","posSide":"long"} ]"#; // Call exchange.IO to directly access the exchange's batch order placement interface; multiple parameters are passed in as a tuple let ret = exchange.IO(("api", "POST", "/api/v5/trade/batch-orders", "", arrOrders)); Log!(ret); }
  • When the value of a key in the params parameter is of string type, you need to wrap the parameter value with single quotes.

    javascript
    var amount = 1 var price = 10 var basecurrency = "ltc" function main () { // Note that there is a ' character on both the left and right sides of amount.toString() and price.toString() var message = "symbol=" + basecurrency + "&amount='" + amount.toString() + "'&price='" + price.toString() + "'&side=buy" + "&type=limit" var id = exchange.IO("api", "POST", "/v1/order/new", message) }
    python
    amount = 1 price = 10 basecurrency = "ltc" def main(): message = "symbol=" + basecurrency + "&amount='" + str(amount) + "'&price='" + str(price) + "'&side=buy" + "&type=limit" id = exchange.IO("api", "POST", "/v1/order/new", message)
    rust
    fn main() { let amount = 1; let price = 10; let basecurrency = "ltc"; // Note that there is a ' character on both the left and right sides of the amount and price parameter values let message = format!("symbol={}&amount='{}'&price='{}'&side=buy&type=limit", basecurrency, amount, price); let id = exchange.IO(("api", "POST", "/v1/order/new", message)); }
  • The resource parameter supports passing in a complete URL.

    javascript
    function main() { var ret = exchange.IO("api", "GET", "https://www.okx.com/api/v5/account/max-withdrawal", "ccy=BTC") Log(ret) }
    python
    def main(): ret = exchange.IO("api", "GET", "https://www.okx.com/api/v5/account/max-withdrawal", "ccy=BTC") Log(ret)
    rust
    fn main() { let ret = exchange.IO(("api", "GET", "https://www.okx.com/api/v5/account/max-withdrawal", "ccy=BTC")); Log!(ret); }
  • A GET request that does not use the raw parameter.

    javascript
    function main(){ var ret = exchange.IO("api", "GET", "/api/v5/trade/orders-pending", "instType=SPOT") Log(ret) }
    python
    def main(): ret = exchange.IO("api", "GET", "/api/v5/trade/orders-pending", "instType=SPOT") Log(ret)
    rust
    fn main() { let ret = exchange.IO(("api", "GET", "/api/v5/trade/orders-pending", "instType=SPOT")); Log!(ret); }

Returns

TypeDescription

object / array / string / null value

Returns the full response of the endpoint; a response that is not JSON is returned as a string. Returns a null value on failure. Live trading only.

Arguments

NameTypeRequiredDescription

k

string

Yes

Selects the exchange.IO() feature; api calls a raw exchange endpoint.

httpMethod

string

Yes

HTTP method, e.g. GET, POST, DELETE.

resource

string

Yes

Endpoint path; a full URL also works (its host replaces the current base address).

params

string

No

URL-encoded request parameters.

raw

string

No

Raw request body, e.g. a JSON string.

See Also

Remarks

Directly Calling Exchange APIs (api mode)
javascript
exchange.IO("api", httpMethod, resource, params, raw)

Used to call the exchange's native API endpoints that are not wrapped by FMZ. FMZ automatically handles signature verification; you only need to fill in the request parameters.

ParameterTypeRequiredDescription
httpMethodstringYesGET, POST, etc.
resourcestringYesRequest path or full URL
paramsstringNoRequest parameters in URL-encoded format
rawstringNoRaw request body (JSON, etc.)

Returns a null value on failure, and this mode is only supported in live trading.