Dear Community,
We’re happy to share an update that allows faster order submission to the brokerage, which will be especially noticeable for clients trading large portfolios.
Originally, orders were sent to the broker one at a time, waiting for confirmation before continuing, which caused significant delays. Now orders can be sent as fast as possible - without waiting for confirmation, enabling a 10-100x speed up. Order submission is now limited only by the brokerage limits.
This new feature is available in LEAN v17282.
How Can I Use It?
All order methods now include the `asynchronous` parameter. Setting this to true enqueues the order for parallel processing:
ticket = self.limit_order(symbol, quantity, limit_price, asynchronous=True)The order ticket will have a New status, not Submitted as before, as the order isn’t submitted to the brokerage yet. To monitor order status updates, continue using the OnOrderEvent method.
Previously, asynchronous orders were only supported on MarketOrders. Now you can use it on all order types: MarketOnOpenOrder, MarketOnCloseOrder, LimitOrder, StopMarketOrder, TrailingStopOrder, StopLimitOrder, LimitIfTouchedOrder, ComboLegLimitOrder, ComboLimitOrder, Liquidate, and SetHoldings.
Potential Breaking Change
If your algorithm uses order tags without specifying the argument name, the update can cause errors. To fix these errors, you just need to specify the tag=”” argument name prefix. For example:
# Before (positional args only)
self.limit_order("AAPL", 100, 700.25, "Order information")
# After (named args)
self.limit_order("AAPL", 100, 700.25, tag="Order information")This break was accepted because it maintains consistency across the API, impacts a small number of clients, and is relatively easy to fix.
Performance Testing
First, we've upgraded our Interactive Brokers integration to utilize this new asynchronous order routing.
In tests placing 50 market orders, we saw a reduction of LEAN loop block time from 6s to 25ms (240x). Once submitted to the brokerage, Interactive Brokers processed all the new order submissions in 3 seconds, a 100% speed increase. Other brokerages with higher rate limits will process even faster as we improve them to take advantage of this asynchronous technology.
If you're processing more than 10 orders this should significantly improve your algorithm execution time, let us know how you go in the comments. As always, please get in touch if you have any questions or issues, and we’d be happy to look into them.
Happy Coding!
Neil Juneja
Does this even apply to ComboLimitOrder ? I don't see a parameter for Asynchronous in this method's signature. Can you give an example of how to call ComboLimitOrder to send orders asynchronously ?
Neil Juneja
Fwiw, Mia isn't reflecting this change yet. I asked Mia for an example and got this response…
// 9) Submit the ComboLimitOrder // Asynchronous parameter does NOT exist for ComboLimitOrder in C# -- only in ComboMarketOrder. var tickets = ComboLimitOrder(legs, 1, limitPrice, "Bull Call Spread (Debit)");
Key points:
LUIS MARCELO VOLPE
Hola Jared, gracias por la actualización. Tengo una duda puntual:
Si estoy corriendo en Live con LEAN master v17283, ¿ya obtengo las mejoras de velocidad automáticamente, o necesito modificar mi código para usar explícitamente asynchronous: true en las órdenes?
Aclaro que opero en C# con MarketOrders y Liquidate(), en brokers Schwab y Alpaca. ¿Debo actualizar el código para beneficiarme, o con la nueva versión ya debería ver la mejora?
¡Gracias!
Bryan Lettner
With asynchronous=True, will OnOrderEvent still only fire serially?
In other words... for 25 orders submitted asynchronously, the order events generated will cause OnOrderEvent to fire a bunch of times one after another, right? (as opposed to parallel Event processing)
Jhonathan Abreu
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!