/// <summary>
        /// Brokerages can send portfolio updates which should include average price of holdings and the
        /// quantity of holdings, we'll trust this information as truth and just set the portfolio with it
        /// </summary>
        private void HandleSecurityHoldingUpdated(SecurityEvent holding)
        {
            // how close are we?
            var securityHolding = _algorithm.Portfolio[holding.Symbol];
            var deltaQuantity = securityHolding.Quantity - holding.Quantity;
            var deltaAvgPrice = securityHolding.AveragePrice - holding.AveragePrice;
            if (deltaQuantity != 0 || deltaAvgPrice != 0)
            {
                Log.Trace(string.Format("BrokerageTransactionHandler.HandleSecurityHoldingUpdated(): {0} DeltaQuantity: {1} DeltaAvgPrice: {2}", holding.Symbol, deltaQuantity, deltaAvgPrice));
            }

            // we don't actually want to do this, this data can be delayed
            //securityHolding.SetHoldings(holding.AveragePrice, holding.Quantity);
        }
Esempio n. 2
0
        /// <summary>
        /// Event invocator for the PortfolioChanged event
        /// </summary>
        /// <param name="e">The PortfolioEvent</param>
        protected virtual void OnPortfolioChanged(SecurityEvent e)
        {
            try
            {
                Log.Trace("Brokerage.OnPortfolioChanged(): " + e);

                var handler = SecurityHoldingUpdated;
                if (handler != null) handler(this, e);
            }
            catch (Exception error)
            {
                Log.Error("Brokerage.OnPortfolioChanged(): Caught Error: " + error.Message);
            }
        }