protected void MarketDataAdapterReplyEvent(Reply reply) { // process asynchronous reply try { // check for errors first if (reply == null) { throw new ApplicationException( String.Format("MarketDataAdapter_ReplyEvent() received null!")); } if (reply.ReplyError != null) { throw new ApplicationException( $"MarketDataAdapter_ReplyEvent() failed: {reply.ReplyError.DisplayName}: {reply.ReplyError.Description}"); } string debugMsg = String.Format("[Received]"); try { debugMsg = debugMsg + $"[ReplyType={reply.ReplyType}]"; if (reply.Request != null) { debugMsg = debugMsg + $"[ReqId={reply.Request.RequestId}]"; SecuritiesDataCollection securityColl = reply.GetSecurityDataItems(); foreach (SecurityDataItem security in securityColl) { debugMsg = debugMsg + $"[{security.Security.Name}]"; debugMsg = security.FieldsData.Cast <FieldDataItem>().Aggregate(debugMsg, (current, dataNodeList) => current + $"[{dataNodeList.Field.Mnemonic}]"); } // map Bloomberg requestid to our subsId RealtimeRequestMap subsMap; lock (SubsMapExternal) { SubsMapExternal.TryGetValue(reply.Request.RequestId, out subsMap); } if (subsMap != null) { if (DateTimeOffset.Now > subsMap.SubsExpires) { MarketDataAdapter.CancelRequest(reply.Request.RequestId); Logger.LogDebug("[Cancelled][ReqId={1}][SubsId={0}]", subsMap.InternalRequestId, reply.Request.RequestId); } Dictionary <string, BasicQuotation> providerResults = BuildProviderResultsIndex(reply); ConsumerCallback(subsMap.InternalRequestId, new QuotedAssetSet { assetQuote = Enumerable.ToArray(ConvertProviderResultsToStandardValuations(providerResults, subsMap.RequestContext)) }); } } else { debugMsg = debugMsg + "[RequestIdUnknown]"; } } catch (Exception e) { debugMsg = debugMsg + Environment.NewLine + "!!!EXCEPTION!!! " + e.Message; } finally { Logger.LogDebug(debugMsg); } } catch (Exception ex) { Logger.Log(ex); // don't rethrow } }
private Dictionary <string, BasicQuotation> BuildProviderResultsIndex(Reply reply) { // build the provider result set DateTime dtNow = DateTime.Now; //InformationSource informationSource = ; // key = provider instrument id / field name var results = new Dictionary <string, BasicQuotation>(); SecuritiesDataCollection securityColl = reply.GetSecurityDataItems(); foreach (SecurityDataItem security in securityColl) { string instrName = security.Security.Name; //int fieldCount = security.FieldsData.Count; //BasicAssetValuation quote = new BasicAssetValuation() { objectReference = new AnyAssetReference() { href = instrName } }; //quote.quote = new BasicQuotation[fieldCount]; int fieldNum = 0; foreach (FieldDataItem dataNodeList in security.FieldsData) { string fieldName = dataNodeList.Field.Mnemonic; string providerQuoteKey = FormatProviderQuoteKey(instrName, fieldName); var providerQuote = new BasicQuotation(); // field value object value = null; string measureTypeAsString = AssetMeasureEnum.Undefined.ToString(); string quoteUnitsAsString = PriceQuoteUnitsEnum.Undefined.ToString(); try { DataPoint point = dataNodeList.DataPoints[0]; value = point.Value; if (point.IsError) { // bloomberg error ReplyError replyError = point.ReplyError; Logger.LogDebug("ReplyError: {0}/{1}={2}/{3}/{4}", instrName, fieldName, replyError.Code, replyError.DisplayName, replyError.Description); quoteUnitsAsString = String.Format("{0}:{1}", replyError.Code, replyError.DisplayName); } else if (value == null) { // value mia Logger.LogDebug("DataNullMissing: {0}/{1}='{2}'", instrName, fieldName); quoteUnitsAsString = "DataNullMissing"; } else if (value.GetType() == typeof(ReplyError)) { // bloomberg error var replyError = (ReplyError)value; Logger.LogDebug("ReplyError: {0}/{1}={2}/{3}/{4}", instrName, fieldName, replyError.Code, replyError.DisplayName, replyError.Description); quoteUnitsAsString = $"{replyError.Code}:{replyError.DisplayName}"; } else if ((value is string) && (value.ToString().ToLower() == "n.a.")) { // not available? Logger.LogDebug("DataNotAvailable: {0}/{1}='{2}'", instrName, fieldName, value.ToString()); quoteUnitsAsString = "DataNotAvailable"; } else { providerQuote.value = Convert.ToDecimal(value); providerQuote.valueSpecified = true; // When the quote was computed (FpML definition) i.e. when the provider published it providerQuote.valuationDateSpecified = true; providerQuote.valuationDate = point.Time; } } catch (Exception e) { Logger.LogDebug("Exception: {0}/{1}='{2}' {3}", instrName, fieldName, value, e); quoteUnitsAsString = $"{e.GetType().Name}:{e.Message}"; } providerQuote.measureType = new AssetMeasureType { Value = measureTypeAsString }; providerQuote.quoteUnits = new PriceQuoteUnits { Value = quoteUnitsAsString }; providerQuote.informationSource = new[] { new InformationSource { rateSource = new InformationProvider { Value = ProviderId.ToString() }, rateSourcePage = new RateSourcePage { Value = instrName + "/" + fieldName } } }; // When the quote was observed or derived (FpML definition) i.e. now. providerQuote.timeSpecified = true; providerQuote.time = dtNow; results[providerQuoteKey] = providerQuote; // next field fieldNum++; } // foreach field } // foreach instr return(results); }