The resource loading... loading...

Special Exchange Instructions

  • Futu Securities It supports FutuNN live trading and demo trading, you need to download FutuOpenD App. When using FutuOpenD to access demo trading, some stock codes are not supported, so you can’t trade, but the FutuOpenD mobile app is able to demo trading. For configuration of exchange objects, running FutuOpenD software, etc. on FMZ Quant, please refer to Futu Securities Configuration Description Document.

    • Frequency of interface calls For GetOrder, GetOrders, GetPositions, GetAccount functions use cached data by default, so there is no limit to the frequency of calls. When new data is available, FutuOpenD will update the data automatically, and cached data will be updated synchronously.

      The exchange.IO("refresh", true) function can be called to disable caching, if disable caching then the frequency of calls is maximum of 10 queries per 30 seconds, exceeding the frequency limit will report an error.

    • Stock code For example: 600519.SH

      • HK
      • US
      • SH
      • SZ

      The strategy code uses the exchange.SetContractType() function to set the stock code, for example:

      function main() {
          var info = exchange.SetContractType("600519.SH")    // Set to stock 600519.SH, namely Kweichow Moutai, and the account will be switched to the China mainland market
          Log(info)
          Log(exchange.GetAccount())                          // The currently set stock is Kweichow Moutai. At this time, call the GetAccount function to obtain the account assets, which are the account assets of the China mainland market
          Log(exchange.GetTicker())                           // Obtain the current price information of Kweichow Moutai stock
      }
      
      def main():
          info = exchange.SetContractType("600519.SH")
          Log(info)
          Log(exchange.GetAccount())
          Log(exchange.GetTicker())
      
      void main() {
          auto info = exchange.SetContractType("600519.SH");
          Log(info);
          Log(exchange.GetAccount());
          Log(exchange.GetTicker());
      }
      

      Functions to set the direction of the transaction exchange.SetDirection, functions to place orders exchange.Buy/exchange.Sell, the withdrawal function exchange.CancelOrder and the query order function exchange.GetOrder are used in the same way as in the futures market.

    • Account information data format: Define the market using TrdMarket to distinguish between Hong Kong Market, United States Market, and China Mainland Market.

      Excerpts from the Futu API documentation:

      const (
          TrdMarket_TrdMarket_Unknown TrdMarket = 0 //Unknown Trading Market
          TrdMarket_TrdMarket_HK      TrdMarket = 1 //Hong Kong Trading Market
          TrdMarket_TrdMarket_US      TrdMarket = 2 //United States Trading Market
          TrdMarket_TrdMarket_CN      TrdMarket = 3 //China Mainland Trading Market
          TrdMarket_TrdMarket_HKCC    TrdMarket = 4 //Hong Kong A-share Trading Market
          TrdMarket_TrdMarket_Futures TrdMarket = 5 //Futures Trading Market
      )
      

      Get account information data, the exchange.GetAccount() function returns:

      {
          "Info": [{
              "Header": {
                  ...                 // omit
                  "TrdMarket": 1      // In the Info raw information, market ID, indicates that the account assets are used for trading in the Hong Kong market
              },
              "Funds": {              // Information on the account's assets in that market
                  ...
              }
          }, ...],
          "Stocks": 0,
          "FrozenStocks": 0,
          "Balance": 1000000,         // Asset values in the current market
          "FrozenBalance": 0
      }
      
    • FutuOpenD distinguish by region based on the logged in IP address There are restrictions on accessing market data for accounts logged in from non-mainland IP addresses, which can be found in the official documentation of FutuOpenD.

  • Futures_Binance It supports the dual position mode of Binance futures; you can use exchange.IO to switch:

    function main() {
        var ret = exchange.IO("api", "POST", "/fapi/v1/positionSide/dual", "dualSidePosition=true")
        // ret : {"code":200,"msg":"success"}
        Log(ret)
    }
    
    def main():
        ret = exchange.IO("api", "POST", "/fapi/v1/positionSide/dual", "dualSidePosition=false")
        Log(ret)
    
    void main() {
        auto ret = exchange.IO("api", "POST", "/fapi/v1/positionSide/dual", "dualSidePosition=true");
        Log(ret);
    }
    

    It supports switching between crossed position/isolated position:

    function main() {
        exchange.SetContractType("swap")
        exchange.IO("cross", true)    // Switch to crossed position
        exchange.IO("cross", false)   // Switch to isolated position
    }
    
    def main():
        exchange.SetContractType("swap")
        exchange.IO("cross", True)
        exchange.IO("cross", False)
    
    void main() {
        exchange.SetContractType("swap");
        exchange.IO("cross", true);
        exchange.IO("cross", false);
    }
    

    It supports for switching to Binance unified account mode:

    function main() {
        exchange.IO("unified", true)   // Switch to unified account mode
        exchange.IO("unified", false)  // Switch to commom mode
    }
    
    def main():
        exchange.IO("unified", True)
        exchange.IO("unified", False)
    
    void main() {
        exchange.IO("unified", true);
        exchange.IO("unified", false);
    }
    

    It supports setting up STP mode for Binance spot/futures orders:

    function main() {
        // "NONE" indicates that STP mode is disabled, other parameters are: "EXPIRE_TAKER", "EXPIRE_MAKER", "EXPIRE_BOTH"
        exchange.IO("selfTradePreventionMode", "NONE")
    }
    
    def main():
        exchange.IO("selfTradePreventionMode", "NONE")
    
    void main() {
        exchange.IO("selfTradePreventionMode", "NONE");
    }
    
  • Futures_HuobiDM

    • Switch address: It supports modifying the address of Huobi Futures participating in the signature, which is not switched by default. If you need to disable the function, you can use exchange.IO("signHost", "") to set an empty string. Use exchange.IO("signHost", "https://aaa.xxx.xxx") to switch the base address of Huobi Futures participating in signature verification. Use exchange.IO("base", "https://bbb.xxx.xxx") or exchange.SetBase("https://bbb.xxx.xxx") to switch the base address of the platform interface.
    • Switch between crossed position/isolated position: When the trading pair is set to XXX_USDT, use the function exchange.SetContractType("swap") to set the contract code to swap perpetual contract, using exchange.IO("cross", true) can switch to USDT-margined perpetual contract in the crossed position mode. Using exchange.IO("cross", false) to switch back to the isolated position mode. The initial default is the isolated position mode.
    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position, and use exchange.IO("dual", false) to switch to a unidirectional position.
  • Huobi

    • Switch special trading pairs: It supports Huobi spot leverage tokens, such as: LINK*(-3); the code defined by the exchange is: link3susdt, which is written when FMZ Quant Trading Platform sets the trading pair LINK3S_USDT. It is also possible to switch trading pairs in the strategy:

      function main() {
          exchange.SetCurrency("LINK3S_USDT")
          Log(exchange.GetTicker())
      }
      
      def main():
          exchange.SetCurrency("LINK3S_USDT")
          Log(exchange.GetTicker())
      
      void main() {
          exchange.SetCurrency("LINK3S_USDT");
          Log(exchange.GetTicker());
      }
      
  • Futures_OKX(Futures_OKCoin/Futures_OKEX)

    • Switch to the demo bot: OKX futures interface can switch to the demo bot testing environment of OKX futures; using exchange.IO("simulate", true) can switch to the simulated trading environment. If you want to switch to the real trading environment, use exchange.IO("simulate", false) to switch. The initial default is the live trading environment.
    • Switch between crossed position/isolated position: It supports switching futures account margin modes; use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode, the initial default is the crossed position mode.
    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position, and use exchange.IO("dual", false) to switch to a unidirectional position.
  • OKX(OKCoin/OKEX)

    • Switch to the demo bot: Use exchange.IO("simulate", true) to switch to the demo bot environment. If you want to switch to the live trading environment, use exchange.IO("simulate", false) to switch to live trading, the initial default is the live trading environment.
  • Futures_Bibox

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to the crossed position mode, and use exchange.IO("cross", false) to switch to the isolated position mode; the initial default is crossed position mode.
    • Unsupported interface: The exchange does not support the query of current pending orders and the interface for querying the historical trading records of the market, so the GetOrders and GetTrades functions are not supported.
  • Futures_Bitget

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position and exchange.IO("dual", false) to switch to a unidirectional position.
  • Futures_MEXC

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
  • Futures_GateIO

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position and exchange.IO("dual", false) to switch to a unidirectional position.
    • Switch the unified account: GateIO futures use exchange.IO("unified", true) to switch unified accounts; use exchange.IO("unified", false) to switch back to non-unified accounts.
  • GateIO

    • Switch the unified account: GateIO spot uses exchange.IO("unified", true) to switch unified accounts; uses exchange.IO("unified", false) to switch back to non-unified accounts.
  • Futures_Bybit

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, use exchange.IO("cross", false) to switch to isolated position mode. Use exchange.IO("unified", true) to switch to unified margin interface, use exchange.IO("unified", false) to switch back to normal contract interface.
    • Switch to the unified margin interface: Use exchange.IO("unified", true) to switch to the unified margin interface, and exchange.IO("unified", false) to switch back to the common contract interface.
    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position and exchange.IO("dual", false) to switch to a unidirectional position.
  • Futures_Pionex

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, use exchange.IO("cross", false) to switch to isolated position mode. Use exchange.IO("dual", true) to switch to bidirectional positions and exchange.IO("dual", false) to switch to unidirectional positions.
    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position and exchange.IO("dual", false) to switch to a unidirectional position.
  • Futures_BitMEX

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
  • BitMEX

    • Market buy order In the BitMEX spot trading order placement interface, the order quantity for a market buy order is not the amount, but the number of coins traded.
  • Bitfinex

    • Market buy order BItfinex spot trading order interface, the order quantity of the market order buy order is not the amount, but the number of trading coins.
  • Futures_Phemex

    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position and exchange.IO("dual", false) to switch to a unidirectional position.
    • K-line interface The exchange K-line interface responds with data that does not contain current Bar data.
    • Switch between crossed position/isolated position: The exchange does not provide an interface to switch between crossed position/isolated position, which needs to be set up on the exchange.
  • Backpack It supports setting the STP mode for Backpack spot orders:

    function main() {
        // "Allow" means to allow self-dealing, "RejectTaker" "RejectMaker" "RejectBoth" "Allow"
        exchange.IO("selfTradePreventionMode", "Allow")
    }
    
    def main():
        exchange.IO("selfTradePreventionMode", "Allow")
    
    void main() {
        exchange.IO("selfTradePreventionMode", "Allow");
    }
    
  • Futures_CoinEx

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
  • Futures_Aevo

    • When placing an order, you need to pass in the signingKey: After connecting to the exchange using a wallet, you can copy the signingKey private key on the exchange’s APIKEY management page. For example, if the private key of signingKey is xxx, use exchange.IO("signingKey", "xxx") to pass it in. Note that signingKey has a time limit. After passing it in, the exchange.IO function returns the public key of signingKey.
  • Futures_Kraken

    • Switch between crossed position/isolated position: Only the multi-collateral contract of Futures_Kraken exchange supports crossed position, isolated position and leverage settings. Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
  • Futures_Crypto

    • Set accountId: Use exchange.IO("accountId", "xxx") to set accountId.
  • Gemini

    • Switch sub-account: Use exchange.IO("subAccount", "xxx") to switch subaccounts.
  • Futures_Aevo

    • Order Id Description: The exchange order Id consists of the actual Id and the order timestamp. The timestamp and the actual order Id are separated by English commas. The purpose is to support the exchange.GetOrder(Id) function to query orders. Since the order timestamp in the data returned by the exchange will change with the order status, if you need to record the order Id and other information locally, please separate the actual order Id record.
  • Futures_dYdX

    • Switch to the test network: dYdX futures interface, you can switch to the test network environment, use exchange.IO("simulate", true), you can switch to the test network environment. If you want to switch to the main network environment, use exchange.IO("simulate", false), the initial default is the main network environment.
    • Set limitFee exchange.IO("limitFee", 0.001)Set the fee rate. The default is 0.001.
    • Set secondsOfValidity exchange.IO("secondsOfValidity", 60 * 60 * 24 * 28) sets the validity period. The default is 60 * 60 * 24 * 28.
  • Futures_WOO

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
    • Switch position unidirection/bidirection: Use exchange.IO("dual", true) to switch to a bidirectional position, and use exchange.IO("dual", false) to switch to a unidirectional position.
  • Futures_KuCoin

    • Switch between crossed position/isolated position: Use exchange.IO("cross", true) to switch to crossed position mode, and use exchange.IO("cross", false) to switch to isolated position mode.
Common Causes for Live Trading Error & Abnormal Exit