Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

The exchange.SetContractType() function is used to set the current contract code of the exchange exchange object.

exchange.SetContractType(symbol)

Examples

  • Set the current contract to the current-week contract:

    javascript
    function main() { // Set to the current-week contract exchange.SetContractType("this_week") }
    python
    def main(): exchange.SetContractType("this_week")
    rust
    fn main() { // Set to the current-week contract exchange.SetContractType("this_week").unwrap(); }
    c++
    void main() { exchange.SetContractType("this_week"); }
  • When setting a contract that uses USDT as margin, you need to switch the trading pair in the code (you can also set the trading pair directly when adding the exchange object):

    javascript
    function main() { // The default trading pair is BTC_USD; set the contract to current-week, which is a coin-margined contract exchange.SetContractType("this_week") Log("ticker:", exchange.GetTicker()) // Switch the trading pair, then set the contract, switching to a USDT-margined contract, as distinct from a coin-margined contract exchange.IO("currency", "BTC_USDT") exchange.SetContractType("swap") Log("ticker:", exchange.GetTicker()) }
    python
    def main(): exchange.SetContractType("this_week") Log("ticker:", exchange.GetTicker()) exchange.IO("currency", "BTC_USDT") exchange.SetContractType("swap") Log("ticker:", exchange.GetTicker())
    rust
    fn main() { // The default trading pair is BTC_USD; set the contract to current-week, which is a coin-margined contract exchange.SetContractType("this_week").unwrap(); Log!("ticker:", exchange.GetTicker(None)); // Switch the trading pair, then set the contract, switching to a USDT-margined contract, as distinct from a coin-margined contract exchange.IO(("currency", "BTC_USDT")).unwrap(); exchange.SetContractType("swap").unwrap(); Log!("ticker:", exchange.GetTicker(None)); }
    c++
    void main() { exchange.SetContractType("this_week"); Log("ticker:", exchange.GetTicker()); exchange.IO("currency", "BTC_USDT"); exchange.SetContractType("swap"); Log("ticker:", exchange.GetTicker()); }
  • Print the return value of the exchange.SetContractType() function:

    javascript
    function main(){ // Set the contract to current-week var ret = exchange.SetContractType("this_week") // Returns the information of the current-week contract Log(ret) }
    python
    def main(): ret = exchange.SetContractType("this_week") Log(ret)
    rust
    fn main() { // Set the contract to current-week let ret = exchange.SetContractType("this_week").unwrap(); // Returns the information of the current-week contract Log!(ret); }
    c++
    void main() { auto ret = exchange.SetContractType("this_week"); Log(ret); }

Returns

TypeDescription

object

The exchange.SetContractType() function returns a struct that contains the exchange contract code corresponding to the current contract code. For example, on a Binance Futures contract exchange, when the current contract code is quarter, the return value structure of this function is: {"InstrumentID":"BTCUSD_230630","instrument":"BTCUSD_230630"}.

Arguments

NameTypeRequiredDescription

symbol

string

Yes

The symbol parameter is used to set the contract code. Optional values are: "this_week", "next_week", "quarter", "next_quarter", "swap", etc.

Unless otherwise specified, the codes for delivery contracts in cryptocurrency futures contracts generally include:

  • this_week: Current week contract.

  • next_week: Next week contract.

  • quarter: Current quarter contract.

  • next_quarter: Next quarter contract.

Unless otherwise specified, the codes for perpetual contracts in cryptocurrency futures contracts generally include:

  • swap: Perpetual contract.

See Also

Remarks

In cryptocurrency futures contract strategies, take switching to the BTC_USDT trading pair as an example:

After switching the trading pair using the exchange.SetCurrency("BTC_USDT") or exchange.IO("currency", "BTC_USDT") function, you need to call the exchange.SetContractType() function again to reset the contract, so as to determine the specific contract to operate on under the new trading pair. The system determines whether the contract is a coin-margined contract or a USDT-margined contract based on the trading pair.

For example: when the trading pair is set to BTC_USDT, using the exchange.SetContractType("swap") function to set the contract code to swap sets it to the BTC USDT-margined perpetual contract. If the trading pair is BTC_USD, using the exchange.SetContractType("swap") function to set the contract code to swap sets it to the BTC coin-margined perpetual contract.

Detailed introduction to the cryptocurrency futures contract exchanges supported by the platform. The contract naming conventions for each exchange are as follows:

  • Futures_OKCoin(OKX)
    Set to perpetual contract: exchange.SetContractType("swap")
    Set to current-week contract: exchange.SetContractType("this_week")
    Set to next-week contract: exchange.SetContractType("next_week")
    Set to monthly contract: exchange.SetContractType("month")
    Set to next-month contract: exchange.SetContractType("next_month")
    Set to quarterly contract: exchange.SetContractType("quarter")
    Set to next-quarter contract: exchange.SetContractType("next_quarter")

    OKX offers pre-market trading contracts, whose delivery dates are fixed. Taking the exchange-defined contract code HMSTR-USDT-250207 as an example, first set the trading pair to HMSTR_USDT on the FMZ platform, then use exchange.SetContractType("HMSTR-USDT-250207") to set this contract.
    For functions that support the symbol parameter (such as exchange.GetTicker(), exchange.CreateOrder(), etc.), you can specify the symbol parameter as HMSTR_USDT.HMSTR-USDT-250207 to obtain market data for this contract or to place orders and perform other operations.

  • Futures_HuobiDM (Huobi Futures)
    Set to current-week contract: exchange.SetContractType("this_week").
    Set to next-week contract: exchange.SetContractType("next_week").
    Set to quarterly contract: exchange.SetContractType("quarter").
    Set to next-quarter contract: exchange.SetContractType("next_quarter").
    Set to perpetual contract: exchange.SetContractType("swap").
    Supports contracts using USDT as margin. Taking the BTC contract as an example: call exchange.IO("currency", "BTC_USDT") to switch to a contract using USDT as margin,
    or directly set the current trading pair to BTC_USDT when configuring live trading parameters and adding the exchange object. After switching the trading pair, you must call the exchange.SetContractType() function again to set the contract.

  • Futures_BitMEX (BitMEX)
    Set to perpetual contract: exchange.SetContractType("swap").
    The delivery contracts on the Futures_BitMEX exchange are monthly contracts, with the following contract codes (January through December):

    code
    "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"

    Set a delivery contract: exchange.SetContractType("December"). For example, when the trading pair is set to XBT_USDT, calling the exchange.SetContractType("December") function sets the USDT-margined December delivery contract for BTC (the corresponding actual contract code is XBTUSDTZ23).

    Summary of Futures_BitMEX contract information

    Contract code defined by Futures_BitMEXCorresponding trading pair on FMZCorresponding contract code on FMZRemarks
    DOGEUSDDOGE_USDswapUSD-denominated, XBT-settled. XBT is BTC.
    DOGEUSDTDOGE_USDTswapUSDT-denominated, USDT-settled.
    XBTETHXBT_ETHswapETH-denominated, XBT-settled.
    XBTEURXBT_EURswapEUR-denominated (EUR), XBT-settled.
    USDTUSDCUSDT_USDCswapUSDC-denominated, XBT-settled.
    ETHUSD_ETHETH_USD_ETHswapUSD-denominated, ETH-settled.
    XBTH24XBT_USDMarchExpiry: March 2024, month code H; USD-denominated, XBT-settled.
    ETHUSDZ23ETH_USDDecemberExpiry: December 2023, month code Z; USD-denominated, XBT-settled.
    XBTUSDTZ23XBT_USDTDecemberExpiry: December 2023, month code Z; USDT-denominated, USDT-settled.
    ADAZ23ADA_XBTDecemberExpiry: December 2023, month code Z; XBT-denominated, XBT-settled.
    P_XBTETFX23USDT_XXXP_XBTETFX23Expiry: November 2023; denominated in percentage, USDT-settled.
  • Futures_GateIO
    Set to current-week contract: exchange.SetContractType("this_week").
    Set to next-week contract: exchange.SetContractType("next_week").
    Set to quarterly contract: exchange.SetContractType("quarter").
    Set to next-quarter contract: exchange.SetContractType("next_quarter").
    Set to perpetual contract: exchange.SetContractType("swap").
    Supports contracts using USDT as margin. Taking the BTC contract as an example, call exchange.IO("currency", "BTC_USDT") to switch to a contract using USDT as margin,
    or directly set the current trading pair to BTC_USDT when configuring live trading parameters and adding the exchange object. After switching the trading pair, you must call the exchange.SetContractType() function again to set the contract.

  • Futures_Deribit
    Set to perpetual contract: exchange.SetContractType("swap").
    Supports Deribit's USDC contracts.
    Delivery contracts include: "this_week", "next_week", "month", "quarter", "next_quarter", "third_quarter", "fourth_quarter".
    Spread contracts (future_combo): "this_week,swap", "next_week,swap", "next_quarter,this_week", "third_quarter,this_week", "month,next_week" and various other combinations.
    For options contracts, you need to pass in the specific options contract code defined by the exchange; for details, please refer to the Deribit official website.

  • Futures_KuCoin
    Coin-margined contracts: for example, set the trading pair to BTC_USD, then set the contract code, which yields a coin-margined contract.
    Set to perpetual contract: exchange.SetContractType("swap").
    Set to current-quarter contract: exchange.SetContractType("quarter").
    Set to next-quarter contract: exchange.SetContractType("next_quarter").

    Contracts using USDT as margin:
    For example, set the trading pair to BTC_USDT, then set the contract code, which yields a contract using USDT as margin.
    Set to perpetual contract: exchange.SetContractType("swap").

  • Futures_Binance
    The Binance Futures exchange defaults to the perpetual contract of the current trading pair, with contract code: swap.
    Set to perpetual contract: exchange.SetContractType("swap"). Binance's perpetual contracts support using USDT as margin; for example, for the USDT-margined perpetual contract of BTC, set the trading pair to BTC_USDT; Binance also supports coin-margined perpetual contracts, for example the coin-margined perpetual contract of BTC, for which you set the trading pair to BTC_USD.
    Set to quarterly contract: exchange.SetContractType("quarter"). Delivery contracts include coin-margined contracts (i.e., using the coin as margin); for example, to set the quarterly contract of BTC, set the trading pair to BTC_USD, then call exchange.SetContractType("quarter") to set the coin-margined quarterly contract of BTC.
    Set to next-quarter contract: exchange.SetContractType("next_quarter"). For example, to set the coin-margined next-quarter contract of BTC, set the trading pair to BTC_USD, then call exchange.SetContractType("next_quarter").
    Binance supports some USDT-margined delivery contracts. Taking BTC as an example, set the trading pair to BTC_USDT, then set the contract code.

    Supports Binance options contracts:
    The options contract code format follows the exchange definition, for example BTC-241227-15000-C, XRP-240112-0.5-C, BTC-241227-15000-P. Taking the Binance options contract code BTC-241227-15000-P as an example: BTC is the option's underlying coin code, 241227 is the exercise date, 15000 is the strike price, P indicates a put option, and C indicates a call option.
    For the specific type of option (European or American), please refer to the relevant documentation on the exchange's options contracts.
    The exchange may impose restrictions on option sellers, requiring a separate application for eligibility. Binance options, for instance, require applying for seller eligibility.

  • Futures_Bibox
    Bibox perpetual contract code: swap.
    Set to perpetual contract: exchange.SetContractType("swap").

  • Futures_Bybit
    Defaults to the perpetual contract of the current trading pair, with contract code: swap.
    Current-week contract code: this_week.
    Next-week contract code: next_week.
    Third-week contract code: third_week.
    Monthly contract code: month.
    Next-month contract code: next_month.
    Quarterly contract code: quarter.
    Next-quarter contract code: next_quarter.
    Third-quarter contract code: third_quarter.
    Directly use the exchange's contract naming: for example ETHUSDT-04APR25. Since some contract instruments on the Bybit exchange have no clear periodicity, the exchange-defined contract code is used directly for naming.

  • Futures_Kraken
    Defaults to the perpetual contract of the current trading pair, with contract code: swap.
    swap: perpetual contract.
    month: current-month contract.
    quarter: quarterly contract.
    next_quarter: next-quarter contract.
    third_quarter: third-quarter contract.
    swap_pf: multi-collateral perpetual contract.
    quarter_ff: multi-collateral quarterly contract.
    month_ff: multi-collateral current-month contract.
    next_quarter_ff: multi-collateral next-quarter contract.
    third_quarter_ff: multi-collateral third-quarter contract.
    Directly use the exchange's contract naming: for example FF_ETHUSD_250307. Since some contract instruments on the Kraken exchange have no clear periodicity, the exchange-defined contract code is used directly for naming.

  • Futures_Bitfinex
    Defaults to the perpetual contract of the current trading pair, with contract code: swap.

  • Futures_Bitget
    Defaults to the perpetual contract of the current trading pair, with contract code: swap.
    Setting the trading pair to BTC_USD yields a coin-margined contract, and setting the trading pair to BTC_USDT yields a USDT-settled contract. For simulation contracts, you can set the trading pair to SBTC_USD or BTC_SUSDT.

  • Futures_dYdX (v4)
    dYdX perpetual contract code: swap.
    Set to perpetual contract: exchange.SetContractType("swap"). dYdX has only the USD.swap instrument dimension, and the margin used is USDC.

  • Futures_MEXC
    MEXC perpetual contract code: swap.
    Set to perpetual contract: exchange.SetContractType("swap"). Setting the trading pair to BTC_USD yields a coin-margined contract, and setting the trading pair to BTC_USDT yields a USDT-settled contract.

  • Futures_Crypto
    Tokens in the crypto.com exchange account can be converted into a USD-denominated allowance to be used as margin for contract trading.
    Set to perpetual contract: exchange.SetContractType("swap"). For example, when the trading pair is set to BTC_USD, calling the exchange.SetContractType("swap") function sets the perpetual contract of BTC.
    The delivery contracts on the crypto.com exchange are monthly contracts, with the following contract codes (January through December):

    code
    "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"

    Set a delivery contract: exchange.SetContractType("October"). For example, when the trading pair is set to BTC_USD, calling the exchange.SetContractType("October") function sets the October delivery contract of BTC.
    The contract code corresponding to the current moment is BTCUSD-231027.

  • Futures_WOO
    The Futures_WOO exchange supports USDT-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to BTC_USDT, calling the exchange.SetContractType("swap") function sets the current contract to the USDT-margined perpetual contract of BTC.

  • Futures_Hyperliquid
    The Futures_Hyperliquid exchange supports USDC-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to ETH_USD, calling the exchange.SetContractType("swap") function sets the current contract to the USDC-margined perpetual contract of ETH.
    Futures_Hyperliquid has only the USD.swap instrument dimension, and the margin used is USDC.
    Futures_Hyperliquid supports HIP-3 instruments.

  • Futures_Lighter
    The Futures_Lighter exchange supports USDC-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to BTC_USDC, calling the exchange.SetContractType("swap") function sets the current contract to the USDC-margined perpetual contract of BTC.
    Futures_Lighter supports perpetual contracts only.

  • Futures_Backpack
    The Futures_Backpack exchange supports USDC-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to ETH_USDC, calling the exchange.SetContractType("swap") function sets the current contract to the USDC-margined perpetual contract of ETH.

  • Futures_edgeX
    The Futures_edgeX exchange supports USDT-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to BTC_USDT, calling the exchange.SetContractType("swap") function sets the current contract to the USDT-margined perpetual contract of BTC.

  • Futures_WOOFI
    The Futures_WOOFI exchange supports USDC-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to ETH_USDC, calling the exchange.SetContractType("swap") function sets the current contract to the USDC-margined perpetual contract of ETH.

  • Futures_Coinw
    The Futures_Coinw exchange supports USDT-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to ETH_USDT, calling the exchange.SetContractType("swap") function sets the current contract to the USDT-margined perpetual contract of ETH.

  • Futures_Aster
    The Futures_Aster exchange supports USDT-margined contracts, with perpetual contract code swap. For example, when the trading pair is set to ETH_USDT, calling the exchange.SetContractType("swap") function sets the current contract to the USDT-margined perpetual contract of ETH.

  • Futures_DeepCoin
    Coin-margined contracts: for example, set the trading pair to BTC_USD, then set the contract code, which yields a coin-margined contract.
    Set to perpetual contract: exchange.SetContractType("swap").

    Contracts using USDT as margin:
    For example, set the trading pair to BTC_USDT, then set the contract code, which yields a contract using USDT as margin.
    Set to perpetual contract: exchange.SetContractType("swap").