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

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).

    javascript
    function main() { exchange.IO("simulate", true) // Switch to demo trading environment // ... trading logic ... exchange.IO("simulate", false) // Switch back to live trading environment }
    python
    def main(): exchange.IO("simulate", True) # ... trading logic ... exchange.IO("simulate", False)
    rust
    fn 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).

    javascript
    function 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 }
    python
    def main(): exchange.IO("dual", True) exchange.IO("dual", False) exchange.SetContractType("swap") exchange.IO("cross", True) exchange.IO("cross", False)
    rust
    fn 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).

    javascript
    function main() { exchange.IO("unified", true) // Switch to unified account mode exchange.IO("unified", false) // Switch to normal mode }
    python
    def main(): exchange.IO("unified", True) exchange.IO("unified", False)
    rust
    fn 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).

    javascript
    function main() { // "NONE" means disable STP mode, other parameters: "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH" exchange.IO("selfTradePreventionMode", "NONE") }
    python
    def main(): exchange.IO("selfTradePreventionMode", "NONE")
    rust
    fn main() { // "NONE" means disable STP mode, other parameters: "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH" let _ = exchange.IO(("selfTradePreventionMode", "NONE")); }

Returns

TypeDescription

string / number / bool / object / array / any

The return value depends on the command. Some commands (e.g. cross and dual on certain exchanges) return a null value even when the call succeeds. On failure, a null value is returned, and the error message can be retrieved with GetLastError.

Arguments

NameTypeRequiredDescription

mode

string

Yes

The command, e.g. simulate, cross, dual. See the table below for the full list of commands.

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.

CommandParameterFunction
simulateboolDemo 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
crossboolCross margin (true) / isolated margin (false)
dualboolHedge mode (true) / one-way mode (false)
unifiedboolUnified account (true) / normal account (false)
trade_marginNoneSwitch to isolated margin trading mode
trade_super_marginNoneSwitch to cross margin trading mode
trade_normalNoneSwitch back to normal spot mode
selfTradePreventionModestringSelf-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.