18 using System.Collections;
19 using System.Collections.Generic;
29 private Dictionary<Symbol, IPosition> _positions;
33 public int Count => _positions.Count;
41 _positions = positions;
49 : this(positions.ToDictionary(p => p.
Symbol))
61 public void Remove(IEnumerable<IPositionGroup> groups)
63 foreach (var group
in groups)
65 foreach (var position
in group.Positions)
68 if (!_positions.TryGetValue(position.Symbol, out existing))
70 throw new InvalidOperationException($
"Position with symbol {position.Symbol} not found.");
73 var resultingPosition = existing.Deduct(position.Quantity);
75 if(resultingPosition.Quantity == 0)
77 _positions.Remove(position.Symbol);
81 _positions[position.Symbol] = resultingPosition;
103 return _positions.TryGetValue(symbol, out position);
110 return _positions.Values.GetEnumerator();
115 IEnumerator IEnumerable.GetEnumerator()