Curious how I could go about canceling an order? Say I place a limit or stop order, how would I later retrieve and/or cancel it?
QUANTCONNECT COMMUNITY
Curious how I could go about canceling an order? Say I place a limit or stop order, how would I later retrieve and/or cancel it?
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Nicholas Stein
Andrzej Fudala
public override void OnOrderEvent(OrderEvent fill) { if (fill.Status.IsClosed() && fill.FillQuantity > 0) { var openedPositions = Securities.Values.Where(sec => sec.HoldStock).ToList(); Console.WriteLine(Time + ": Bought " + fill.FillQuantity + " " + fill.Symbol + " for " + fill.FillPrice + " Open Positions=" + openedPositions.Count); if (openedPositions.Count >= 2) { foreach (var ticket in Transactions.GetOrderTickets(x => x.Status.IsOpen())) { ticket.Cancel(); } var openedTickets = Transactions.GetOrderTickets(x => x.Status.IsOpen()).ToList(); Console.WriteLine(Time + ": Opened tickets: " + openedTickets.Count); } } }
But it doesn't work at all. I have still opened tickets after loop to cancel each of them. Has anybody working solution to cancel opened orders?Jared Broad
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Keith K
FYI on ETrade recently, out of curiosity, I placed and then cancelled an after hours limit order. Placing the order took 1 minute, and cancelling it took several minutes.
Not sure how other brokerages work.
For other brokerages, has anyone experienced more than 5 seconds to cancel a limit order during normal trading hours?
Jared Broad
Hey Keith; you placed it through the eTrade website? Or do you have an eTrade adaptor for LEAN?
Even for afterhours trading no broker should take more than 1sec to place an order. If thats true (and not just a UX glitch) then eTrade seems fairly slow.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Keith K
I was just doing a manual order, not using LEAN.
I was placing an after hours order on ETrade. It was a very thinly traded stock, and I was placing a Bid, but there was no Ask. Maybe it took so long because there was no Ask?
With regards to an adaptor for ETrade... its very low on my priority list of things to do. Its going to be a while before my code is safe enough for automatic trading. I'll stick with SMS messages and email until then.
Jared Broad
If you're placing a limit order then there's no limit to how long it can take to fill. But placing the order should be instantaneous.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Keith K
on ETrade using manual trading, it took 2 minutes to update an existing after hours limit order by changing my bid. I eventually cancelled the order after increasing the bid 5 times over a 10 minute period. Inevitably, the next morning the stock had popped up ~2%.
Now, you're probably correct that when I submitted the limit order initially, it was instantaneous.
Ian Worthington
Jared does this 100ms~1s also apply to backtesting data (which is moving very fast)?
Alexandre Catarino
No. That response span range only applies to live trading when Lean is connected to a real brokerages. It depends on how fast/slow the brokerage server respond to our resquest (order placing, cancelling, etc).
In backtesting mode, order cancelling should be, like placing, instantaneous.
Ian Worthington
Thanks for the reply Alex. Does this also apply to orders placed from within the OnOrder event? Ignoring functions like MarketOrderOnClose, is there some kind of restriction regarding the resolution of the algorithm? IE:
Resolution is hourly.
- 17:00 OnData makes some StopOrder()
- 17:16 OnOrderEvent gets a Filled event (Could this theoretically happen any time? not restricted to the "hourly pulse"?
- 18:00 OnData is fired again.
Is this the standard flow?
Ian Worthington
I just did a small test to see what is happening with OrderEvents. It seems that events are actually happening by the minute. This mean's that OnOrderEvent is tied to the "Resolution" set by the algorithm. Now, either I am misunderstanding the usage, or this makes it completely useless at emulating a live situation, where an algorithm may be subscribed to "minute" data, but may want to perform actions within that minute if something should happen which fires the OnOrderEvent.
Alexandre Catarino
In backtesting mode, when our algorithm subscribes to a ticker with given resolution, no event will be fired at a higher frequency, because there is no higher resolution data to trigger an event. E.g.:
Resolution is hourly.
- 17:00 OnData makes some StopOrder()
- 18:00 OnOrderEvent gets a Filled event (not possible to be fired at 17:16)
- 18:00 OnData is fired again.
I wouldn't say it is useless at emulating a live situation, because it is not really the point. We use low resolution data to test a theory quickly. Once we have validated it, we should increase resolution to catch intraday nuances if we want our algorithm to trade during the day.
Levitikon
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!