I want to get the last order's fill price and compare it to the current price of the equity.
I want to get the last order's fill price and compare it to the current price of the equity.
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.
Hey Benjamin,
We can use the OnOrderEvent(self, orderevent) method, which fires each time an order is partially filled, filled, cancelled, etc. The orderevent object which is passed as a parameter contains information about the order which has been updated.Using the orderevent object, we can access properties of the order like
symbol = orderevent.Symbol # The symbol of the security the order is associated with
status = orderevent.Status # Whether the order has been filled, partially filled, cancelled, submitted, etc
fill_price = orderevent.FillPrice # The fill price of the order
fill_quantity = orderevent.FillQuantity # The fill quantity of the order
Knowing the symbol of the order, we can find the latest price of the corresponding symbol using
price = self.Securities[symbol].Price
So putting it all together,
def OnOrderEvent(self, orderevent):
# check if orderevent is a fill
if orderevent.Status == OrderStatus.Filled:
symbol = orderevent.Symbol
fill_price = orderevent.FillPrice
current_price = self.Securities[symbol].Price
Learn more in the documentation on trading and orders. I also recommend completing the Buy & Hold with a Trailing Stop Bootcamp, which covers the OnOrderEvent method.
Best
Rahul
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!