Python Bloomberg API pdblp intraday request
Asked Answered
E

2

6

pdblp allows daily historical Bloomberg requests via:

con = pdblp.BCon(debug=False)
con = start()
df = con.bdh(['SPY Equity'], 'PX_LAST', '20150103', '20150619')

How can intraday price/volume/open interest etc requests be made?

Desired behavior resembling as below, the price on 15 minute intervals.

df = con.bdh(['SPY Equity'], 'PX_Last', ... , periodSelection = 'MINUTE', period=15)
Earful answered 24/7, 2017 at 14:44 Comment(0)
M
2

Start time and end time must be in UTC timezone. So a bit of conversions should be made - and need to account for daylight savings as well.

Using xbbg instead is much easier:

In [1]: from xbbg import blp

In [2]: blp.bdib(ticker='SPY US Equity', dt='2018-11-20').tail()
Out[2]:
ticker                    SPY US Equity
field                              open   high    low  close   volume num_trds
2018-11-20 15:57:00-05:00        264.42 264.49 264.35 264.41   590775     2590
2018-11-20 15:58:00-05:00        264.42 264.42 264.26 264.27  1005241     3688
2018-11-20 15:59:00-05:00        264.26 264.48 264.12 264.15  4227150     7886
2018-11-20 16:09:00-05:00        264.12 264.12 264.12 264.12        0        1
2018-11-20 16:15:00-05:00        264.12 264.12 264.12 264.12        0        1

Need the full equity ticker here to find the timezone of exchange.

Malachite answered 27/11, 2018 at 17:18 Comment(5)
Nice! It seems that it requires less parsing of the responseSleety
I tried to install xbbg but I got this error: "Cannot uninstall 'PyYAML'. It is a disutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall." Could you give me any suggestion?Sleety
@LayGonzález it probably tries to update your pyyaml package but you have other jupyter / ipython process locking the package. close all python processes and try again?Malachite
@LayGonzález I encountered same issue in a new PC. removed PyYAML from dependencies nowMalachite
I'll give it another try on Monday!Sleety
P
1

Have you looked at the intraday request python example? You need to specify the timing in your request.

def sendIntradayTickRequest(session, options):
refDataService = session.getService("//blp/refdata")
request = refDataService.createRequest("IntradayTickRequest")

# only one security/eventType per request
request.set("security", options.security)

# Add fields to request
eventTypes = request.getElement("eventTypes")
for event in options.events:
    eventTypes.appendValue(event)

# All times are in GMT
if not options.startDateTime or not options.endDateTime:
    tradedOn = getPreviousTradingDate()
    if tradedOn:
        startTime = datetime.datetime.combine(tradedOn,
                                              datetime.time(15, 30))
        request.set("startDateTime", startTime)
        endTime = datetime.datetime.combine(tradedOn,
                                            datetime.time(15, 35))
        request.set("endDateTime", endTime)
else:
    if options.startDateTime and options.endDateTime:
        request.set("startDateTime", options.startDateTime)
        request.set("endDateTime", options.endDateTime)

if options.conditionCodes:
    request.set("includeConditionCodes", True)

print "Sending Request:", request
session.sendRequest(request)

I'm not exactly sure what you're trying to do, if you want historical intra-day then use the above and add the parameters for intra-day timing in your request. Then parse the output. However, if you're looking to do some function based on the live feed, the way I've done it is to set a cron job on the python script that grabs the rate/security every X minutes and save it into a database. Not sure if you're looking to do a real-time function, or just pull historicals.

IntradayTickRequests are not currently supported in pdblp, but if you don't want to use the main api, within pdblp try this and it should work:

df3 = con.bdib('SPY Equity', '2015-06-19T09:30:00', '2015-06-19T15:30:00', eventType='TRADE', interval=15)
df3.head()

Let me know if I misread your question.

Peart answered 24/7, 2017 at 15:9 Comment(5)
Hey, ah this must be with the raw bbg api, probably worth trying, I've been using the pdblp library github.com/matthewgilbert/pdblp.Earful
Ah, try this: df3 = con.bdib('SPY Equity', '2015-06-19T09:30:00', '2015-06-19T15:30:00', eventType='TRADE', interval=15)Peart
As Benloper explained above, bdib can be used for IntradayBarRequests. IntradayTickRequests are not currently supported in pdblp. You can read about the differences in the Bloomberg Developer's Guide here data.bloomberglp.com/professional/sites/10/2017/03/…Frampton
No problem, it was IntradayTickRequests I was after as opposed to candle/bar data.Earful
Depending on how you process the request, you can in effect be receiving the intra-day tick, and just disregard the pieces of candle/bar you don't need by dropping them from the dataframe. What part exactly are you wanting in that pull and not getting, this should give you 15 minute price intervals. I think using pdblp you cannot get intradayticks right now.Peart

© 2022 - 2024 — McMap. All rights reserved.