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!