Learning QuantConnect - Part V: Orders & Order Events (Python) ππ¨βπ
QuantConnect is a powerful open-source, cloud-based platform for algorithmic trading platform. It allows users to design, test, and deploy trading strategies across various financial markets including equities, FX, futures, options, and cryptocurrencies.
QuantConnect can be a bit of a beast when it comes to complexity. The thing is packed with features and, let's be real, wading through the docs can feel overwhelming. So in this series I tried to break it down into bite-sized chunks that won't make your head hurt. In this part we will take a look at order submission, management and order events.
Suggested Reads:
Learning QuantConnect - Part II: Portfolio, Security Holding & Cashbook
Learning QuantConnect - Part IV: Working with Data and DataSets
This story is solely for general information purposes, and should not be relied upon for trading recommendations or financial advice. Source code and information is provided for educational purposes only, and should not be relied upon to make an investment decision. Please review my full cautionary guidance before continuing.
What is an Order?
An order is a request from an individual or an institution to a broker or financial institution to buy or sell a security. An order typically includes specific instructions about the type of order, type of security, quantity and price of the security.
LEAN support the following order types:
Market: Executes immediately at the current market price.
Limit: Sets a maximum or minimum price at which you're willing to buy or sell. The order only executes if the market reaches your specified price.
Limit if Touched: Similar to a limit order, but it becomes active only after a specified trigger price is reached.
Stop Market: Executes as a market order once a specified stop price is reached. It's used to limit losses or protect profits.
Stop Limit: Combines features of stop and limit orders. When the stop price is reached, the order becomes a limit order to be executed at a specified price.
Trailing Stop: A stop order that adjusts itself as the market price moves in a favorable direction, maintaining a specified distance (trailing amount) from the market price.
Market on Open (MOO): Executes as a market order at the opening of the market session.
Market on Close (MOC): Executes as a market order at the closing of the market session.
Combo Market: A specialized order type that allows you to execute a combination of positions (e.g., buying a stock and selling a call option on that stock) at the current market prices.
Combo Limit: Similar to a combo market order but with a limit price for the combination, ensuring that the combo executes only at a specified price or better.
Combo Leg Limit: Sets limit prices on individual legs of a combo order, allowing precise control over the execution prices of each component of the combo.
Option Exercise: Used specifically for options trading, it instructs the broker to exercise the rights granted by the option contract (either to buy or sell the underlying asset) at the option's strike price.
Not all of these order types will be covered in this tutorial.
Here the most important properties of the Order class:
Id
Symbol
Price
PriceCurrency
Quantity
OrderType
OrderStatus.
For a complete list of properties, check out the LEAN Class reference.
Take the emotions out of trading and free up hours of screen time by letting the algorithms do the work for you. Join Algohive and get an exclusive 50% discount on our membership.