Back

How To Access FillPrice Field From OrderEvent Class

Hey!

I'm trying to get the fill price of my order for the day to compare it to the current price. I'm having a little trouble accessing the FillPrice field from the OrderEvent Class that it belongs to. I've imported the namespace Orders with using QuantConnect.Orders;. It always shows 0 in the console.

Do you know how to do this?

Update Backtest








Hey Travis,

In order to get order events you'll need to override the OnOrderEvent(OrderEvent) method. I've modified your algorithm to do this. The issue was you were using your own OrderEvents class and that value is never updated by the LEAN engine. You can inspect the log and see the fill prices.

0

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.


Thank you!
Michael that worked like a charm. Now how do I access the fill.FillPrice publicly then store it in a variable? I'm trying this
OrderEvent percentFill = new OrderEvent(); but it isn't working

0

@Travis, Michael has it right but you also need to look at the order status. The first time an OnOrderEvent fires, the orderEvent.Status is Submitted and the fill price will be 0 because the order has not filled yet. Subsequent events will tell you what happened in more detail.


switch (orderEvent.Status)
{
case OrderStatus.New:
case OrderStatus.None:
break;
case OrderStatus.Submitted:
Log("Order Submitted");
case OrderStatus.Invalid:
break;
case OrderStatus.PartiallyFilled:
decimal nEntryPrice = Portfolio[orderEvent.Symbol].HoldStock ? Portfolio[orderEvent.Symbol].AveragePrice : 0;

Log(string.Format("Partial Fill: {0}",nEntryPrice ));
}

break;
case OrderStatus.Canceled:
Log(string.Format("Order {0} cancelled.", orderEvent.OrderId));
break;
case OrderStatus.Filled:

decimal nEntryPrice = Portfolio[orderEvent.Symbol].HoldStock ? Portfolio[orderEvent.Symbol].AveragePrice : 0;

Log(string.Format("Order Filled: {0}",nEntryPrice ));
break;

0

Michael - It finally clicked in my mind why you said to use the override modifier. Its implementation needs to be inherited from the QCAlgorithm class.

Nicholas - I've never seen a switch statement before but I was able to implement it in my code. This is definitely a good step towards a more resilient algorithm that can handle different situations.

0


Update Backtest





0

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.


Loading...

This discussion is closed