public static MarketSummaryMessage Parse(string message, MarketSummaryHandler marketSummaryHandler) { if (marketSummaryHandler.FieldNames.Count == 0) { // The first line received will be field names, which will tell us what we're getting and in what order foreach (var fieldName in message.SplitFeedMessage()) { // Work out which field we're dealing with, and then add it to a map of fieldname => marketSummaryDynamicFieldset if (!Enum.TryParse <MarketSummaryDynamicFieldset>(fieldName, out var marketSummaryDynamicFieldsetKey)) { throw new Exception($"Unknown Market Summary Field Type: {fieldName}"); } // this is all done in the same order that values will be received so everything will just work marketSummaryHandler.FieldNames.Add(marketSummaryDynamicFieldsetKey); } return(null); } var index = 0; var values = message.SplitFeedMessage(); return(new MarketSummaryMessage(values, marketSummaryHandler)); }
public Task <IEnumerable <MarketSummaryMessage> > Get5MinuteSnapshotSummaryAsync(SecurityType securityType, int listedMarketGroupId, string requestId = null) { var request = _marketSummaryRequestFormatter.Req5MinuteSnapshotSummary(securityType, listedMarketGroupId, requestId); var marketSummaryHandler = new MarketSummaryHandler(); return(string.IsNullOrEmpty(requestId) ? GetMessagesAsync(request, marketSummaryHandler.GetMarketSummaryMessages) : GetMessagesAsync(request, marketSummaryHandler.GetMarketSummaryMessagesWithRequestId)); }
public Task <IEnumerable <MarketSummaryMessage> > GetEndOfDayFundamentalSummaryAsync(SecurityType securityType, int listedMarketGroupId, DateTime date, string requestId = null) { var request = _marketSummaryRequestFormatter.ReqFundamentalSummary(securityType, listedMarketGroupId, date, requestId); var marketSummaryHandler = new MarketSummaryHandler(); return(string.IsNullOrEmpty(requestId) ? GetMessagesAsync(request, marketSummaryHandler.GetMarketSummaryMessages) : GetMessagesAsync(request, marketSummaryHandler.GetMarketSummaryMessagesWithRequestId)); }
public void Should_Parse_MarketSummaryMessage() { // Arrange var requestId = "TEST"; var symbol = "MSFT"; var last = 1.234D; var tradeDate = new DateTime(2021, 03, 24); var tradeTime = new TimeSpan(11, 42, 12); var message1 = "RequestId,Symbol,Last,TradeDate,TradeTime"; var message2 = "TEST,MSFT,1.234,20210324,114212"; var values = new string[] { "TEST", "MSFT", "1.234", "20210324", "114212" }; var marketSummaryHandler = new MarketSummaryHandler(); // Act var marketSummaryMessage1Parsed = MarketSummaryMessage.Parse(message1, marketSummaryHandler); var marketSummaryMessage2Parsed = MarketSummaryMessage.Parse(message2, marketSummaryHandler); var marketSummaryMessage1 = new MarketSummaryMessage(symbol, 0, 0, last, null, null, tradeDate, tradeTime, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, requestId); var marketSummaryMessage2 = new MarketSummaryMessage(values, marketSummaryHandler); // Assert // MarketSummaryMessage1Parsed should be null, as it was the Fieldname pass Assert.IsNull(marketSummaryMessage1Parsed); Assert.IsNotNull(marketSummaryMessage2Parsed); Assert.AreEqual(marketSummaryMessage2Parsed, marketSummaryMessage1); Assert.AreEqual(marketSummaryMessage2Parsed, marketSummaryMessage2); }
public static MarketSummaryMessage ParseWithRequestId(string message, MarketSummaryHandler marketSummaryHandler) { // no difference with dynamic - RequestId will be a field return(Parse(message, marketSummaryHandler)); }
public MarketSummaryMessage(string[] values, MarketSummaryHandler marketSummaryHandler) { for (var index = 0; index < values.Length; index++) { switch (marketSummaryHandler.FieldNames[index]) { case MarketSummaryDynamicFieldset.RequestId: RequestId = (string)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.RequestId].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Symbol: Symbol = (string)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Symbol].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Exchange: ExchangeId = (int)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Exchange].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Type: SecurityType = (SecurityType)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Type].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Last: Last = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Last].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.TradeSize: TradeSize = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.TradeSize].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.TradedMarket: TradedMarket = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.TradedMarket].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.TradeDate: TradeDate = (DateTime?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.TradeDate].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.TradeTime: TradeTime = (TimeSpan?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.TradeTime].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Open: Open = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Open].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.High: High = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.High].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Low: Low = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Low].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Close: Close = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Close].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Bid: Bid = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Bid].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.BidMarket: BidMarket = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.BidMarket].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.BidSize: BidSize = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.BidSize].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Ask: Ask = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Ask].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.AskMarket: AskMarket = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.AskMarket].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.AskSize: AskSize = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.AskSize].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Volume: Volume = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Volume].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.PDayVolume: PDayVolume = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.PDayVolume].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.UpVolume: UpVolume = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.UpVolume].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.DownVolume: DownVolume = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.DownVolume].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.NeutralVolume: NeutralVolume = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.NeutralVolume].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.TradeCount: TradeCount = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.TradeCount].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.UpTrades: UpTrades = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.UpTrades].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.DownTrades: DownTrades = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.DownTrades].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.NeutralTrades: NeutralTrades = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.NeutralTrades].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.VWAP: VWAP = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.VWAP].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.MutualDiv: MutualDiv = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.MutualDiv].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.SevenDayYield: SevenDayYield = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.SevenDayYield].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.OpenInterest: OpenInterest = (int?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.OpenInterest].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Settlement: Settlement = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Settlement].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.SettlementDate: SettlementDate = (DateTime?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.SettlementDate].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.ExpirationDate: ExpirationDate = (DateTime?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.ExpirationDate].Invoke(values[index]); break; case MarketSummaryDynamicFieldset.Strike: Strike = (double?)marketSummaryHandler.FieldConvertors[(int)MarketSummaryDynamicFieldset.Strike].Invoke(values[index]); break; } } }