exchange.IO
Calls other interfaces related to the exchange object.
exchange.IO(k, ...args)Examples
Switch the margin mode and call a raw exchange endpoint (Binance futures as an example).
javascript
function main() {
exchange.SetContractType("swap")
// Switch the current contract to isolated margin
exchange.IO("cross", false)
// The third argument names the contract: switch the ETH_USDT perpetual to cross margin
exchange.IO("cross", true, "ETH_USDT.swap")
// Call an endpoint that has no wrapper function
var ret = exchange.IO("api", "GET", "/fapi/v1/time")
Log(ret)
}
python
def main():
exchange.SetContractType("swap")
exchange.IO("cross", False)
exchange.IO("cross", True, "ETH_USDT.swap")
ret = exchange.IO("api", "GET", "/fapi/v1/time")
Log(ret)
rust
fn main() {
let _ = exchange.SetContractType("swap");
// Switch the current contract to isolated margin
let _ = exchange.IO(("cross", false));
// The third argument names the contract: switch the ETH_USDT perpetual to cross margin
let _ = exchange.IO(("cross", true, "ETH_USDT.swap"));
// Call an endpoint that has no wrapper function
let ret = exchange.IO(("api", "GET", "/fapi/v1/time"));
Log!(ret);
}Returns
| Type | Description |
string / number / bool / object / array / any | The return value depends on the command, and some commands return a null value on success; a failed call returns a null value, and the error message can be obtained with |
Arguments
| Name | Type | Required | Description |
k | string | Yes | Call type identifier. Different values correspond to different functions; please refer to the descriptions in each section below for details. |
args | string / number / bool / object / array / any | No | Extended parameters. Different parameters are passed according to the |
See Also
Remarks
Commands at a glance
| Command | Description |
|---|---|
api | Call a raw exchange endpoint that has no wrapper function |
currency | Switch the trading pair at runtime |
base | Query or switch the API base address |
simulate, cross, dual, unified and more | Switch trading modes, see exchange.IO(mode, value) |
rate / quota | Rate-limit API calls |
Each command has its own page in this category; commands specific to an exchange object are indexed below and documented on the exchange pages (see Capability Matrix).
Return values and error checking
The return value depends on the command. Some commands (for example cross, dual or unified on some futures exchanges) return a null value on success, which is the same as the value returned on failure; to confirm success, read the error message with GetLastError after the call. A command the exchange does not support reports an error (unsupported io method) and returns a null value.
Commands that act on a specific contract, such as cross, dual and unified, accept a symbol argument after the value to name the contract, for example exchange.IO("cross", false, "ETH_USDT.swap"); without it they act on the current trading pair and contract. Whether such a command applies per contract or to the whole account, and what each command returns, is given in the IO command table of the exchange page.
Exchange-specific commands
Commands of exchange.IO() specific to an exchange object; see the exchange page for arguments and details.