Loading ...

关于期货 exchange.SetDirection 与 exchange.Buy exchange.Sell 的关系

Author: 中本大料, Created: 2018-12-31 21:54:33, Updated:

作为一名成长中的韭菜,我对平台期货交易中选择方向和交易买卖指令结合在一起的情况十分困惑

“首先选择交易方向 exchange.SetDirection(buy/sell/closebuy/closesell),交易方向一共有四种” “然后,调用exchange.Buy/Sell()函数进行下单交易”

一度纠结于如下的几种组合情况: “buy 方向下的 buy和sell sell 方向下的 buy和sell closebuy 方向下的 buy和sell closesell 方向下的 buy和sell”,分别如何理解,经过用更傻的方法进行手动测试, 我得出了如下结论 “//结论1:无论当前方向是 buy 还是sell ,开多仓是buy,开空仓是sell” “//结论2:无论方向是closebuy还是closesell,平多都是sell,平空都是buy”

供更小的韭菜参考。测试的傻代码如下:

/*backtest start: 2018-12-01 00:00:00 end: 2018-12-31 00:00:00 period: 1h exchanges: [{“eid”:“Futures_OKCoin”,“currency”:“BTC_USD”}] */

function main() { exchange.SetContractType(“quarter”) exchange.SetMarginLevel(10) exchange.SetDirection(“sell”) var buy1 =exchange.GetTicker() Log(buy1.Sell) exchange.Sell(3500,500) Log(exchange.GetAccount()); Log(exchange.GetPosition()); exchange.SetDirection(“closebuy”) exchange.Buy(4000,500) Log(exchange.GetAccount()); Log(exchange.GetPosition());

}

//buy sell // [{“Price”:3934.21,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230381575061599,“Margin”:1.27090318,“MarginLevel”:10,“Type”:1,“ContractType”:“quarter”}] // {“Balance”:0,“FrozenBalance”:0,“Stocks”:98.72528411046,“FrozenStocks”:0}

//buy buy // [{“Price”:3934.23,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230365153283115,“Margin”:1.27089671,“MarginLevel”:10,“Type”:0,“ContractType”:“quarter”}] // {“Balance”:0,“FrozenBalance”:0,“Stocks”:98.725290599843,“FrozenStocks”:0}

//sell sell //[{“Price”:3934.21,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230381575061599,“Margin”:1.27090318,“MarginLevel”:10,“Type”:1,“ContractType”:“quarter”}] //{“Balance”:0,“FrozenBalance”:0,“Stocks”:98.72528411046,“FrozenStocks”:0}

//sell buy //[{“Price”:3934.23,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230365153283115,“Margin”:1.27089671,“MarginLevel”:10,“Type”:0,“ContractType”:“quarter”}] //{“Balance”:0,“FrozenBalance”:0,“Stocks”:98.725290599843,“FrozenStocks”:0}

//--------------------------------------------------------------------------- //buy buy //[{“Price”:3934.23,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230365153283115,“Margin”:1.27089671,“MarginLevel”:10,“Type”:0,“ContractType”:“quarter”}] // {“Balance”:0,“FrozenBalance”:0,“Stocks”:1.725290599843,“FrozenStocks”:0} //sell buy //[{“Price”:3934.23,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230365153283115,“Margin”:1.27089671,“MarginLevel”:10,“Type”:0,“ContractType”:“quarter”}] //{“Balance”:0,“FrozenBalance”:0,“Stocks”:1.725290599843,“FrozenStocks”:0}

//buy sell //[{“Price”:3934.21,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230381575061599,“Margin”:1.27090318,“MarginLevel”:10,“Type”:1,“ContractType”:“quarter”}] // {“Balance”:0,“FrozenBalance”:0,“Stocks”:1.72528411046,“FrozenStocks”:0} //sell sell //[{“Price”:3934.21,“Amount”:500,“FrozenAmount”:0,“Profit”:-0.00003230381575061599,“Margin”:1.27090318,“MarginLevel”:10,“Type”:1,“ContractType”:“quarter”}] // {“Balance”:0,“FrozenBalance”:0,“Stocks”:1.72528411046,“FrozenStocks”:0} //结论:无论当前方向是 buy 还是sell ,开多仓是buy,开空仓是sell

//当前持多仓 //-------------------------------------------- //closebuy buy //invalid position //closebuy sell //[] //{“Balance”:0,“FrozenBalance”:0,“Stocks”:2.992310000303,“FrozenStocks”:0}

//closesell buy //invalid position //closesell sell //[] //{“Balance”:0,“FrozenBalance”:0,“Stocks”:2.992310000303,“FrozenStocks”:0} //-------------------------------------------- //结论:无论方向是closebuy还是closesell,平多都是sell

//当前持空仓 //-------------------------------------------- //closesell sell //invalid position //closesell buy //[] //{“Balance”:0,“FrozenBalance”:0,“Stocks”:2.992310000303,“FrozenStocks”:0}

//closebuy sell //invalid position //closebuy buy //[] //{“Balance”:0,“FrozenBalance”:0,“Stocks”:2.992310000303,“FrozenStocks”:0} //结论:无论方向是closebuy还是closesell,平多都是buy


More

小小梦 |下单函数|设置方向|备注| |-|-|-| |exchange.Buy| 开多仓: exchange.SetDirection("buy") 、 平空仓: exchange.SetDirection("closesell")| 都是买入,但是一个是开仓 一个是平仓。 | |exchange.Sell| 开空仓: exchange.SetDirection("sell") 、 平多仓:exchange.SetDirection("closebuy")| 数字货币期货是四个方向,商品期货还有对于今仓的处理。|

Nightsky 这是哪个平台?我试试回测

中本大料 exchange.SetDirection 在数字货币期货设置 四个方向 closesell sell 对应 exchange.Sell, closebuy buy 对应 exchange.Buy。<<<<<<官方解释

中本大料 :)

suanli 明白了!

小小梦 那是 BITMEX 吧, BITMEX 永续合约 类似 现货的概念,只有买卖 ,如果是其他 交易所 期货 比如 OKEX 的 你就必须用 平多仓 平空仓 才能平仓了。

suanli 我目前也有这个疑惑,用sell buy全都实现开仓平仓 那close不是没用了吗

suanli 你现在是如何理解这四个按钮的?

suanli 我现在也是这个疑惑,这四个方向是在什么情况下产生作用的? 我设置之后 只用buy sell 不管是平多仓平空仓还是开多仓开空仓全都实现了,那closebuy 跟closesell 不是没有用了吗????

中本大料 okex 期货模拟回测