Skip to content

Commit

Permalink
Merge pull request #1210 from tgibson11/missing-data-6
Browse files Browse the repository at this point in the history
Raise missingFile exception when unable to read IB instrument config
  • Loading branch information
robcarver17 authored Jul 3, 2023
2 parents 3433fc5 + 855eff6 commit 32572db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
36 changes: 14 additions & 22 deletions sysbrokers/IB/config/ib_instrument_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
NOT_REQUIRED_FOR_IB,
ibInstrumentConfigData,
)
from syscore.constants import missing_file
from syscore.exceptions import missingData, missingInstrument
from syscore.exceptions import missingData, missingInstrument, missingFile
from syscore.fileutils import resolve_path_and_filename_for_package
from syscore.genutils import return_another_value_if_nan
from syslogging.logger import *
Expand All @@ -26,9 +25,9 @@ class IBconfig(pd.DataFrame):
def read_ib_config_from_file(log: pst_logger = logtoscreen("")) -> IBconfig:
try:
df = pd.read_csv(IB_FUTURES_CONFIG_FILE)
except BaseException:
log.warn("Can't read file %s" % IB_FUTURES_CONFIG_FILE)
return missing_file
except Exception as e:
log.warning("Can't read file %s" % IB_FUTURES_CONFIG_FILE)
raise missingFile from e

return IBconfig(df)

Expand All @@ -40,16 +39,16 @@ def get_instrument_object_from_config(
new_log = log.setup(instrument_code=instrument_code)

if config is None:
config = read_ib_config_from_file()

if config is missing_file:
new_log.warn(
"Can't get config for instrument %s as IB configuration file missing"
% instrument_code
)
raise missingInstrument
try:
config = read_ib_config_from_file()
except missingFile as e:
new_log.warn(
"Can't get config for instrument %s as IB configuration file missing"
% instrument_code
)
raise missingInstrument from e

list_of_instruments = get_instrument_list_from_ib_config(config=config, log=log)
list_of_instruments = get_instrument_list_from_ib_config(config=config)
try:
assert instrument_code in list_of_instruments
except:
Expand Down Expand Up @@ -196,13 +195,6 @@ def _get_relevant_config_rows_from_broker_instrument_identity_fields(
return config_rows


def get_instrument_list_from_ib_config(
config: IBconfig, log: pst_logger = logtoscreen("")
):
if config is missing_file:
log.warn("Can't get list of instruments because IB config file missing")
return []

def get_instrument_list_from_ib_config(config: IBconfig):
instrument_list = list(config.Instrument)

return instrument_list
12 changes: 10 additions & 2 deletions sysbrokers/IB/ib_instruments_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sysbrokers.IB.ib_connection import connectionIB
from sysbrokers.IB.client.ib_client import ibClient
from sysbrokers.broker_instrument_data import brokerFuturesInstrumentData
from syscore.exceptions import missingFile

from sysdata.data_blob import dataBlob

Expand Down Expand Up @@ -64,8 +65,15 @@ def get_list_of_instruments(self) -> list:
:return: list of str
"""

config = self.ib_config
instrument_list = get_instrument_list_from_ib_config(config, log=self.log)
try:
config = self.ib_config
except missingFile:
self.log.warn(
"Can't get list of instruments because IB config file missing"
)
return []

instrument_list = get_instrument_list_from_ib_config(config)

return instrument_list

Expand Down

0 comments on commit 32572db

Please sign in to comment.