public void TestForReference2() { List <BloombergDataInstrument> bbdis = new List <BloombergDataInstrument>(); BloombergDataInstrument bbdi = new BloombergDataInstrument(); bbdi.RequestType = BloombergDataInstrument.eRequestType.Reference; bbdi.ID = 0; // bbdi.Ticker = "IT0004840788 Govt"; 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")); bbdi.BBFields.Add("NAME", new BloombergDataInstrumentField("NAME")); bbdis.Add(bbdi); new BloombergApiController(new BergController()).GetBbgData(bbdis); foreach (var item in bbdis) { foreach (var field in item.BBFields.Values) { Console.WriteLine(field.Name + ": " + field.Value); } } }
public void TestForHistory() { List <BloombergDataInstrument> bbdis = new List <BloombergDataInstrument>(); BloombergDataInstrument bbdi = new BloombergDataInstrument(); bbdi.RequestType = BloombergDataInstrument.eRequestType.Historic; bbdi.ID = 0; bbdi.Ticker = "VOD LN Equity"; bbdi.SecurityType = "Equity"; bbdi.Type = BloombergDataInstrumentType.Security; bbdi.BBFields = new Dictionary <string, BloombergDataInstrumentField>(); bbdi.BBFields.Add("PX_LAST", new BloombergDataInstrumentField("PX_LAST")); bbdi.DateFrom = DateTime.Today.AddDays(-12); bbdi.DateTo = DateTime.Today.AddDays(-5); bbdis.Add(bbdi); BloombergData bbd = new BloombergData(new StringCollection(), "*****@*****.**", "testing Bloomberg v3 api", ";"); bbd.InstrumentCompleteChanged += bbd_InstrumentCompleteChanged; bbd.PercentCompleteChanged += bbd_PercentCompleteChanged; bbd.ProcessCompleted += bbd_ProcessCompleted; bbd.StatusChanged += bbd_StatusChanged; bbd.GetBloombergData(bbdis); }
private void AddBBfield(BloombergDataInstrument bdi, RequestItemField Field, int id) { // Ignore duplicate field names if (!bdi.BBFields.ContainsKey(Field.Key)) { BloombergDataInstrumentField field = new BloombergDataInstrumentField(Field.Key); field.ID = id; foreach (OverrideField oField in Field.OverrideFields) { field.FieldOverrides.Add(oField.Name, oField.Value); } bdi.BBFields.Add(Field.Key, field); } }
public void TestForReference() { List <BloombergDataInstrument> bbdis = new List <BloombergDataInstrument>(); BloombergDataInstrument bbdi = new BloombergDataInstrument(); bbdi.RequestType = BloombergDataInstrument.eRequestType.Reference; 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 += bbd_InstrumentCompleteChanged; bbd.PercentCompleteChanged += bbd_PercentCompleteChanged; bbd.ProcessCompleted += bbd_ProcessCompleted; bbd.StatusChanged += bbd_StatusChanged; bbd.GetBloombergData(bbdis); }
/// <summary> /// unpack the dataset into a list of Tickers/fields /// </summary> /// <param name="PriceDate"></param> /// <param name="ds"></param> /// <returns></returns> internal static List <BloombergDataInstrument> GetTickers(DateTime PriceDate, DataSet ds) { Dictionary <string, BloombergDataInstrument> ticker_map = new Dictionary <string, BloombergDataInstrument>(); List <BloombergDataInstrument> tickers = new List <BloombergDataInstrument>(); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { string ticker; string field; int i = 0; BloombergDataInstrument ins; foreach (DataRow dr in ds.Tables[0].Rows) { ticker = dr["BBTicker"].ToString(); field = dr["BBField"].ToString(); //add if we do not have already if (!ticker_map.ContainsKey(ticker)) { ins = new BloombergDataInstrument() { ID = i++, Ticker = ticker, BBFields = new Dictionary <string, BloombergDataInstrumentField>(), //DataFrom = PriceDate, //this means that we only get a single point corresponding to pricedate when making historical requests //DataTo = PriceDate }; ticker_map.Add(ticker, ins); tickers.Add(ins); } else { ins = ticker_map[ticker]; } //add the field ins.BBFields.Add(field, null); } } return(tickers); }
private 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("Ticker - {0} : Key - {1} : Value - {2} : Error - {3}", ticker, key, value, error); } }
private void AddResultsToRequestItems(List <BloombergDataInstrument> instruments) { // Now for all requests, find the data foreach (RequestItem ri in _requestItems) { if (!ri.SendToBloomberg) { continue; } ri.Errors = ""; BloombergDataInstrument source = null; source = instruments.FirstOrDefault(x => (ri.RequestType == BloombergDataInstrument.eRequestType.Reference && x.Ticker.ToUpper() == ri.BBTicker.ToUpper()) || (ri.RequestType != BloombergDataInstrument.eRequestType.Reference && x.ID == ri.ID)); if (source != null) { if (source.ResponseError != "") { ri.Errors = source.ResponseError; } else { if (source.IsSecurityValid) { // If we have dates coming back from Bloomberg, create an entry for each date returned // otherwise time stamp with Now if (source.BBFields.ContainsKey("date")) { List <object> list = (List <object>)source.BBFields["date"].Value; if (list != null) { foreach (object val in list) { DateTime timeStamp; if (DateTime.TryParse(val.ToString(), out timeStamp)) { ri.Data.Add(timeStamp, new string[source.BBFields.Count - 1]); } else { throw new Exception("Expected date not found in AddResultsToRequestItems"); } } } } else if (source.BBFields.ContainsKey("time")) { List <object> list = (List <object>)source.BBFields["time"].Value; if (list != null) { foreach (object val in list) { DateTime timeStamp; if (DateTime.TryParse(val.ToString(), out timeStamp)) { ri.Data.Add(timeStamp, new string[source.BBFields.Count - 1]); } else { throw new Exception("Expected time not found in AddResultsToRequestItems"); } } } } else { ri.Data.Add(DateTime.Now, new string[source.BBFields.Count]); } // As we need to get a list of values from a list of fields and add it to a dictionary, // it is easier to do using numbers and arrays List <string[]> array = new List <string[]>(); foreach (string[] sa in ri.Data.Values) { array.Add(sa); } // Loop through each field and find the values int fieldPos = 0; foreach (RequestItemField field in ri.riFields.Values) { BloombergDataInstrumentField fld = source.BBFields[field.Key]; if (fld.Name != "date" && fld.Name != "time") { // handled earlier and is the key in the ri.Data dictionary if (fld.Value != null) { if (fld.Value.GetType().Name == "List`1") { List <object> list = (List <object>)fld.Value; for (int timeLine = 0; timeLine < list.Count; timeLine++) { array[timeLine][fieldPos] = GetStringValue(list[timeLine]); } } else { array[0][fieldPos] = GetStringValue(fld.Value); } } else { string err = fld.Error; // Sometimes no error is returned even when the Value is null if (err == null) { err = "N.A."; } ri.Errors += string.Format("[{0}|{1}]", fld.Name, err); } fieldPos++; } } } else { // Invalid security ri.Errors = source.SecurityErrors; } } NLogger.Instance.Info("at end"); } else { // No data returned ri.Errors = "No data returned from BB"; } } }
public List <BloombergDataInstrument> ComposeBBobjects(List <RequestItem> requestItems) { List <BloombergDataInstrument> tickerList = new List <BloombergDataInstrument>(); int lastId = 0; string lastTicker = ""; BloombergDataInstrument.eRequestType lastRequestType = BloombergDataInstrument.eRequestType.NotSet; BloombergDataInstrument bdi = null; foreach (RequestItem ri in requestItems) { if (ri.SendToBloomberg) { bool newBdi = false; // For reference types, we can place the fields into the same bdi for speed if (lastRequestType == ri.RequestType && ri.RequestType == BloombergDataInstrument.eRequestType.Reference) { if (string.Compare(lastTicker, ri.BBTicker, true) != 0) { newBdi = true; } } else { if (lastId != ri.ID) { newBdi = true; } } lastRequestType = ri.RequestType; lastTicker = ri.BBTicker; lastId = ri.ID; if (newBdi) { // Next instrument class bdi = new BloombergDataInstrument(); bdi.ResponseError = ""; bdi.RequestType = ri.RequestType; bdi.ID = ri.ID; bdi.EventType = ri.EventType == null ? null : ri.EventType.ToUpper(); bdi.Ticker = ri.BBTicker; if (ri.DateFrom > DateTime.MinValue) { bdi.DateFrom = ri.DateFrom; } if (ri.DateTo > DateTime.MinValue) { bdi.DateTo = ri.DateTo; } else { // Just one day bdi.DateTo = bdi.DateFrom; } bdi.Periodicity = ri.Periodicity; } foreach (RequestItemField field in ri.riFields.Values) { AddBBfield(bdi, field, ri.ID); } if (newBdi) { tickerList.Add(bdi); } } } return(tickerList); }