exchange.IO(mode, value)
Switches the trading mode of an exchange, including demo/live trading, cross/isolated margin, hedge/one-way position mode, unified account, margin trading mode and self-trade prevention.
exchange.IO(mode)
exchange.IO(mode, value)Examples
-
Switch between demo and live trading environments (using
Futures_OKCoin(OKX Futures) as an example).javascriptfunction main() { exchange.IO("simulate", true) // Switch to demo trading environment // ... trading logic ... exchange.IO("simulate", false) // Switch back to live trading environment }pythondef main(): exchange.IO("simulate", True) # ... trading logic ... exchange.IO("simulate", False)rustfn main() { let _ = exchange.IO(("simulate", true)); // Switch to demo trading environment // ... trading logic ... let _ = exchange.IO(("simulate", false)); // Switch back to live trading environment } -
Switch the margin mode and position mode of contracts (using Binance Futures as an example).
javascriptfunction main() { exchange.IO("dual", true) // Switch to hedge mode (dual position) exchange.IO("dual", false) // Switch to one-way mode exchange.SetContractType("swap") exchange.IO("cross", true) // Switch to cross margin exchange.IO("cross", false) // Switch to isolated margin }pythondef main(): exchange.IO("dual", True) exchange.IO("dual", False) exchange.SetContractType("swap") exchange.IO("cross", True) exchange.IO("cross", False)rustfn main() { let _ = exchange.IO(("dual", true)); // Switch to hedge mode (dual position) let _ = exchange.IO(("dual", false)); // Switch to one-way mode let _ = exchange.SetContractType("swap"); let _ = exchange.IO(("cross", true)); // Switch to cross margin let _ = exchange.IO(("cross", false)); // Switch to isolated margin } -
Switch unified account mode (using Binance Futures as an example).
javascriptfunction main() { exchange.IO("unified", true) // Switch to unified account mode exchange.IO("unified", false) // Switch to normal mode }pythondef main(): exchange.IO("unified", True) exchange.IO("unified", False)rustfn main() { let _ = exchange.IO(("unified", true)); // Switch to unified account mode let _ = exchange.IO(("unified", false)); // Switch to normal mode } -
Set the self-trade prevention (STP) mode (using Binance as an example).
javascriptfunction main() { // "NONE" means disable STP mode, other parameters: "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH" exchange.IO("selfTradePreventionMode", "NONE") }pythondef main(): exchange.IO("selfTradePreventionMode", "NONE")rustfn main() { // "NONE" means disable STP mode, other parameters: "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH" let _ = exchange.IO(("selfTradePreventionMode", "NONE")); }
Returns
| Type | Description |
string / number / bool / object / array / any | The return value depends on the command. Some commands (e.g. |
Arguments
| Name | Type | Required | Description |
mode | string | Yes | The command, e.g. |
value | bool / string | No | The value for the command. Its type and meaning are given in the table below. Some commands do not take this parameter. |
See Also
Remarks
General Trading Mode Commands
The following commands are shared by multiple exchanges. For which commands each exchange supports, see the capability matrix. For differences in value meaning, whether a command applies per contract, and return values, see the page for each exchange.
| Command | Parameter | Function |
|---|---|---|
simulate | bool | Demo trading (true) / live trading (false). It is recommended to tick "Demo trading" when adding the exchange; this command is kept only for compatibility with legacy strategies |
cross | bool | Cross margin (true) / isolated margin (false) |
dual | bool | Hedge mode (true) / one-way mode (false) |
unified | bool | Unified account (true) / normal account (false) |
trade_margin | None | Switch to isolated margin trading mode |
trade_super_margin | None | Switch to cross margin trading mode |
trade_normal | None | Switch back to normal spot mode |
selfTradePreventionMode | string | Self-trade prevention (STP) mode |
Demo Trading
Exchanges that support demo trading offer a "Demo trading" checkbox in their configuration when added. Once ticked, the exchange object connects to the demo environment (testnet) from startup, and the strategy does not need to switch. Supported exchanges include: Binance Spot and Futures, Bybit Spot and Futures, OKX Spot and Futures, Bitget Spot and Futures, Gate.io Spot and Futures, Futures_DigiFinex, Hyperliquid Spot and Futures (testnet), Futures_Lighter, and Futu (paper trading account).
exchange.IO("simulate", true/false) can still switch between demo and live trading at runtime for compatibility with legacy strategies (see the support tables for each command below for supported exchanges); new strategies should rely on the checkbox set when adding the exchange. The DigiFinex spot exchange itself does not provide a demo environment.