Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何在ontick里面调用onOrder的变量? #23

Closed
ghost opened this issue Feb 24, 2016 · 4 comments
Closed

如何在ontick里面调用onOrder的变量? #23

ghost opened this issue Feb 24, 2016 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 24, 2016

如何载onTick里面调用onOrder里面的onOrder.status等变量?

用global吗?

@vnpy
Copy link
Owner

vnpy commented Feb 24, 2016

在策略的Class里,创建一个类成员,比如self.lastOrder。

然后onOrder函数里,使用self.lastOrder = order缓存下来。

在onTick里就可以随意调用了。

@ghost
Copy link
Author

ghost commented Feb 24, 2016

` # CTA委托类型映射
if self.lastOrder != None and self.lastOrder.direction == u'多' and self.lastOrder.offset == u'开仓':
self.orderType = u'买开'
elif self.lastOrder != None and self.lastOrder.direction == u'多' and self.lastOrder.offset == u'平仓':
self.orderType = u'买平'
elif self.lastOrder != None and self.lastOrder.direction == u'空' and self.lastOrder.offset == u'开仓':
self.orderType = u'卖开'
elif self.lastOrder != None and self.lastOrder.direction == u'空' and self.lastOrder.offset == u'平仓':
self.orderType = u'卖平'

    if  self.lastOrder != None and self.lastOrder.status == u'未成交':
        self.cancelOrder(self.lastOrder.vtOrderID)

    elif self.lastOrder != None and self.lastOrder.status == u'已撤销':

        self.sendOrder(self.orderType, self.bar.close-10, 1)`

把代码放到onTick里面,极个别会出现不成交的撤销不了的情况,请看一下原因,谢谢

@vnpy
Copy link
Owner

vnpy commented Feb 24, 2016

撤销不了的委托,在OrderMonitor里面,显示的状态是什么?

@ghost
Copy link
Author

ghost commented Feb 24, 2016

@ghost ghost closed this as completed Feb 26, 2016
vnpy pushed a commit that referenced this issue Feb 26, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant