Reputation:
Using the Bloomberg open API. How can I get the PX_LAST value at a specific date and time?
I am able to get the last trade of a specific day (effectively, the close price) using:
Request request = refDataService.createRequest(historicalData);
request.getElement("securities").appendValue("IBM US Equity");
request.getElement("fields").appendValue("PX_LAST");
String date = "20120801";
request.set("startDate", date);
request.set("endDate", date);
Now I need to know the PX_LAST at a specific date and time. For instance, what was the prevailing trade price at 9:45 on Aug 1?
Upvotes: 3
Views: 4320
Reputation: 328815
One way is to create an IntradayBarRequest
request with the following parameters:
request.set("security", ticker);
request.set("eventType", EventType.TRADE);
request.set("interval", 1);
request.set("gapFillInitialBar", true);
request.set("startDateTime", startDate);
request.set("endDateTime", startDate);
with startDate = "2012-08-01T09:45:00"
Note that in my timezone I don't get anything for 9:45 but I do get something for 15:45 (cf your previous question).
If you use Joda's DateTime, you can use the following pattern:
private static final DateTimeFormatter bbDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
DateTime start = new DateTime(2012, 8, 1, 15, 45, 0, 0);
String bbStartDate = startDate.toString(bbDateFormat);
request.set("startDateTime", bbStartDate);
Upvotes: 1