vn.py官网
开源量化社区
Member
avatar
加入于:
帖子: 21
声望: 1

多头有仓位,如果需要平仓(或者减仓)的话,对应的操作应该是多头平仓吧?为什么在vnpy中是空头平仓?

Member
加入于:
帖子: 136
声望: 44

这个日常买卖语言和程序逻辑不搭配,没必要一定mapping 上,只要看看下面代码,注意Direction和Offset就可以
def buy(self, price: float, volume: float, stop: bool = False, lock: bool = False):
"""
Send buy order to open a long position.
"""
return self.send_order(Direction.LONG, Offset.OPEN, price, volume, stop, lock)

def sell(self, price: float, volume: float, stop: bool = False, lock: bool = False):
    """
    Send sell order to close a long position.
    """
    return self.send_order(Direction.SHORT, Offset.CLOSE, price, volume, stop, lock)

def short(self, price: float, volume: float, stop: bool = False, lock: bool = False):
    """
    Send short order to open as short position.
    """
    return self.send_order(Direction.SHORT, Offset.OPEN, price, volume, stop, lock)

def cover(self, price: float, volume: float, stop: bool = False, lock: bool = False):
    """
    Send cover order to close a short position.
    """
    return self.send_order(Direction.LONG, Offset.CLOSE, price, volume, stop, lock)
© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号