public void ProcessPriceChanges(IEnumerable <PriceChange> priceChanges) { PositionChangeProcessor changeProcessor = new PositionChangeProcessor(this._dataTable); lock (this) { foreach (PriceChange priceChange in priceChanges) { int index = this._positions.BinarySearchByValue(priceChange.Ticker, pos => pos.Ticker); if (index < 0) { continue; } Position position = this._positions[index]; position.PropertyChanged += changeProcessor.PropertyChangedEventHandler; PortfolioData.CalculatePosition(position, priceChange.Price); position.PropertyChanged -= changeProcessor.PropertyChangedEventHandler; } if (changeProcessor.RowChanges.Count == 0) { return; } this._dataTable.AcceptChanges(); } this.OnDataChanged(changeProcessor.RowChanges); }
private static void ProcessTrade(Position position, int quantity, decimal price) { if (quantity == 0) { return; } position.Quantity += quantity; decimal tradeValue = quantity * price; if (tradeValue < 0) { position.Cash -= tradeValue; } else { position.CostBasis += tradeValue; } PortfolioData.CalculatePosition(position, price); }