Hey guys, I can't seem to figure this out, and maybe it's just not possible, but does anyone know how I'd update an order tag within the OnOrderEvent handler? I was hoping something like the below would work, but it seems to have no impact. Note that I'm using the Algorithm Framework, and am not creating my orders directly.
def OnOrderEvent(self, orderEvent):
""" Handles various order events. """
# Handle filled orders
if orderEvent.Status == OrderStatus.Filled:
order = self.Transactions.GetOrderById(orderEvent.OrderId)
orderTicket = self.Transactions.GetOrderTicket(orderEvent.OrderId)
# Tag pnl of covered short position
if orderTicket is not None and orderEvent.Direction == OrderDirection.Buy:
orderPNL = self.Portfolio[orderEvent.Symbol].Profit
orderUpdate = UpdateOrderFields()
orderUpdate.Tag = f'PNL: ${orderPNL:,.2f}'
orderTicket.Update(orderUpdate)
Shile Wen
Hi Charles,
By the time the OrderEvent is called, the order has already been filled so it is not possible to update its tag.
Best,
Shile Wen
Charles Naccio
Hey Shile Wen that makes sense, but I'd expect still being able to update the order when catching the new order event, which occurs before the filled event?
Shile Wen
Hi Charles,
We can update the tag if the order in the OrderEvent is not filled, but if the order is already filled, then it's not possible to update the tag. However, I've submitted a feature request to allow retroactive updates of tags on Github here, and I suggest subscribing to the thread to be notified when the solution is merged.
An alternative way to track order profits can be found in this thread.
Best,
Shile Wen
Charles Naccio
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!