Skip to content

Commit

Permalink
SecurityTransactionManager.GetOrderTicket - Faster implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoRaggi authored and mchandschuh committed Jan 5, 2016
1 parent 05e620e commit 2a752f8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Common/Securities/IOrderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public interface IOrderProvider
/// <returns>An enumerable of <see cref="OrderTicket"/> matching the specified <paramref name="filter"/></returns>
IEnumerable<OrderTicket> GetOrderTickets(Func<OrderTicket, bool> filter = null);

/// <summary>
/// Gets the order ticket for the specified order id. Returns null if not found
/// </summary>
/// <param name="orderId">The order's id</param>
/// <returns>The order ticket with the specified id, or null if not found</returns>
OrderTicket GetOrderTicket(int orderId);

/// <summary>
/// Gets all orders matching the specified filter. Specifying null will return an enumerable
/// of all orders.
Expand Down
2 changes: 1 addition & 1 deletion Common/Securities/SecurityTransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public IEnumerable<OrderTicket> GetOrderTickets(Func<OrderTicket, bool> filter =
/// <returns>The order ticket with the specified id, or null if not found</returns>
public OrderTicket GetOrderTicket(int orderId)
{
return GetOrderTickets(x => x.OrderId == orderId).FirstOrDefault();
return _orderProcessor.GetOrderTicket(orderId);
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions Engine/TransactionHandlers/BrokerageTransactionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ public IEnumerable<OrderTicket> GetOrderTickets(Func<OrderTicket, bool> filter =
return _orderTickets.Select(x => x.Value).Where(filter ?? (x => true));
}

/// <summary>
/// Gets the order ticket for the specified order id. Returns null if not found
/// </summary>
/// <param name="orderId">The order's id</param>
/// <returns>The order ticket with the specified id, or null if not found</returns>
public OrderTicket GetOrderTicket(int orderId)
{
OrderTicket ticket;
_orderTickets.TryGetValue(orderId, out ticket);
return ticket;
}

#endregion

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions Tests/Brokerages/OrderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public IEnumerable<OrderTicket> GetOrderTickets(Func<OrderTicket, bool> filter =
throw new NotImplementedException("This method has not been implemented");
}

public OrderTicket GetOrderTicket(int orderId)
{
throw new NotImplementedException("This method has not been implemented");
}

public IEnumerable<Order> GetOrders(Func<Order, bool> filter)
{
return _orders.Where(filter);
Expand Down
7 changes: 7 additions & 0 deletions Tests/Common/Securities/SecurityPortfolioManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ public IEnumerable<OrderTicket> GetOrderTickets(Func<OrderTicket, bool> filter =
return _tickets.Values.Where(filter ?? (x => true));
}

public OrderTicket GetOrderTicket(int orderId)
{
OrderTicket ticket;
_tickets.TryGetValue(orderId, out ticket);
return ticket;
}

public IEnumerable<Order> GetOrders(Func<Order, bool> filter = null)
{
return _orders.Values.Where(filter ?? (x => true));
Expand Down

0 comments on commit 2a752f8

Please sign in to comment.