19 using System.Collections.Generic;
20 using System.Collections.Specialized;
34 private bool _requiresGroupResolution;
73 _securities = securities;
77 foreach (var security
in _securities.
Values)
80 security.Holdings.QuantityChanged += HoldingsOnQuantityChanged;
86 securities.CollectionChanged += (sender, args) =>
88 var items = args.NewItems ??
new List<object>();
89 if (args.OldItems !=
null)
91 foreach (var item
in args.OldItems)
99 if (args.Action == NotifyCollectionChangedAction.Add)
105 _requiresGroupResolution =
true;
108 else if (args.Action == NotifyCollectionChangedAction.Remove)
114 _requiresGroupResolution =
true;
135 var newPositions = orders.Select(order => order.CreatePositions(_securities)).SelectMany(x => x).ToList();
154 return _resolver.
Resolve(positions);
198 _requiresGroupResolution =
true;
204 private void ResolvePositionGroups()
206 if (_requiresGroupResolution)
208 _requiresGroupResolution =
false;
211 var investedPositions = _securities.Where(kvp => kvp.Value.Invested).Select(kvp => (IPosition)
new Position(kvp.Value));
212 var positionsCollection =
new PositionCollection(investedPositions);
213 Groups = ResolvePositionGroups(positionsCollection);