private bool BuildPortfolioRow(List <HugoDataSet.PortfolioRow> subscribeList, List <string> indicesForNetting, HugoDataSet.CurrentPositionsRow positionRow, int updateCounter) { try { bool bCheckForNetting; bCheckForNetting = false; HugoDataSet.PortfolioRow portfolioRow = m_portfolio.Rows.Find(new string[] { positionRow.AcctName, positionRow.Symbol }) as HugoDataSet.PortfolioRow; if (portfolioRow == null) { bCheckForNetting = true; 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; } if (!positionRow.IsUnderlyingSymbolNull()) { portfolioRow.UnderlyingSymbol = positionRow.UnderlyingSymbol; } // Two multipliers are necessary // Multiplier is used to determine the deltas on the associated index // PriceMultiplier is used to determine the market value fo the option itself portfolioRow.Multiplier = (short)Math.Round(positionRow.Multiplier * positionRow.AssociatedIndexMultiplier, 0); portfolioRow.PriceMultiplier = positionRow.Multiplier; portfolioRow.IsStock = positionRow.IsStock; portfolioRow.IsOption = positionRow.IsOption; portfolioRow.IsFuture = positionRow.IsFuture; m_portfolio.Rows.Add(portfolioRow); } else { // if current position has changed, we must perform netting if (portfolioRow.Current_Position != positionRow.Current_Position) { bCheckForNetting = true; } } portfolioRow.Current_Position = positionRow.IsCurrent_PositionNull() ? 0 : positionRow.Current_Position; portfolioRow.SOD_Position = positionRow.IsSOD_PositionNull() ? 0 : 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_Cost = positionRow.Current_Cost; portfolioRow.UpdateCounter = updateCounter; if (IsSubscribed && (portfolioRow.SubscriptionStatus != SubscriptionStatus.Subscribed.ToString())) { // must subscribe to stocks with 0 positions in case we have associated options (so we can calculated dollar deltas) if ((portfolioRow.Current_Position != 0) || (portfolioRow.SOD_Position != 0) || (portfolioRow.IsStock == 1)) { portfolioRow.SubscriptionStatus = SubscriptionStatus.Subscribed.ToString(); subscribeList.Add(portfolioRow); } } if (bCheckForNetting) { if ((portfolioRow.IsOption == 1) || (portfolioRow.IsFuture == 1)) { if (!indicesForNetting.Contains(portfolioRow.UnderlyingSymbol)) { indicesForNetting.Add(portfolioRow.UnderlyingSymbol); } } } return(true); } catch (Exception ex) { PositionMonitorUtilities.Error(Name + " unable to build portfolio row", ex); return(false); } }
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); }