Trading and Orders

Order Events

Introduction

An OrderEvent object represents an update to the state of an order. As the state of your orders change, we notify your algorithm with OrderEvent objects through the OnOrderEventon_order_event and OnAssignmentOrderEventon_assignment_order_event event handlers.

Track Order Events

Each order generates events over its life as its status changes. Your algorithm receives these events through the OnOrderEventon_order_event and OnAssignmentOrderEventon_assignment_order_event methods. The OnOrderEventon_order_event event handler receives all order events. The OnAssignmentOrderEventon_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 OrderEventsorder_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.

Order States

Orders can have any of the following states:

Event Attributes

The OnOrderEventon_order_event and OnAssignmentOrderEventon_assignment_order_event event handlers in your algorithm receive OrderEvent objects, which have the following attributes:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: