I am struggling with the logic to get hourly OPEN, HIGH, LOW and LAST_PRICE snapshot from Bloomberg using .Net API 3.0. I have googled it many times but with no luck! Any help on this will be much appreciated.
I am trying to find equivalent of following VBA BDH function in Bloomberg .Net API (C#).
BDH(B5,C6:F6,TODAY()-30,"","BarTp=T","BarSz=120","days=T","Dir=V","Dts=S",,"Quote=C","UseDPDF=Y","Sort=D",,"cols=5;rows=271")
where B5 is security name and C6:F6 contain OPEN, HIGH, LOW and LAST_PRICE fields. I have tried Intraday Bar request but it does not return same values as returned by this BDH function. Also, Historical Data request does not have HOURLY interval option, it starts from DAILY interval.
Following is the code which I have tried so far:
BBService refDataService = session.GetService("//blp/refdata");
BBRequest request = refDataService.CreateRequest("IntradayBarRequest");
request.Set("security", "SPX INDEX");
request.Set("eventType", "TRADE");
request.Set("interval", 120); // bar interval in minutes
request.Set("startDateTime", new BBDateTime(2012, 08, 11, 07, 30, 0, 0));
request.Set("endDateTime", new BBDateTime(2012, 08, 20, 18, 30, 0, 0));
session.SendRequest(request, null);
in the Bloomberg API distribution, take a look at the great "examples" folder.
The sample application below implements your request.:
\blp\API\APIv3\DotnetAPI\v3.2.9.0\examples\WinForm\C#\SimpleIntradayBarExample
Basically the "core" is like that:
Service refDataService = d_session.GetService("//blp/refdata");
// create intraday bar request
Request request = refDataService.CreateRequest("IntradayBarRequest");
// set request parameters
request.Set("eventType", "TRADE");
request.Set("security", "SPX Index");
DateTime startDate = dateTimePickerStartDate.Value;
DateTime endDate = dateTimePickerEndDate.Value;
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));
request.Set("gapFillInitialBar", True);
request.Set("interval",60);
// create correlation id
CorrelationID cID = new CorrelationID(1);
d_session.Cancel(cID);
// send request
d_session.SendRequest(request, cID);
toolStripStatusLabel1.Text = "Submitted request. Waiting for response...";
and after the Submission, you must take the Bloomberg response, parse it and use it.
Happy coding.
EDITED:
Please find the result of the sample C# code and the equivalent request made by Bloomberg. Just keep in mind the difference in TimeZONE! When you code in C#, the Bloomberg library is in UTC, while using Excel addin the timezone is your Local Zone.