bpsmith / tia

Toolkit for integration and analysis
BSD 3-Clause "New" or "Revised" License
404 stars 165 forks source link

Error Handling #51

Closed dom681 closed 5 years ago

dom681 commented 5 years ago

I have the following:

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

mgr = dm.BbgDataManager()

tickers = mgr['GLEN LN EQUITY', 'AAPL US EQUITY',"a"] 

df = tickers.get_historical('PX_LAST', start = '31/1/2019', end = 
           '31/1/2019', currency='EUR')

Since "a" is obviously not a valid ticker I get the following error:

raise Exception('SecurityError: %s' % ','.join(msgs))

Exception: SecurityError: (a, BAD_SEC, Null/Blank Security String [nid:191] 

What is the best way to handle potentially invalid tickers?

I have tried:

try:
    df = tickers.get_historical('PX_LAST', start = '31/1/2019', end = 
            '31/1/2019', currency='EUR')
except Exception:
     print("Could not validate ticker:")

But this stops the request entirely and does not provide any valid returns, indeed it says 'df' not defined.

The output if "a" was not in tickers would be:

                 GLEN LN EQUITY  AAPL US EQUITY
date                                      
2019-01-31         3.54638       145.36245 

Ideally I would like the invalid tickers skipped entirely and the output be the same as it would have been had it not been there originally, i.e., the same as above.

dom681 commented 5 years ago

ignore_security_error=1