Exemple #1
0
        /// <summary>
        /// Update position statistics for a given Security (Symbol)
        /// </summary>
        /// <param name="orderDetails">Order details</param>
        public void UpdatePosition(OrderDetails orderDetails)
        {
            PositionStatistics statistics;

            // Find Existing Statistics for the incoming order security
            if (!_positionStatisticsDictionary.TryGetValue(orderDetails.Security.Symbol, out statistics))
            {
                // Create a new object
                statistics = new PositionStatistics(orderDetails.Security);

                // Add to dictionary collection
                _positionStatisticsDictionary.Add(orderDetails.Security.Symbol, statistics);

                _currentDispatcher.Invoke(DispatcherPriority.Background, (Action)(() =>
                {
                    // Add to Collection to dispaly on UI
                    PositionStatisticsCollection.Add(statistics);
                }));
            }

            // Handle BUY Order
            if (orderDetails.Side.Equals(OrderSide.BUY))
            {
                statistics.Position += orderDetails.Quantity;
                statistics.Pnl      -= orderDetails.Quantity * orderDetails.FillDetails.Last().FillPrice;
            }
            else
            {
                statistics.Position -= orderDetails.Quantity;
                statistics.Pnl      += orderDetails.Quantity * orderDetails.FillDetails.Last().FillPrice;
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns Position Statistics for the requested Symbol
        /// </summary>
        /// <param name="symbol">Symbol Name</param>
        /// <returns></returns>
        public PositionStatistics GetPositionStatistics(string symbol)
        {
            PositionStatistics positionStatistics = null;

            // Get information from local dictionary
            _positionStatisticsDictionary.TryGetValue(symbol, out positionStatistics);

            return(positionStatistics);
        }