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

给出的这个例子似乎无法平仓 #2

Open
goodluck028 opened this issue Aug 2, 2017 · 1 comment
Open

给出的这个例子似乎无法平仓 #2

goodluck028 opened this issue Aug 2, 2017 · 1 comment

Comments

@goodluck028
Copy link

goodluck028 commented Aug 2, 2017

Order openLimitOrder;
Order openMarketOrder;
private void OnBar(Instrument instrument,Bar bar)
{
openLimitOrder = BuyLimitOrder(instrument, 1, bar.Open, "buy limit order");
Send(openLimitOrder);//买限价单
AddReminder(Clock.DateTime.AddMinutes(1),"cancel buy limit order");//添加定时器,下单1分钟后还未成交的话做撤单处理
openMarketOrder = BuyOrder(instrument, 2, "buy market order");//买市价单
Send(openMarketOrder);
}
protected override void OnOrderFilled(Order order)
{
if (order.Text == "buy market order")
{
closeLimitOrder = SellLimitOrder(order.Instrument, order.Qty, order.Price + order.Instrument.TickSize * 2);
Send(closeLimitOrder);
}
}
protected override void OnReminder(DateTime dateTime, object data)
{
if (data != null && data.ToString() == "cancel buy limit order")
{//是撤单定时器触发的
if (!openLimitOrder.IsDone)
{//openLimitOrder还未成交
Cancel(openLimitOrder);
}
}
}

@geyexiaocai
Copy link

这个写法是基于Openquant自身的特性没有引用ctp插件特性,所以在国内市场确实不能平仓
如果针对CTP插件的写法,平仓代码部分可以改成:
if (order.Text == "buy market order")
{
closeLimitOrder = SellLimitOrder(order.Instrument, order.Qty, order.Price + order.Instrument.TickSize * 2);
closeLimitOrder.Close();
Send(closeLimitOrder);
}
需要在项目中引用QuantBox.Extensions

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

2 participants