The exchange.SetMarginLevel()
function is used to set the leverage value of the trading pair or contract specified by the symbol
parameter. Compatible with only passing in the parameter marginLevel
to set the leverage value of the current trading pair or contract of the {@var/EXCHANGE exchange} exchange object.
exchange.SetMarginLevel(symbol, marginLevel) exchange.SetMarginLevel(marginLevel)
The symbol
parameter is used to specify the trading pair or contract for which the leverage value needs to be adjusted. The format of the symbol
parameter of the SetMarginLevel()
function is consistent with the format of the symbol
parameter of the GetTicker()
function.
symbol
false
string
The marginLevel
parameter is used to set the leverage value, which is usually an integer for exchanges and it also supports floating point leverage value settings for some exchanges.
marginLevel
true
number
function main() {
exchange.SetMarginLevel(10)
// Set the leverage of BTC’s USDT-margined perpetual contract to 15
exchange.SetMarginLevel("BTC_USDT.swap", 15)
}
def main():
exchange.SetMarginLevel(10)
exchange.SetMarginLevel("BTC_USDT.swap", 15)
void main() {
exchange.SetMarginLevel(10);
exchange.SetMarginLevel("BTC_USDT.swap", 15);
}
The exchange.SetMarginLevel()
function supports cryptocurrency futures contract exchange objects only. The backtesting system supports calling the exchange.SetMarginLevel()
function to set the leverage value.
For cryptocurrency futures contracts, the leverage mechanism is not uniform due to the cryptocurrency futures contract exchanges. In some exchanges, the leverage value of the futures contract is a parameter in the order placement interface, when calling the exchange.SetMarginLevel()
function does not generate a network request, but only sets the leverage variable in the underlying FMZ system (used for passing parameters in the order placement interface). The leverage value of some exchange futures contracts is a setting of the exchange, which needs to be set on the exchange website page or using the API interface. In this case calling the exchange.SetMarginLevel()
function will generate a network request and may fail to set leverage. There can be many reasons for this, for example: there is a current position or pending order, which makes it impossible to set a new leverage value for this trading pair or contract.
Exchanges that do not support the exchange.SetMarginLevel()
function:
Function Name | Unsupported Spot Exchanges | Unsupported Futures Exchanges |
---|---|---|
SetMarginLevel | – | Futures_dYdX / Futures_Deribit |
{@var/EXCHANGE exchange}
exchange.GetPositions exchange.SetDirection