Python Bloomberg API pdblp intraday request

回眸只為那壹抹淺笑 提交于 2019-12-01 09:18:41

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.

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.

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