matthewgilbert / pdblp

pandas wrapper for Bloomberg Open API
MIT License
241 stars 67 forks source link

Adding a limit to brsch #14

Open TSchulz85 opened 7 years ago

TSchulz85 commented 7 years ago

Hi,

Thanks a lot for your work, I use this project a lot and really like it! I currently started using the bsrch function and it seems it uses the standard limit of 5,000 results. In excel you can get up to 20,000 results with this function: =BSRCH("FI:BONDS","LIMIT=20000") Would it be possible to add this limit as well? I am fairly new to python, so struggling a bit programming it myself.

Thanks, Tobias

matthewgilbert commented 7 years ago

Glad you find the project helpful. This might be possible but I'm unsure since I don't believe bsrch is documented in the Developers Guide. I also don't currently have access to a Bloomberg connection so I can't really test this. In theory it would be fairly straightforward if the ExcelGetGridRequest behaves similarly to the HistoricalDataRequest, you could add an ovrd parameter to the function call and then something like

overrides = request.getElement("overrides")
for ovrd_fld, ovrd_val in ovrds:
    ovrd = overrides.appendElement()
    ovrd.setElement("fieldId", ovrd_fld)
    ovrd.setElement("value", ovrd_val)

@MarekOzana thoughts on this?

MarekOzana commented 7 years ago

I am tied with other things right now, let me ask Bloomberg help and come back.

matthewgilbert commented 7 years ago

Yes it seems like returning all the results is better default behaviour than limiting the returned data. Having not actually used this functionality and not currently having access to BBG I can't implement this change but if someone wants to implement I'm happy to accept a pull request. Otherwise I can look at implementing next time I have access to BBG.

TSchulz85 commented 7 years ago

So by default, there is a limit of 5000 items, but you can increase the limit by specifying the override of "LIMIT=20000". I'm happy to test some things via BBG, but unfortunately, my programming skills are limited, thus I would need some instructions what to do.

matthewgilbert commented 7 years ago

As previously discussed, since this is undocumented this is just a guess, but something like this may work

overrides = request.getElement("overrides")
ovrd = overrides.appendElement()
ovrd.setElement("fieldId", "LIMIT")
ovrd.setElement("value", 20000)

You could add this to the bsrch function in the pdblp.py module after the request is created, i.e. after line 462. I'd play around with the value of 20000 to make sure it's actually having the desired effect. If you are doing this make sure to set the debug flag to True since this can be quite helpful.

TSchulz85 commented 7 years ago

Basically I get this error back

NotFoundException: Attempt to access unknown sub-element 'overrides' on element 'ExcelGetGridRequest' (0x0006000d)

matthewgilbert commented 7 years ago

Hmmm, it looks as if unlike other request types, e.g. HistoricalDataRequest and ReferenceDataRequest, overrides are not supported. To the best of my understanding since this is undocumented functionality I'm unsure how to move forward on this.

matthewgilbert commented 6 years ago

Checking back on this, I don't seem to be able to reproduce this issue. Possibly Bloomberg has changed the behavior of the upsteam ExcelGetGridRequest service. @TSchulz85 are you still encountering this problem? e.g. I don't seem to have an issue with requests limited to 5000 results.

con = pdblp.BCon()   
df = con.bsrch("FI:BONDS")
df.shape
(136392, 1)
TSchulz85 commented 6 years ago

Hmm, I actually still have the same problem. Any idea what I could modify to make it work?

matthewgilbert commented 6 years ago

Hmmm, so to be clear when you run the code I posted above you are seeing 5000? e.g.

con = pdblp.BCon()   
df = con.bsrch("FI:BONDS")
df.shape
(5000, 1)
TSchulz85 commented 6 years ago

Almost exactly:

con = pdblp.BCon()   
con.start()
df = con.bsrch("FI:BONDS")
df.shape
Out[16]: (5000, 1)
matthewgilbert commented 6 years ago

I'm not exactly sure what is happening. My guess would be that there is some setting associated with a user profile in a BBG terminal that defines the behaviour. In excel I understand that you can use the LIMIT keyword but since this relies on the ExcelGetGridRequest which has no documentation it is a bit unclear how to do this in the Bloomberg Open API. A possible solution would be to ask the BBG help if there is a user profile setting you could change. Alternatively you could ask what the corresponding override for their Bloomberg Open API is for the excel call =BSRCH("FI:BONDS","LIMIT=20000")

prd1 commented 5 years ago

Has anyone ever figured out how to use ExcelGetGridRequest? BBG support no help.

gioxc88 commented 2 years ago

same problem