How can I start Bloomberg API in python?

Hannah Lee picture Hannah Lee · Apr 19, 2018 · Viewed 16k times · Source

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?

Answer

Alpha picture Alpha · Nov 27, 2018

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
......