输入/搜索内容
内置函数
Global
Log
Market
Trade
Account
Futures
exchange.SetContractType
exchange.GetContractType
exchange.SetDirection
exchange.SetMarginLevel
exchange.GetPositions
exchange.GetFundings
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
结构体
内置变量与常量
通用约定
交易所

设置symbol参数所指定的交易对、合约的杠杆值。同时兼容仅传入marginLevel参数的调用方式,用于设置exchange交易所对象当前交易对、合约的杠杆值。

exchange.SetMarginLevel(symbol, marginLevel)
exchange.SetMarginLevel(marginLevel)

示例

设置当前合约的杠杆,再设置指定品种的杠杆。

javascript
function main() { exchange.SetMarginLevel(10) // 设置BTC的USDT本位永续合约的杠杆为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); // Rust SDK 中SetMarginLevel函数不支持symbol参数,仅设置当前交易对、合约的杠杆值 // 如需设置BTC_USDT.swap品种的杠杆为15,需先切换到该交易对、合约后再调用exchange.SetMarginLevel(15) }

参数

名称类型必填描述

symbol

string

否

要调整杠杆值的品种,例如BTC_USDT.swap,写法见品种代码。

marginLevel

number

是

杠杆值。交易所的杠杆值通常为整数,部分交易所也支持浮点数形式的杠杆值设置。

参考

备注

exchange.SetMarginLevel()函数仅支持加密货币期货合约交易所对象。回测系统支持调用exchange.SetMarginLevel()函数来设置杠杆值。

对于加密货币期货合约而言,由于各加密货币期货合约交易所的杠杆机制并不统一。

在某些交易所中,期货合约的杠杆值是下单接口中的一个参数,此时调用exchange.SetMarginLevel()函数并不会产生网络请求,仅设置FMZ系统底层中的杠杆变量(用于下单接口传参)。

在另一些交易所中,期货合约的杠杆值是交易所的一项独立设置,需要通过交易所网站页面或API接口进行设置。此时调用exchange.SetMarginLevel()函数则会产生网络请求,并且有可能设置失败。失败原因可能有多种,例如:当前存在持仓或挂单,导致该交易对、合约无法再设置新的杠杆值。

不支持的交易所:Futures_Deribit、Futures_EdgeX、Futures_Boros、Futures_Polymarket、Futures_Futu、Futures_IB。调用时报错并返回空值,所有交易所的对照见能力矩阵。