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 is also compatible with a calling method that passes only the marginLevel parameter, which is used to set the leverage value of 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)
rust
fn main() {
exchange.SetMarginLevel(10);
// In the Rust SDK, the SetMarginLevel function does not support the symbol parameter; it only sets the leverage value of the current trading pair or contract
// To set the leverage of the BTC_USDT.swap instrument to 15, you need to switch to that trading pair or contract first and then call exchange.SetMarginLevel(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 the leverage value.
For cryptocurrency futures contracts, the leverage mechanisms of different cryptocurrency futures contract exchanges are not unified.
On some exchanges, the leverage value of a futures contract is a parameter in the order-placing interface. In this case, calling the exchange.SetMarginLevel() function does not generate a network request; it merely sets the underlying leverage variable in the FMZ system (used for passing parameters to the order-placing interface).
On other exchanges, the leverage value of a futures contract is an independent setting of the exchange, which needs to be set through the exchange's website page or API interface. In this case, calling the exchange.SetMarginLevel() function will generate a network request and may fail to set the value. There can be various reasons for failure, for example: there are currently open positions or pending orders, which prevents a new leverage value from being set for that 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 / Futures_edgeX |