alpha-xone / xbbg

An intuitive Bloomberg API
https://xbbg.readthedocs.io/
Apache License 2.0
244 stars 51 forks source link

blp.live is blocking instead of async #101

Open sye98 opened 1 year ago

sye98 commented 1 year ago

Hi,

I'm pretty beginner in asyncio so I could be wrong. Just want to point out that, in async def blp.live,

with subscribe(tickers=tickers, flds=s_flds, options=options, **kwargs):
        cnt = 0
        while True and cnt <= max_cnt:
            try:
                ev = sess.tryNextEvent()
                if ev is None: continue

This is blocking. Performance wise, it's same as sync version.

From blpapi.Session docstring:

A Session is asynchronous if an eventHandler argument is supplied when it is constructed. The nextEvent() method may not be called. All incoming events are delivered to the eventHandler supplied on construction.

If supplied, eventHandler must be a callable object that takes two arguments: received :class:Event and related session.

A Session is synchronous if an eventHandler argument is not supplied when it is constructed. The :meth:nextEvent() method must be called to read incoming events.

And it looks like in xbbg.core.conn.connect_bbg: session = blpapi.Session(sess_opts) no eventHandler is provided.

It would be great it we can have it truly async. Thank you!