I'm new to bloomberg terminals but I'm trying to pull data from bloomberg using the python API. The underlying c++ SDK seems to be working as I have pip installed the following python libraries:
blpapi
pdblp
I can connect to the terminal and run the example data that comes with the packages:
con = pdblp.BCon(debug=False, port=8194, timeout=5000)
con.start()
# print some data
con.bdh('SPY US Equity', ['PX_LAST', 'VOLUME'],'20150629', '20150630')
This returns the following:
ticker SPY US Equity
field PX_LAST VOLUME
date
2015-06-29 205.42 202621332.0
2015-06-30 205.85 182925106.0
So everything seems to be working. The problem is if I want to try searching certain tickers it just returns an empty datafame:
con.bsrch('COH9') #returns []
con.bsrch("COMDTY:COH9")
con.bsrch('COH9 Comdty')
con.bsrch("COMDTY")
con.bsrch('CL1 Comdty')
con.bsrch('CO1 Comdty')
All of these return []. the 'bsrch' method should work because the following example provided in the readme works and fetches data:
con.bsrch("COMDTY:NGFLOW")
The issue is that each of these strings returns something in the bloomberg terminal yet returns nothing with this api. why? The docs say this is a search function?
I've tried other commands such as:
con.bdib('CL1 Comdty', start_datetime='20190127', end_datetime='20190128', event_type='BID', interval=1)
which also throws an error:
Traceback (most recent call last):
File "bloomberg_api_test.py", line 56, in <module>
bloomberg_api_test()
File "bloomberg_api_test.py", line 38, in bloomberg_api_test
print(con.bdib('CL1 Comdty', start_datetime='20190127', end_datetime='20190128', event_type='BID', interval=1))
File "C:\Users\svc_tradingops\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pdblp\pdblp.py", line 681, in bdib
data = pd.DataFrame(data).set_index('time').sort_index().loc[:, flds]
File "C:\Users\svc_tradingops\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py", line 4156, in set_index
raise KeyError('{}'.format(missing))
KeyError: "['time']"
There doesn't seem to be much clear guidance in the docs about how to use these methods unless there is something I missed?