private void ShowCompletedInstrument(BloombergDataInstrument instr) { if (InstrumentCompleteChanged != null) { InstrumentCompleteChanged(instr); } }
private void GetData(BloombergDataInstrument instrument, BB.Element fields, BB.Element secData) { #region security errors if (secData.HasElement(SECURITY_ERROR)) { instrument.IsSecurityValid = false; BB.Element error = secData.GetElement(SECURITY_ERROR); UpdateStatus(string.Format("Security error for ticker {0} : {1}", instrument.Ticker, error.GetElementAsString(MESSAGE))); instrument.SecurityErrors += (error.GetElementAsString(MESSAGE) + "; "); } #endregion #region field errors if (secData.HasElement(FIELD_EXCEPTIONS)) { instrument.HasFieldErrors = true; // process error BB.Element error = secData.GetElement(FIELD_EXCEPTIONS); for (int errorIndex = 0; errorIndex < error.NumValues; errorIndex++) { BB.Element errorException = error.GetValueAsElement(errorIndex); BB.Element errorInfo = errorException.GetElement(ERROR_INFO); instrument.BBFields[errorException.GetElementAsString(FIELD_ID)].Error = errorInfo.GetElementAsString(MESSAGE); instrument.HasFieldErrors = true; string msg = string.Format("Field error for ticker {0} : Field {1}: {2}", instrument.Ticker, errorException.GetElementAsString(FIELD_ID), errorInfo.GetElementAsString(MESSAGE)); UpdateStatus(msg); } } #endregion #region get the data if (instrument.BBFields != null) { lock (lockObject) { foreach (string bbField in instrument.BBFields.Keys.ToList()) { if (fields.HasElement(bbField)) { BB.Element item = fields.GetElement(bbField); if (item.IsArray) { instrument.BBFields[bbField].Value = processBulkData(item); } else { // set the value in the instrument field item instrument.BBFields[bbField].Value = item.GetValue(); } } } } } #endregion }
/// <summary> /// Finds the sent instrument by GUID. /// </summary> /// <param name="guid">The GUID.</param> /// <returns></returns> private BloombergDataInstrument FindSentInstrumentByGuid(Guid guid) { BloombergDataInstrument instr = null; foreach (BloombergDataInstrument bbdi in sentToBB) { if (bbdi.GUID == guid) { instr = bbdi; break; } } return(instr); }
public void TestForReference() { List <BloombergDataInstrument> bbdis = new List <BloombergDataInstrument>(); BloombergDataInstrument bbdi = new BloombergDataInstrument(); bbdi.ID = 0; bbdi.Ticker = "VOD LN Equity"; //bbdi.Ticker = "BBG002626686 BUID"; //bbdi.SecurityType = "Equity"; bbdi.Type = BloombergDataInstrumentType.Security; bbdi.BBFields = new Dictionary <string, BloombergDataInstrumentField>(); bbdi.BBFields.Add("PX_LAST", new BloombergDataInstrumentField("PX_LAST")); bbdis.Add(bbdi); /* * bbdi.ID = 0; * bbdi.Ticker = "US0200021014 EQUITY"; * bbdi.SecurityType = "EQUITY"; * bbdi.Type = BloombergDataInstrumentType.Security; * bbdi.BBFields = new Dictionary<string, object>(); * bbdi.BBFields.Add("ID_ISIN", null); * bbdi.BBFields.Add("BID", null); * bbdi.BBFields.Add("ASK", null); * bbdi.BBFields.Add("PX_CLOSE_DT", null); * bbdis.Add(bbdi); * * bbdi = new BloombergDataInstrument(); * bbdi.ID = 1; * bbdi.Ticker = "RBS LN EQUITY"; * bbdi.SecurityType = "EQUITY"; * bbdi.Type = BloombergDataInstrumentType.Security; * bbdi.BBFields = new Dictionary<string, object>(); * bbdi.BBFields.Add("ID_GAVIN", null); * bbdi.BBFields.Add("PX_LAST", null); * bbdis.Add(bbdi); */ // BloombergData bbd = new BloombergData(new System.Collections.Specialized.StringCollection(), "*****@*****.**", "testing Bloomberg v3 api", ";"); // OR BloombergData bbd = new BloombergData(); bbd.InstrumentCompleteChanged += new BloombergData.InstrumentComplete(bbd_InstrumentCompleteChanged); bbd.PercentCompleteChanged += new BloombergData.PercentComplete(bbd_PercentCompleteChanged); bbd.ProcessCompleted += new BloombergData.ProcessStatus(bbd_ProcessCompleted); bbd.StatusChanged += new BloombergData.StatusUpdate(bbd_StatusChanged); bbd.GetBloombergData(bbdis); }
/// <summary> /// Gets the field value from the BloombergData BBField collection. /// </summary> /// <param name="instrument">The instrument.</param> /// <param name="fieldName">Name of the field.</param> /// <returns></returns> private static object GetFieldValue(BloombergDataInstrument instrument, string fieldName) { object fieldValue = null; try { if (instrument.BBFields != null) { if (instrument.BBFields.ContainsKey(fieldName)) { fieldValue = instrument.BBFields[fieldName].Value; } } } catch { fieldValue = null; } return(fieldValue); }
static void bbd_InstrumentCompleteChanged(BloombergDataInstrument instr) { string ticker = instr.Ticker; string value = string.Empty; string error = string.Empty; Console.WriteLine("BloombergDataInstrument completed " + ticker); foreach (string key in instr.BBFields.Keys) { if (instr.BBFields[key].Value == null) { value = "[NULL]"; } else { value = instr.BBFields[key].Value.ToString(); } error = instr.BBFields[key].Error; Console.WriteLine(string.Format("Ticker - {0} : Key - {1} : Value - {2} : Error - {3}", ticker, key, value)); } }
public void TestForHistory() { List <BloombergDataInstrument> bbdis = new List <BloombergDataInstrument>(); BloombergDataInstrument bbdi = new BloombergDataInstrument(); bbdi.ID = 0; bbdi.Ticker = "EUR001M INDEX"; bbdi.SecurityType = "INDEX"; bbdi.BBFields = new Dictionary <string, BloombergDataInstrumentField>(); bbdi.BBFields.Add("PX_LAST", new BloombergDataInstrumentField("PX_LAST")); bbdis.Add(bbdi); BloombergData bbd = new BloombergData(new System.Collections.Specialized.StringCollection(), "*****@*****.**", "testing Bloomberg v3 api", ";"); bbd.InstrumentCompleteChanged += new BloombergData.InstrumentComplete(bbd_InstrumentCompleteChanged); bbd.PercentCompleteChanged += new BloombergData.PercentComplete(bbd_PercentCompleteChanged); bbd.ProcessCompleted += new BloombergData.ProcessStatus(bbd_ProcessCompleted); bbd.StatusChanged += new BloombergData.StatusUpdate(bbd_StatusChanged); bbd.GetBloombergData(bbdis, DateTime.Today.AddDays(-1)); }
/// <summary> /// Processes the Bloomberg subscription data event. /// </summary> /// <param name="eventObj">The event obj.</param> /// <param name="session">The session.</param> private void processSubscriptionDataEvent(BB.Event eventObj, BB.Session session) { try { // process message foreach (BB.Message msg in eventObj.GetMessages()) { #region find instrument Guid reqGUID = (Guid)msg.CorrelationID.Object; // check for duplicate replies just in case if (guids.Contains(reqGUID)) { return; } else { guids.Add(reqGUID); } // find the correct instrument BloombergDataInstrument bbdi = FindSentInstrumentByGuid(reqGUID); if (bbdi == null) { UpdateStatus("Unable to find received instrument by Guid - " + reqGUID.ToString()); continue; } #endregion UpdateStatus(string.Format("Received {0} of {1} requests : {2}", guids.Count, sentToBB.Count, bbdi.Ticker)); if (msg.HasElement("responseError")) { BB.Element error = msg.GetElement(RESPONSE_ERROR); string responseError = error.GetElementAsString(SUBCATEGORY); UpdateStatus("Response error : " + error.GetElementAsString(MESSAGE)); CheckForLimits(responseError); bbdi.HasFieldErrors = true; continue; } BB.Element secDataArray = msg.GetElement(SECURITY_DATA); #region process security data // process security data int numberOfSecurities = secDataArray.NumValues; for (int index = 0; index < numberOfSecurities; index++) { if (msg.MessageType.Equals(Bloomberglp.Blpapi.Name.GetName(BLP_REFERENCE_RESPONSE))) { // just contains the one element, which is actually a sequence BB.Element secData = secDataArray.GetValueAsElement(index); BB.Element fields = secData.GetElement(FIELD_DATA); GetData(bbdi, fields, secData); } else if (msg.MessageType.Equals(Bloomberglp.Blpapi.Name.GetName(BLP_HISTORICAL_RESPONSE))) { // Historical is handled slightly different. Can contain many elements each with possibly multiple values foreach (BB.Element secData in secDataArray.Elements) { if (secData.Name != FIELD_DATA) { continue; } for (int pointIndex = 0; pointIndex < secData.NumValues; pointIndex++) { BB.Element fields = secData.GetValueAsElement(pointIndex); GetData(bbdi, fields, secData); } } } } #endregion ShowCompletionPercentage(guids.Count, sentToBB.Count); ShowCompletedInstrument(bbdi); } } catch (Exception ex) { UpdateStatus("Error occurred processing reply : " + ex.Message); } finally { if (guids.Count == sentToBB.Count) // we are done { ShowCompletionPercentage(1, 1); ProcessComplete(); } } }
/// <summary> /// Gets the int value from the BloombergData BBField collection. /// </summary> /// <param name="instrument">The instrument.</param> /// <param name="fieldName">Name of the field.</param> /// <returns></returns> public static int?GetInt(BloombergDataInstrument instrument, string fieldName) { object fieldValue = GetFieldValue(instrument, fieldName); return(GetInt(fieldValue)); }
/// <summary> /// Gets the date time value from the BloombergData BBField collection. /// </summary> /// <param name="instrument">The instrument.</param> /// <param name="fieldName">Name of the field.</param> /// <returns></returns> public static DateTime?GetDateTime(BloombergDataInstrument instrument, string fieldName) { object fieldValue = GetFieldValue(instrument, fieldName); return(GetDateTime(fieldValue)); }
/// <summary> /// Gets the decimal value from the BloombergData BBField collection. /// </summary> /// <param name="instrument">The instrument.</param> /// <param name="fieldName">Name of the field.</param> /// <returns></returns> public static decimal?GetDecimal(BloombergDataInstrument instrument, string fieldName) { object fieldValue = GetFieldValue(instrument, fieldName); return(GetDecimal(fieldValue)); }