-->

How can I start Bloomberg API in python?

2019-06-09 19:26发布

问题:

I managed to install blpapi in my python. However, there is error Exception: failed to start session My simple code is as follows.

import blpapi
import pandas as pd
import tia.bbg.datamgr as dm

mgr = dm.BbgDataManager()
sids = mgr['MSFT US EQUITY', 'IBM US EQUITY', 'CSCO US EQUITY']
df = sids.get_historical('PX_LAST', '1/1/2014', '11/12/2014')

What Can I do with this? Can you help?

回答1:

Please clarify which IP and port you're attempting to connect to.

If connecting to the local process 'bbcomm.exe' then the IP is 127.0.0.1 (localhost) and port 8194. Check if bbcomm.exe process is running (e.g. in Task Manager) if not then start it manually by typing bbcomm.exe in CMD, or by launching Excel with one or more BDP() functions. Make sure the Bloomberg Terminal is running.

If you are connecting to a remote host (e.g. B-Pipe or ServerApi) then check if the port is reachable: telnet



回答2:

Don’t need to worry about connections if you use xbbg:

from xbbg import blp

blp.bdh(
    ['MSFT US Equity', 'IBM US Equity', 'CSCO US Equity'],
    'Px_Last', '1/1/2014', '11/12/2014'
)

Output:

ticker     MSFT US Equity IBM US Equity CSCO US Equity
field             Px_Last       Px_Last        Px_Last
date                                                  
2014-01-02          32.95        155.62          18.88
2014-01-03          32.73        156.55          18.86
2014-01-06          32.04        156.01          18.89
2014-01-07          32.29        159.12          19.14
2014-01-08          31.71        157.66          19.13
......


回答3:

It sounds like all you did was import the library and attempt to use it.

Most apis require you to set up some sort of account with them to access their data so that they can see who's using their api improperly and who's exceeding their rate limits.

Download the BLPAPI Core Developer Guide from their website and follow those instructions carefully.

https://www.bloomberg.com/professional/support/api-library/