I am trying to call the example of blpapi using xbbg
from xbbg.core import conn, process
from xbbg import blp
from datetime import date
def allInstruments(): # Return all govts with the given ticker, matured or not
req = process.create_request(service='//blp/instruments', request='instrumentListRequest')
req.set('query', "Dhaka")
req.set('maxResults', 10)
def _process_instruments(msg): # Process the response
print(msg)
pass
conn.send_request(request=req)
processed_elements_list = list(process.rec_events(func=_process_instruments))
for i in processed_elements_list:
print(i)
allInstruments()
it gives me following error but still i get the result
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
h:\tanjin-work\xbbg\Examples.ipynb Cell 45 line 2
18 for i in processed_elements_list:
19 print(i)
---> 21 allGovts()
h:\tanjin-work\xbbg\Examples.ipynb Cell 45 line 1
14 conn.send_request(request=req)
16 # Process events and get the list of elements
---> 17 processed_elements_list = list(process.rec_events(func=_process_instruments))
19 # Iterate over the processed elements
20 for i in processed_elements_list:
File h:\tanjin-work\xbbg\xbbg\core\process.py:197, in rec_events(func, **kwargs)
195 if ev.eventType() in responses:
196 for msg in ev:
--> 197 for r in func(msg=msg, **kwargs):
198 yield r
199 if ev.eventType() == blpapi.Event.RESPONSE:
TypeError: 'NoneType' object is not iterable
result snap
CID: {[ valueType=AUTOGEN classId=0 value=65 ]}
RequestId: 2838b8e0-83d5-4fb7-855f-d2122184f5c2
InstrumentListResponse = {
results[] = {
results = {
security = "MBL BD<equity>"
description = "Marico Bangladesh Ltd (Dhaka)"
}
results = {
security = "BATBC BD<equity>"
description = "British American Tobacco Bangladesh Co Ltd (Dhaka)"
}
results = {
security = "DSEX<index>"
description = "Bangladesh Dhaka Stock Exchange Broad Index"
}
results = {
security = "BRAC BD<equity>"
description = "BRAC Bank PLC (Dhaka)"
}
results = {
security = "SQUARE BD<equity>"
description = "Square Pharmaceuticals PLC (Dhaka)"
}
.....
it shows all the data where max value is not working
The OP's code is not
yield
ing anything in the_process_instruments
function, so the result cannot be iterated over.Alternative code:
with the output:
The
yellowKeyFilter
allows you to filter only the security types you want. Alternatives areYK_FILTER_INDX
,YK_FILTER_CORP
and others. If not set, you get all matches (I think).The
//blp/instruments
service is a little fickle, and the Bloomberg documentation is quite thin. Eg, thequery
is not selecting by Ticker but seems to be matching on theDescription
field. An alternative is to use instrument searches saved by name in the Terminal (in the equivalent of the ExcelBSRCH()
function).