private bool ManageSubscriptions(List <HugoDataSet.PortfolioRow> subscribeList, List <string> unsubscribeList)
        {
            try
            {
                if (IsSubscribed)
                {
                    if (subscribeList.Count > 0)
                    {
                        foreach (HugoDataSet.PortfolioRow row in subscribeList)
                        {
                            m_messageUtilities1.Subscribe(row.Symbol, row.QuoteType, row);
                            PositionMonitorUtilities.Info(String.Format("{0} now subscribed to {1}", Name, row.Symbol));
                        }
                        PositionMonitorUtilities.Info(String.Format("{0} subscribed to {1} new symbols", Name, subscribeList.Count));
                    }
                    if (unsubscribeList.Count > 0)
                    {
                        foreach (string ticker in unsubscribeList)
                        {
                            m_messageUtilities1.Unsubscribe(ticker);
                            PositionMonitorUtilities.Info(String.Format("{0} now unsubscribed from {1}", Name, ticker));
                        }
                        PositionMonitorUtilities.Info(String.Format("{0} unsubscribed from {1} symbols", Name, unsubscribeList.Count));
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                PositionMonitorUtilities.Error(Name + " unable to manage subscriptions", ex);
                return(false);
            }
        }
Esempio n. 2
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            foreach (ISubscriptionId subscription in m_subscriptions)
            {
                if (subscription.Symbol == textBoxStock.Text)
                {
                    m_subscriptions.Remove(subscription);
                    dataSet1.StockQuotes.Rows.Remove((DataSet1.StockQuotesRow)subscription.QuoteObject);

                    if (m_nativeUtilities.IsConnected)
                    {
                        m_nativeUtilities.Unsubscribe(new string[] { subscription.Symbol });
                    }
                    else if (m_messageUtilities.IsSubscriberStarted)
                    {
                        m_messageUtilities.Unsubscribe(subscription.Symbol);
                    }
                    break;
                }
            }
        }
Esempio n. 3
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);
        }