Trading and Orders
Order Events
Track Order Events
Each order generates events over its life as its status changes. Your algorithm receives these events through the OnOrderEvent
on_order_event
and OnAssignmentOrderEvent
on_assignment_order_event
methods. The OnOrderEvent
on_order_event
event handler receives all order events. The OnAssignmentOrderEvent
on_assignment_order_event
receives order events for Option assignments. The event handlers receive an OrderEvent
object, which contains information about the order status.
public override void OnOrderEvent(OrderEvent orderEvent) { var order = Transactions.GetOrderById(orderEvent.OrderId); if (orderEvent.Status == OrderStatus.Filled) { Debug($"{Time}: {order.Type}: {orderEvent}"); } } public override void OnAssignmentOrderEvent(OrderEvent assignmentEvent) { Log(assignmentEvent.ToString()); }
def on_order_event(self, order_event: OrderEvent) -> None: order = self.transactions.get_order_by_id(order_event.order_id) if order_event.status == OrderStatus.FILLED: self.debug(f"{self.time}: {order.type}: {order_event}") def on_assignment_order_event(self, assignment_event: OrderEvent) -> None: self.log(str(assignment_event))
To get a list of all OrderEvent
objects for an order, call the OrderEvents
order_events
method of the order ticket.
var orderEvents = orderTicket.OrderEvents();
order_events = order_ticket.order_events()
If you don't have the order ticket, get the order ticket from the TransactionManager.