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 }
public List <String> SearchTicker(String ticker) { List <String> listTicker = new List <string>(); // request.AsElement.SetElement("partialMatch", true); request.AsElement.SetElement("query", ticker);// this plus the previous line permits to retrieve all the thicker that begins with T request.AsElement.SetElement("languageOverride", "LANG_OVERRIDE_NONE"); request.AsElement.SetElement("maxResults", 10); session.SendRequest(request, null); bool done = false; while (!done) { // Grab the next Event object Event eventObject = session.NextEvent(); // If this event type is Response then process the messages if (eventObject.Type == Event.EventType.RESPONSE) { // Loop over all of the messages in this Event foreach (Message msg in eventObject.GetMessages()) { Console.WriteLine(msg); Element secDataArray = msg.GetElement("results"); for (int index = 0; index < secDataArray.NumValues - 1; index++) { Element fieldData = secDataArray.GetValueAsElement(index); if (fieldData.HasElement("security")) { listTicker.Add(fieldData.GetElementAsString("security")); } } } done = true; } } return(listTicker); }