matthewgilbert / pdblp

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

Timeout - Option to override? #15

Closed NoahKauffman closed 6 years ago

NoahKauffman commented 7 years ago

Hi Mathew -

Great package, I find your package super useful.

I'm getting a timeout error from calls such as:

con.ref(['X US EQUITY', 'IBM US EQUITY'],['EQY_WEIGHTED_AVG_PX'],[('VWAP_START_DT','20170808'),('VWAP_END_DT','20170808'),('VWAP_START_TIME','11:00:00'),('VWAP_END_TIME','12:00:00')])

Error reads: "RuntimeError: Timeout, increase timeout parameter"

I see you ref timeout in method _parse_ref() ... Is there a simple way for user to override this; I couldn't find one in the docs?

Best,

Noah

NoahKauffman commented 7 years ago

I guess I should mention that I know how to do this by modifying the underlying code - but didn't know if there was a smarter way to do this without touching the code.

matthewgilbert commented 7 years ago

Glad you find it helpful.

This timeout option was originally added for ref_hist as a bit of a hack to essentially allow a bunch of iterative ref calls to be made which occasionally resulted in a blpapi.Event.TIMEOUT. I had never seen this occur before for a single ref() call and therefore it's currently not exposed.

One possible hacky solution (but preferable to a hardcoded fix) would be to use ref_hist instead and use one of either VWAP_START_DT or VWAP_END_DT as the field to iterate over, something like

tickers = ['X US EQUITY', 'IBM US EQUITY']
flds = ['EQY_WEIGHTED_AVG_PX']
dates = ['20170808']
ovrds = [('VWAP_END_DT', '20170808'), ('VWAP_START_TIME', '11:00:00'),
         ('VWAP_END_TIME', '12:00:00')]
con.ref_hist(tickers, flds, dates, date_field='VWAP_START_DT', ovrds=ovrds)

The default timeout for ref_hist is longer than ref, 2000 vs 500 milliseconds, but is also exposed as a parameter if this is not long enough.

Unfortunately I don't currently have access to a Bloomberg connection so I can't confirm this works, but please let me know.

NoahKauffman commented 7 years ago

Cool, your solution does work! Thanks!

matthewgilbert commented 7 years ago

Okay great, somewhat of a round about way of doing things but glad it works. It would likely be better to add an instance variable with a default that the user can change and which is used throughout the self.session.nextEvent() calls but I am a bit hesitant to make changes without the ability to do any testing.

NoahKauffman commented 7 years ago

cool. Hit me up if you ever want to make any significant mods to the code (like for something more substantial than this). Happy to contribute and/or run tests for you. Thanks again for the reply.

MarekOzana commented 6 years ago

Hi Matthew, I have the same issue with timeout in con.ref() call. Your workaround with ref_hist works nicely, but the proper fix (e.g. exposing timeout in con.ref()) would be nice.

matthewgilbert commented 6 years ago

Yes this is something I would like to implement. The fix is fairly straightforward so just a matter of testing against a Bloomberg connection. Will hopefully get something out in fairly short order.

matthewgilbert commented 6 years ago

This is now possible using the the timeout parameter when instantiating a BCon instance, e.g.

import pdblp
con = pdblp.BCon(timeout=5000)
gflores87 commented 6 years ago

Hi Matthew,

I updated pdblp and I get an error when I run the following command:

con = pdblp.BCon(debug=False, port=8194,timeout=5000)

TypeError: init() got an unexpected keyword argument 'timeout'

What could be happening?

matthewgilbert commented 6 years ago

Can you post the full stacktrace output to your screen.

gflores87 commented 6 years ago

`Traceback (most recent call last):

  File "<ipython-input-6-3e678b5fe243>", line 1, in <module>
    runfile('C:/Users/XXXX/Documents/Projects/Cap Arb/full_pdblp.py', wdir='C:/Users/XXXX/Documents/Projects/Cap Arb')

  File "C:\Users\XXXX\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\XXXX\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/XXXX/Documents/Projects/Cap Arb/full_pdblp.py", line 788, in <module>
    x,_ = CapArb_Intraday('US')

  File "C:/Users/XXXX/Documents/Projects/Cap Arb/full_pdblp.py", line 758, in CapArb_Intraday
    bag_US = CapArb(market)

  File "C:/Users/XXXX/Documents/Projects/Cap Arb/full_pdblp.py", line 746, in CapArb
    output['dfTR'],output['dfSpread_Value'] = get_Source_data(tickers,startDate,colNames,market)

  File "C:/Users/XXXX/Documents/Projects/Cap Arb/full_pdblp.py", line 517, in get_Source_data
    con = pdblp.BCon(debug=False, port=8194,timeout = 5000)

TypeError: __init__() got an unexpected keyword argument 'timeout'`
matthewgilbert commented 6 years ago

I haven't actually pushed a release so you would need to install the dev version from GitHub for the time being, if when you updated you meant from PyPi. If you look at your source from pdblp.py does BCon() have the parameter timeout?

matthewgilbert commented 6 years ago

This release is now on pypi in 0.1.3

gflores87 commented 6 years ago

I see it now, thank you so much!