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_edgeX |
{@var/EXCHANGE exchange}