资源加载中... loading...

exchange.SetDirection


exchange.SetDirection(direction)

```direction```参数用于设置期货合约下单时的方向,可选值为:```"buy"```、```"closesell"```、```"sell"```、```"closebuy"```。
direction
true
string

```javascript
function main(){
    // 举例设置为OKX期货当周合约
    exchange.SetContractType("this_week")    
    // 设置杠杆为5倍
    exchange.SetMarginLevel(5)
    // 设置下单类型为做多
    exchange.SetDirection("buy")
    // 以10000的价格,合约数量为2张下单
    exchange.Buy(10000, 2)              
    exchange.SetMarginLevel(5)
    exchange.SetDirection("closebuy")
    exchange.Sell(1000, 2)
}
def main():
    exchange.SetContractType("this_week")
    exchange.SetMarginLevel(5)
    exchange.SetDirection("buy")
    exchange.Buy(10000, 2)
    exchange.SetMarginLevel(5)
    exchange.SetDirection("closebuy")
    exchange.Sell(1000, 2)
void main() {
    exchange.SetContractType("this_week");
    exchange.SetMarginLevel(5);
    exchange.SetDirection("buy");
    exchange.Buy(10000, 2);
    exchange.SetMarginLevel(5);
    exchange.SetDirection("closebuy");
    exchange.Sell(1000, 2);
}

exchange.SetDirection()函数设置期货合约交易的方向和下单函数之间的对应关系:

下单函数 SetDirection函数的参数设置的方向 备注
exchange.Buy “buy” 买入开多仓
exchange.Buy “closesell” 买入平空仓
exchange.Sell “sell” 卖出开空仓
exchange.Sell “closebuy” 卖出平多仓

{@fun/Trade/exchange.Buy exchange.Buy}, {@fun/Trade/exchange.Sell exchange.Sell}

exchange.SetMarginLevel exchange.SetContractType