public bool Start() { try { if (!IsStarted) { if (!PositionMonitorUtilities.IsMonitoring) { PositionMonitorUtilities.Info(String.Format("Cannot start {0} before starting monitor", Name)); } else { Update(); PositionMonitorUtilities.OnRefresh += utilities_OnRefresh; IsStarted = true; StartSubscriber(); } } } catch (Exception ex) { PositionMonitorUtilities.Error("Unable to start " + Name, ex); IsStarted = false; } return(IsStarted); }
private void m_messageUtilities_OnReaderStopped(object sender, ServiceStoppedEventArgs e) { IsSubscribed = false; if (e.Exception == null) { PositionMonitorUtilities.Info(e.Message); } else { PositionMonitorUtilities.Error(e.Message, e.Exception); } lock (m_portfolioLock) { foreach (HugoDataSet.PortfolioRow row in m_portfolio.Rows) { row.SubscriptionStatus = SubscriptionStatus.Unsubscribed.ToString(); row.UpdateTime = DateTime.Now - DateTime.Today; } } if (m_refreshEventHandler != null) { m_refreshEventHandler(this, new EventArgs()); } }
private void Dispose(bool disposing) { if (disposing) { if (m_portfolio != null) { m_portfolio.Dispose(); m_portfolio = null; } if (m_messageUtilities != null) { m_messageUtilities.Dispose(); m_messageUtilities = null; } PositionMonitorUtilities.Info(Name + " disposed"); } }
public bool StartSubscriber() { try { if (!IsSubscribed) { int rowCount = 0; if (IsSubscribed = m_messageUtilities.StartSubscriber(Properties.Settings.Default.MarketDataHost, Properties.Settings.Default.MarketDataPort)) { lock (m_portfolioLock) { foreach (HugoDataSet.PortfolioRow row in m_portfolio.Rows) { if (!row.IsCurrent_PositionNull()) { if (row.Current_Position != 0) { row.SubscriptionStatus = SubscriptionStatus.Subscribed.ToString(); m_messageUtilities.Subscribe(row.Symbol, row.QuoteType, row); rowCount++; } } } } } PositionMonitorUtilities.Info(String.Format("{0} subscribed to {1} symbols", Name, rowCount)); } } catch (Exception ex) { PositionMonitorUtilities.Error(Name + " unable to subscribe to market data", ex); StopSubscriber(); } return(IsSubscribed); }
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); }
private void m_messageUtilities_OnInfo(object sender, LoggingEventArgs e) { PositionMonitorUtilities.Info(e.Message); }