17 using System.Collections.Generic;
34 var newQuantity = position.
Quantity - quantityToDeduct;
48 throw new ArgumentException($
"Position symbols must match in order to combine quantities.");
62 public static Dictionary<Symbol, IPosition>
Consolidate(
this IEnumerable<IPosition> positions)
64 var consolidated =
new Dictionary<Symbol, IPosition>();
65 foreach (var position
in positions)
68 if (consolidated.TryGetValue(position.Symbol, out existing))
71 consolidated[position.Symbol] = existing.Combine(position);
75 consolidated[position.Symbol] = position;
90 var sign = position.
Quantity < 0 ? -1 : +1;