The exchange.SetContractType()
function is used to set the current contract code of the {@var/EXCHANGE exchange} exchange object.
The exchange.SetContractType()
function returns a structure that contains the exchange contract code corresponding to the current contract code. For example, for the Binance Futures contract exchange, the current contract code is quarter
, and the return value structure of this function is: {"InstrumentID": "BTCUSD_230630", "instrument": "BTCUSD_230630"}
.
object
exchange.SetContractType(symbol)
The symbol
parameter is used to set the contract code, the optional values are: "this_week"
, "next_week"
, "quarter"
, "next_quarter"
, "swap"
, etc.
Cryptocurrency futures contracts delivery contract codes, if not specified, generally have:
this_week
: the current week’s contract.next_week
: the next week’s contract.quarter
: quarterly contract.next_quarter
: the next quarterly contract.
Permanent contracts codes in cryptocurrency futures contracts, if not specified, generally have:swap
: perpetual contract.symbol true string
function main() {
// Set to this week contract
exchange.SetContractType("this_week")
}
def main():
exchange.SetContractType("this_week")
void main() {
exchange.SetContractType("this_week");
}
Set the current contract as the current week’s contract:
function main() {
// The default trading pair is BTC_USD, set the contract for this week, and the contract is a currency standard contract
exchange.SetContractType("this_week")
Log("ticker:", exchange.GetTicker())
// Switching trading pairs, then setting up contracts, switching to USDT as margin contracts, as opposed to currency standard contracts
exchange.IO("currency", "BTC_USDT")
exchange.SetContractType("swap")
Log("ticker:", exchange.GetTicker())
}
def main():
exchange.SetContractType("this_week")
Log("ticker:", exchange.GetTicker())
exchange.IO("currency", "BTC_USDT")
exchange.SetContractType("swap")
Log("ticker:", exchange.GetTicker())
void main() {
exchange.SetContractType("this_week");
Log("ticker:", exchange.GetTicker());
exchange.IO("currency", "BTC_USDT");
exchange.SetContractType("swap");
Log("ticker:", exchange.GetTicker());
}
When setting up a contract with 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):
function main(){
// Set the contract for this week
var ret = exchange.SetContractType("this_week")
// Return information about the current week's contracts
Log(ret)
}
def main():
ret = exchange.SetContractType("this_week")
Log(ret)
void main() {
auto ret = exchange.SetContractType("this_week");
Log(ret);
}
Print the return value of the exchange.SetContractType()
function:
In the cryptocurrency futures contract strategy, take an example of switching to the BTC_USDT
trading pair: When switching trading pairs using the exchange.SetCurrency("BTC_USDT")
or exchange.IO("currency", "BTC_USDT")
functions, after switching, you need to use the exchange.SetContractType()
function to reset the contract in order to determine the current contract to be operated under the new trading pair. The system determines whether it is a currency standard contract or a USDT standard contract based on the trading pair. For example, if a trading pair is set to BTC_USDT
, use the exchange.SetContractType("swap")
function to set the contract code to swap
. At this point, it is set to BTC
for the USDT standard perpetual contract. If the trading pair is BTC_USD
, use the exchange.SetContractType("swap")
function to set the contract code to swap
. At this point, it is set to BTC
's currency standard perpetual contract.
Details of the supported cryptocurrency futures contract exchanges, with contract names for each exchange as follows:
Futures_OKCoin (OKX)
Set to perpetual contracts: exchange.SetContractType("swap")
Set to the contract of this week: exchange.SetContractType("this_week")
Set to next week’s contract: exchange.SetContractType("next_week")
Set to monthly contract: exchange.SetContractType("month")
Set to next month contract: exchange.SetContractType("next_month")
Set to quarterly contracts: exchange.SetContractType("quarter")
Set to next quarter contract: exchange.SetContractType("next_quarter")
OKX has pre-market trading contracts: the contract delivery date is a fixed time. The contract code defined by the exchange is, for example: HMSTR-USDT-250207
. Set the trading pair to HMSTR_USDT
on the FMZ platform, and then use exchange.SetContractType("HMSTR-USDT-250207")
to set the 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 the market data of this contract or place an order.
Futures_HuobiDM (Huobi futures)
Set to the contract of this week: exchange.SetContractType("this_week")
.
Set to next week’s contract: exchange.SetContractType("next_week")
.
Set to quarterly contracts: exchange.SetContractType("quarter")
.
Set to next quarter contract: exchange.SetContractType("next_quarter")
.
Set to perpetual contracts: exchange.SetContractType("swap")
.
It supports contracts with USDT
as margin, take BTC
contract as an example: use exchange.IO("currency", "BTC_USDT")
to switch to a contract that uses USDT
as margin.
Or set the current trading pair to BTC_USDT
directly when configuring live trading parameters and adding exchange objects. After switching trading pairs, you need to call exchange.SetContractType()
function again to set the contract.
Futures_BitMEX (BitMEX)
Set to perpetual contracts: exchange.SetContractType("swap")
.
Futures_BitMEX exchange delivery contracts are monthly contracts with the following contract codes (from January to December):
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
Setting up delivery contracts: exchange.SetContractType("December")
. For example, when the trading pair is set to XBT_USDT
, the exchange.SetContractType("December")
function is called to set the contract for December delivery in the USDT based of BTC (corresponding to the actual contract code of XBTUSDTZ23
).
Futures_BitMEX Contract Information Summary
Contract code defined by Futures_BitMEX | The corresponding trading pair in FMZ | The corresponding contract code in FMZ | Remark |
---|---|---|---|
DOGEUSD | DOGE_USD | swap | USD denominated, XBT settled. XBT is BTC. |
DOGEUSDT | DOGE_USDT | swap | USDT denominated, USDT settled. |
XBTETH | XBT_ETH | swap | ETH denominated, XBT settled. |
XBTEUR | XBT_EUR | swap | EUR-denominated, XBT settled. |
USDTUSDC | USDT_USDC | swap | USDC denominated, XBT settled. |
ETHUSD_ETH | ETH_USD_ETH | swap | USD denominated, ETH settled. |
XBTH24 | XBT_USD | March | Expiration date: March 24, month code is: H; USD denominated, XBT settled. |
ETHUSDZ23 | ETH_USD | December | Expiration date: Dec 23, month code is: Z; USD denominated, XBT settled. |
XBTUSDTZ23 | XBT_USDT | December | Expiration date: December 23, month code is: Z ; USDT denominated, USDT settled. |
ADAZ23 | ADA_XBT | December | Expiration date: December 23, month code is: Z ; XBT billing, XBT settled. |
P_XBTETFX23 | USDT_XXX | P_XBTETFX23 | Expiration: 11/23/23; denominated as a percentage and settled in USDT. |
Futures_GateIO
Set to the contract of this week: exchange.SetContractType("this_week")
.
Set to next week’s contract: exchange.SetContractType("next_week")
.
Set to quarterly contracts: exchange.SetContractType("quarter")
.
Set to next quarter contract: exchange.SetContractType("next_quarter")
.
Set to perpetual contracts: exchange.SetContractType("swap")
.
It supports contracts with USDT
as margin, take BTC
contract as an example: use exchange.IO("currency", "BTC_USDT")
to switch to a contract that uses USDT
as margin.
Or set the current trading pair to BTC_USDT
directly when configuring live trading parameters and adding exchange objects. After switching trading pairs, you need to call exchange.SetContractType()
function again to set the contract.
Futures_Deribit
Set to perpetual contracts: exchange.SetContractType("swap")
.
It supports Deribit’s USDC
contract.
The delivery contracts are: "this_week"
, "next_week"
, "month"
, "quarter"
, "next_quarter"
, "third_quarter"
, "fourth_quarter"
.
CFD (future_combo): "this_week,swap"
, "next_week,swap"
, "next_quarter,this_week"
, "third_quarter,this_week"
, "month,next_week"
, there are many combinations.
For option contracts you need to pass in the specific option contract code defined by the exchange, see the Deribit website for details.
Futures_KuCoin
For example, if the trading pair is set to BTC_USD
and the contract code is set, it is a currency-based contract:
Set to perpetual contracts: exchange.SetContractType("swap")
.
Set to quarterly contracts: exchange.SetContractType("quarter")
.
Set to next quarter contract: exchange.SetContractType("next_quarter")
.
USDT as margin contract:
For example, if the trading pair is set to BTC_USDT
, and then set the contract code, it is a contract with USDT as margin.
Set to perpetual contracts: exchange.SetContractType("swap")
.
Futures_Binance
Binance Futures Exchange defaults to the perpetual contract of the current trading pair, contract code: swap
.
Set to perpetual contracts: exchange.SetContractType("swap")
, the perpetual contracts of Binance have contracts that use USDT
as margin. For example, USDT
standard perpetual contract of BTC
can be used as a margin contract, and the trading pair is set to BTC_USDT
. Binance also supports perpetual contracts that use coins as margin, for example, BTC
's Binance standard perpetual contract, with the trading pair set to BTC_USD
.
Set to quarterly contracts: exchange.SetContractType("quarter")
, the delivery contract has a currency standard contract (i.e., using currencies as margin), for example, BTC
's quarterly contract, the trading pair is set to: BTC_USD
and then set the contract exchange.SetContractType("quarter")
, it is set to BTC
quarterly contract with a currency standard contract.
Set to next quarter contract: exchange.SetContractType("next_quarter")
, for example, BTC
of the currency standard quarterly contract, the trading pair set to: BTC_USD
, and then set the contract exchange.SetContractType("next_quarter")
.
Binance supports partial USDT
as margin delivery contract, take BTC
as an example, set trading pair to BTC_USDT
, then set the contract code.
Support for Binance Options contracts:
The format of the option contract code is based on the option contract code defined by the exchange: BTC-241227-15000-C
, XRP-240112-0.5-C
, BTC-241227-15000-P
. Take the Binance option contract code BTC-241227-15000-P
as an example: BTC is the option currency code, 241227 is the exercise date, 15000 is the exercise price, P represents a put option, and C represents a call option.
For details on the option type, whether it is European option or American option, please refer to the relevant information of the exchange’s option contract.
The exchange may restrict option sellers and require them to apply for qualifications separately. Binance options require seller qualifications.
Futures_Bibox
Contract code for Bibox perpetual contracts: swap
.
Set to perpetual contracts: exchange.SetContractType("swap")
.
Futures_Bybit
The default is the perpetual contract for the current trading pair, contract code: swap
.
This 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
.
Futures_Kraken
The default is the perpetual contract of the current trading pair, contract code: swap
.
swap
: perpetual contract.
month
: current month contract.
quarter
: quarterly contract.
next_quarter
: next quarter contract.
swap_pf
: Mixed margin perpetual contract.
quarter_ff
: Mixed margin quarterly contract.
month_ff
: Mixed margin current month contract.
next_quarter_ff
: Mixed margin next quarter contract.
Futures_Bitfinex
Default is the perpetual contract for the current trading pair, contract code: swap
.
Futures_Bitget
Default is the perpetual contract for the current trading pair, contract code: swap
.
The trading pair is set to BTC_USD
for currency standard contracts, and the trading pair is set to BTC_USDT
for contracts settled by USDT
. Demo contracts can be set up with trading pairs as SBTC_USD
, BTC_SUSDT
.
Futures_dYdX
Contract code for dYdX perpetual contracts: swap
.
Set to perpetual contracts: exchange.SetContractType("swap")
, dYdX has USDT standard contracts only.
Futures_MEXC
Contract code for MEXC perpetual contracts: swap
.
Set to perpetual contracts: exchange.SetContractType("swap")
. Set trading pair to BTC_USD
, which is currency standard contract, and set trading pair to BTC_USDT
, which is USDT
-settled contract.
Futures_Crypto
Tokens in an account on the crypto.com exchange can be converted into USD-denominated credits to be used as margin for contract trading.
Set to perpetual contract: exchange.SetContractType("swap")
. Example of calling the exchange.SetContractType("swap")
function to set a perpetual contract for BTC when the trading pair is set to BTC_USD
.
The crypto.com exchange delivery contracts are monthly contracts with the following contract codes (from January to December):
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
Set the delivery contract: exchange.SetContractType("October")
. For example, when the trading pair is set to BTC_USD
, call the function exchange.SetContractType("October")
to set the October delivery contract for BTC.
The corresponding contract code at the current moment is: BTCUSD-231027
.
Futures_WOO
Futures_WOO exchange supports USDT
based contracts with a perpetual contract code of swap
. For example, when the trading pair is set to BTC_USDT
, the function exchange.SetContractType("swap")
is called to set the current contract to be a USDT based perpetual contract for BTC.
{@fun/Futures/exchange.GetContractType exchange.GetContractType}, {@fun/Account/exchange.SetCurrency exchange.SetCurrency}
exchange.SetDirection exchange.GetContractType