exchange.SetMarginLevel
The exchange.SetMarginLevel() function is used to set the leverage value for the trading pair or contract specified by the symbol parameter. It supports passing only the marginLevel parameter to set the leverage value for the current trading pair or contract of the exchange exchange object.
exchange.SetMarginLevel(symbol, marginLevel)
exchange.SetMarginLevel(marginLevel)Examples
javascript
function main() {
exchange.SetMarginLevel(10)
// Set the leverage of BTC's USDT-margined perpetual contract to 15
exchange.SetMarginLevel("BTC_USDT.swap", 15)
}
python
def main():
exchange.SetMarginLevel(10)
exchange.SetMarginLevel("BTC_USDT.swap", 15)
c++
void main() {
exchange.SetMarginLevel(10);
exchange.SetMarginLevel("BTC_USDT.swap", 15);
}Arguments
| Name | Type | Required | Description |
symbol | string | No | The |
marginLevel | number | Yes | The |
See Also
Remarks
The exchange.SetMarginLevel() function only supports cryptocurrency futures contract exchange objects. The backtesting system supports calling the exchange.SetMarginLevel() function to set leverage values.
For cryptocurrency futures contracts, the leverage mechanisms across exchanges are not unified.
For some exchanges, the futures contract leverage value is a parameter in the order placement interface. In this case, calling the exchange.SetMarginLevel() function will not generate a network request, but only sets the underlying leverage variable in the FMZ system (used for order interface parameter passing).
For some exchanges, the futures contract leverage value is an exchange setting that needs to be configured through the exchange website page or using API interfaces. In this case, calling the exchange.SetMarginLevel() function will generate a network request and may fail to set. Reasons for failure may include: existing positions or pending orders that prevent the trading pair or contract from being set to a new leverage value.
Exchanges that do not support the exchange.SetMarginLevel() function:
| Function Name | Unsupported Spot Exchanges | Unsupported Futures Exchanges |
|---|---|---|
| SetMarginLevel | -- | Futures_dYdX / Futures_Deribit / Futures_edgeX |