exchange.SetMarginLevel()函数用于设置symbol参数指定的交易对或合约的杠杆倍数。兼容仅传入marginLevel参数来设置{@var/EXCHANGE exchange}交易所对象当前交易对或合约的杠杆倍数。
exchange.SetMarginLevel(symbol, marginLevel) exchange.SetMarginLevel(marginLevel)
symbol参数用于指定需要调整杠杆倍数的交易对或合约。SetMarginLevel()函数的symbol参数格式与GetTicker()函数的symbol参数格式一致。
symbol
false
string
marginLevel参数用于设置杠杆倍数。交易所的杠杆倍数通常为整数,部分交易所也支持浮点数杠杆倍数设置。
marginLevel
true
number
function main() {
exchange.SetMarginLevel(10)
// 设置BTC的USDT本位永续合约的杠杆为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);
}
exchange.SetMarginLevel()函数仅支持加密货币期货合约交易所对象。回测系统支持调用exchange.SetMarginLevel()函数设置杠杆倍数。
对于加密货币期货合约,由于各交易所的杠杆机制并不统一:
某些交易所的期货合约杠杆倍数是下单接口中的一个参数,此时调用exchange.SetMarginLevel()函数不会产生网络请求,仅设置FMZ系统底层的杠杆变量(用于下单接口传参)。
某些交易所的期货合约杠杆倍数是交易所的一项配置,需要通过交易所网站页面或API接口进行设置。此时调用exchange.SetMarginLevel()函数会产生网络请求,并且可能设置失败。失败原因可能包括:当前存在持仓或挂单,导致该交易对或合约无法设置新的杠杆倍数。
不支持exchange.SetMarginLevel()函数的交易所:
| 函数名 | 不支持的现货交易所 | 不支持的期货交易所 |
|---|---|---|
| SetMarginLevel | – | Futures_dYdX / Futures_Deribit / Futures_Vertex / Futures_edgeX |
{@var/EXCHANGE exchange}