How to get a snapshot of a price in bloomberg?

I am looking to get a real-time snapshot from Bloomberg.Net API 3 with C #.

From the examples you can see how to get historical prices or subscribe to the data, but I can’t find the correct request for a snapshot of the order book, that is, Bid / Ask / Last trade Price and quantities.

For an intraday tick, I would do something like this:

Service refDataService = d_session.GetService("//blp/refdata"); // create intraday tick request Request request = refDataService.CreateRequest("IntradayTickRequest"); // set request parameters request.Set("includeConditionCodes", checkBoxIncludeConditionCode.Checked); request.Set("includeExchangeCodes", checkBoxIncludeExchangeCode.Checked); Element eventTypes = request.GetElement("eventTypes"); eventTypes.AppendValue("TRADE"); eventTypes.AppendValue("BID"); eventTypes.AppendValue("ASK"); request.Set("security", d_requestSecurity); request.Set("startDateTime", new BDateTime(startDate.Year, startDate.Month, startDate.Day,startDate.Hour, startDate.Minute, startDate.Second, 0)); request.Set("endDateTime", new BDateTime(endDate.Year, endDate.Month, endDate.Day, endDate.Hour, endDate.Minute, endDate.Second, 0)); 

Is there any other snapshot request?

+6
source share
4 answers

Minimally adapted from the example that comes with the API:

 using System; using System.Collections.Generic; using System.IO; using System.Linq; using Bloomberglp.Blpapi; namespace BbServerApiTool { public class GetFields : GetBloombergFields { private static readonly Name EXCEPTIONS = new Name("exceptions"); private static readonly Name FIELD_ID = new Name("fieldId"); private static readonly Name REASON = new Name("reason"); private static readonly Name CATEGORY = new Name("category"); private static readonly Name DESCRIPTION = new Name("description"); private static readonly Name ERROR_CODE = new Name("errorCode"); private static readonly Name SOURCE = new Name("source"); private static readonly Name SECURITY_ERROR = new Name("securityError"); private static readonly Name MESSAGE = new Name("message"); private static readonly Name RESPONSE_ERROR = new Name("responseError"); private static readonly Name SECURITY_DATA = new Name("securityData"); private static readonly Name FIELD_EXCEPTIONS = new Name("fieldExceptions"); private static readonly Name ERROR_INFO = new Name("errorInfo"); public override List<List<string>> GetBbFields(string[] tickers, string[] fieldsParam) { string serverHost = System.Configuration.ConfigurationManager.AppSettings["Host"]; int serverPort = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]); var sessionOptions = new SessionOptions {ServerHost = serverHost, ServerPort = serverPort}; var session = new Session(sessionOptions); session.Start(); session.OpenService("//blp/refdata"); Service refDataService = session.GetService("//blp/refdata"); Request request = refDataService.CreateRequest("ReferenceDataRequest"); Element securities = request.GetElement("securities"); Element fields = request.GetElement("fields"); request.Set("returnEids", true); foreach (var ticker in tickers) { securities.AppendValue(ticker); } foreach (var field in fieldsParam) { fields.AppendValue(field); } var cID = new CorrelationID(1); session.Cancel(cID); Results = new List<List<string>>(); session.SendRequest(request, cID); while (true) { Event eventObj = session.NextEvent(); processEvent(eventObj, session, fieldsParam); if (eventObj.Type == Event.EventType.RESPONSE) { return Results; } } } protected override string GetName() { return "BbServerApiTool"; } private void processEvent(Event eventObj, Session session, string[] fields) { switch (eventObj.Type) { case Event.EventType.RESPONSE: case Event.EventType.PARTIAL_RESPONSE: processRequestDataEvent(eventObj, session, fields); break; default: processMiscEvents(eventObj, session); break; } } private void processMiscEvents(Event eventObj, Session session) { foreach (Message msg in eventObj.GetMessages()) { switch (msg.MessageType.ToString()) { case "RequestFailure": Element reason = msg.GetElement(REASON); string message = string.Concat("Error: Source-", reason.GetElementAsString(SOURCE), ", Code-", reason.GetElementAsString(ERROR_CODE), ", category-", reason.GetElementAsString(CATEGORY), ", desc-", reason.GetElementAsString(DESCRIPTION)); throw new ArgumentException(message); case "SessionStarted": case "SessionTerminated": case "SessionStopped": case "ServiceOpened": default: break; } } } private void processRequestDataEvent(Event eventObj, Session session, string[] fields) { foreach (Message msg in eventObj.GetMessages()) { if (msg.MessageType.Equals(Name.GetName("ReferenceDataResponse"))) { Element secDataArray = msg.GetElement(SECURITY_DATA); int numberOfSecurities = secDataArray.NumValues; for (int index = 0; index < numberOfSecurities; index++) { Element secData = secDataArray.GetValueAsElement(index); Element fieldData = secData.GetElement("fieldData"); if (secData.HasElement(FIELD_EXCEPTIONS)) { // process error Element error = secData.GetElement(FIELD_EXCEPTIONS); if (error.Elements.Count() > 0) { Element errorException = error.GetValueAsElement(0); Element errorInfo = errorException.GetElement(ERROR_INFO); string message = errorInfo.GetElementAsString(MESSAGE); throw new ArgumentException(message); } } var list = new List<string> { secData.GetElement("security").GetValueAsString() }; if (secData.HasElement(SECURITY_ERROR)) { Element error = secData.GetElement(SECURITY_ERROR); string errorMessage = error.GetElementAsString(MESSAGE); // throw new ArgumentException(errorMessage); //TODO Log logger.WriteLine("Couldn't get a value for " + secData.GetElement("security").GetValueAsString()); foreach (var field in fields) { list.Add("N/A"); } } else { foreach (var field in fields) { Element item = fieldData.GetElement(field); list.Add(item.IsNull ? "N/A" : item.GetValueAsString()); } } Results.Add(list); } } } } } } 
+5
source

If you want to ensure absolutely live pricing, you are likely to use the api subscription service (// blp / mktdata), which will also return the price with the exact time of the last trade marked with it.

There is a good example in the Developer's Guide available through the Bloomberg terminal in Appendix C.2 (Subscription Paradigm).

+2
source

There seems to be no specific Bloomberg request for a β€œLive Snapshot” order book. Other methods are obviously described in the examples, but Bloomberg doesn't seem to give this in its .Net API.

There are reference data requests that seem to be closest to the type of snapshot request, but there is no delay documentation when updating these variables. The name "reference" does not inspire much confidence in what sounds like a query in real time.

Subscription is an alternative method for the type of snapshot and can be excellent in many applications. With a subscription, updates in the order book are broadcast live to your socket. The disadvantage of this approach is that it requires an internal architecture to support it, and it may take you an indefinite period of time to see any activity in some markets.

With this in mind, I think the trial and error method is best, and working with another data provider can be more fruitful.

+2
source

If you need to get prices in real time, and not static, you can still do it via ReferenceDataRequest. The difference is which field to use. PX_LAST gives you the latest price, which corresponds to the monthly limit of your data. LAST_PRICE gives you the latest real-time price, which is calculated according to the monthly real-time data limit.

PS: I received this information from our Bloomberg sales representative.

+1
source

Source: https://habr.com/ru/post/896787/


All Articles