Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Feature Request: Add ExecutionId to OrderEvent and SerializedOrderEvent

Open JaggerH opened this issue 1 month ago • 0 comments

Expected Behavior

OrderEvent and SerializedOrderEvent should have an ExecutionId field to store the unique execution identifier provided by brokerages.

Actual Behavior

Currently, OrderEvent and SerializedOrderEvent classes do not have a field to store the brokerage's execution identifier.

Algorithm maintains a virtual position tracker that differs from the brokerage's portfolio (e.g., for pairs trading, multi-leg strategies) . To keep the virtual position in sync, It's necessary.

Potential Solution

Add an ExecutionId property to both OrderEvent and SerializedOrderEvent classes:

Common/Orders/OrderEvent.cs:

/// <summary>
/// Unique execution identifier from the brokerage
/// </summary>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
[ProtoMember(20)]
public string ExecutionId { get; set; }

Common/Orders/Serialization/SerializedOrderEvent.cs:
/// <summary>
/// Unique execution identifier from the brokerage
/// </summary>
[JsonProperty("executionId", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string ExecutionId { get; set; }

// Backwards compatibility
[JsonProperty("execution-id", DefaultValueHandling = DefaultValueHandling.Ignore)]
string OldExecutionId
{
    set { ExecutionId = value; }
}

Benefits:
- ✅ Minimal change to core classes (one property addition)
- ✅ Fully backward compatible (optional field with DefaultValueHandling.Ignore)
- ✅ Follows existing serialization patterns in SerializedOrderEvent
- ✅ Brokerages can optionally populate this field without breaking existing code
- ✅ Enables deduplication and reconciliation logic in user algorithms

Brokerage Implementation:
var orderEvent = new OrderEvent(...)
{
    ExecutionId = brokerageExecution.Id  // e.g., IB execution ID
};
---
Note: I'm willing to submit a PR implementing this change if the proposal is accepted.

JaggerH avatar Dec 16 '25 08:12 JaggerH