Hourly Data using Bloomberg .Net API

孤街浪徒 提交于 2019-12-12 09:04:51

问题


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",,"Quot‌​e=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);

回答1:


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.




回答2:


You may worked this out already, but you need to be careful with the time zone of your times.

Bloomberg intraday times are all be in GMT - I think it says this in the docs somewhere. This applies to both "IntradayBarRequest" and "IntradayTickRequest".

N.b. this is different from a subscription to live data (e.g. using Subscription and Session), which uses your local time zone (as set in your Bloomberg Terminal). That is, of course, unless you use the override "useGMT".



来源:https://stackoverflow.com/questions/12038336/hourly-data-using-bloomberg-net-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!