Exemplo n.º 1
0
        private bool UpdatePortfolio(HugoDataSet.CurrentPositionsRow[] rows)
        {
            try
            {
                List <HugoDataSet.PortfolioRow> m_subscribeList = new List <HugoDataSet.PortfolioRow>();
                List <string> m_unsubscribeList = new List <string>();

                lock (m_portfolioLock)
                {
                    foreach (HugoDataSet.CurrentPositionsRow positionRow in rows)
                    {
                        HugoDataSet.PortfolioRow portfolioRow = m_portfolio.Rows.Find(new string[] { positionRow.AcctName, positionRow.Symbol }) as HugoDataSet.PortfolioRow;
                        if (portfolioRow == null)
                        {
                            portfolioRow          = m_portfolio.NewPortfolioRow();
                            portfolioRow.AcctName = positionRow.AcctName;
                            portfolioRow.Symbol   = positionRow.Symbol;

                            if (!positionRow.IsExpirationDateNull())
                            {
                                portfolioRow.ExpirationDate = positionRow.ExpirationDate;
                            }
                            if (!positionRow.IsStrikePriceNull())
                            {
                                portfolioRow.StrikePrice = positionRow.StrikePrice;
                            }
                            if (!positionRow.IsOptionTypeNull())
                            {
                                portfolioRow.OptionType = positionRow.OptionType;
                            }

                            portfolioRow.IsStock  = positionRow.IsStock;
                            portfolioRow.IsOption = positionRow.IsOption;
                            portfolioRow.IsFuture = positionRow.IsFuture;
                            m_portfolio.Rows.Add(portfolioRow);
                        }
                        portfolioRow.SOD_Position       = positionRow.SOD_Position;
                        portfolioRow.SOD_Price          = positionRow.SOD_Price;
                        portfolioRow.SOD_Market_Value   = positionRow.SOD_Market_Value;
                        portfolioRow.Change_in_Position = positionRow.Change_in_Position;
                        portfolioRow.Change_in_Cost     = positionRow.Change_in_Cost;
                        portfolioRow.Current_Position   = positionRow.Current_Position;
                        portfolioRow.Current_Cost       = positionRow.Current_Cost;

                        if (IsSubscribed && (portfolioRow.SubscriptionStatus != SubscriptionStatus.Subscribed.ToString()) && !portfolioRow.IsCurrent_PositionNull())
                        {
                            if (portfolioRow.Current_Position != 0)
                            {
                                portfolioRow.SubscriptionStatus = SubscriptionStatus.Subscribed.ToString();
                                m_subscribeList.Add(portfolioRow);
                            }
                        }
                    }

                    foreach (HugoDataSet.PortfolioRow portfolioRow in m_portfolio.Rows)
                    {
                        if ((portfolioRow.Current_Position == 0) && (portfolioRow.SubscriptionStatus == SubscriptionStatus.Subscribed.ToString()))
                        {
                            portfolioRow.SubscriptionStatus = SubscriptionStatus.Unsubscribed.ToString();
                            m_unsubscribeList.Add(portfolioRow.Symbol);
                        }
                    }
                }

                if (IsSubscribed)
                {
                    if (m_subscribeList.Count > 0)
                    {
                        foreach (HugoDataSet.PortfolioRow row in m_subscribeList)
                        {
                            m_messageUtilities.Subscribe(row.Symbol, row.QuoteType, row);
                        }
                        PositionMonitorUtilities.Info(String.Format("{0} subscribed to {1} new symbols", Name, m_subscribeList.Count));
                    }
                    if (m_unsubscribeList.Count > 0)
                    {
                        foreach (string ticker in m_unsubscribeList)
                        {
                            m_messageUtilities.Unsubscribe(ticker);
                        }
                        PositionMonitorUtilities.Info(String.Format("{0} unsubscribed from {1} symbols", Name, m_unsubscribeList.Count));
                    }
                }
            }
            catch (Exception ex)
            {
                PositionMonitorUtilities.Error("Unable to fill current position table " + Name, ex);
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        private void m_messageUtilities_OnQuote(object sender, QuoteEventArgs e)
        {
            string ticker = null;

            try
            {
                if (IsSubscribed)
                {
                    ticker = e.Quote.Ticker;
                    HugoDataSet.PortfolioRow row = e.ClientObject as HugoDataSet.PortfolioRow;

                    lock (m_portfolioLock)
                    {
                        bool bUpdated = false;
                        if (e.Quote.SubscriptionStatus != SubscriptionStatus.Unchanged)
                        {
                            row.SubscriptionStatus = e.Quote.SubscriptionStatus.ToString();
                            bUpdated = true;
                        }

                        if (!row.Closed)
                        {
                            if (e.Quote.HasLast)
                            {
                                row.LastPrice = e.Quote.Last;
                                bUpdated      = true;
                            }

                            if (e.Quote.HasBid)
                            {
                                row.Bid  = e.Quote.Bid;
                                bUpdated = true;
                            }
                            if (e.Quote.HasAsk)
                            {
                                row.Ask  = e.Quote.Ask;
                                bUpdated = true;
                            }
                            if (e.Quote.HasDelta)
                            {
                                row.Delta = e.Quote.Delta;
                                bUpdated  = true;
                            }
                            if (e.Quote.HasGamma)
                            {
                                row.Gamma = e.Quote.Gamma;
                                bUpdated  = true;
                            }
                            if (e.Quote.HasTheta)
                            {
                                row.Theta = e.Quote.Theta;
                                bUpdated  = true;
                            }
                            if (e.Quote.HasVega)
                            {
                                row.Vega = e.Quote.Vega;
                                bUpdated = true;
                            }
                            if (e.Quote.HasImpliedVol)
                            {
                                row.ImpliedVol = e.Quote.ImpliedVol;
                                bUpdated       = true;
                            }

                            if (e.Quote.HasClose)
                            {
                                row.ClosingPrice = e.Quote.Close;
                                bUpdated         = true;
                            }

                            if (e.Quote.OpenStatus == OpenStatus.Closed)
                            {
                                row.Closed = true;
                                bUpdated   = true;
                            }

                            if (e.Quote.OpenStatus == OpenStatus.Open)
                            {
                                row.Closed = false;
                                bUpdated   = true;
                            }

                            if (bUpdated)
                            {
                                row.UpdateTime = DateTime.Now - DateTime.Today;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                PositionMonitorUtilities.Error(Name + " unable to process quote for " + (ticker ?? "<NULL>"), ex);
            }
        }