Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/robcarver17/pysystemtrade
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
rob committed Jul 3, 2023
2 parents dedacf9 + 32572db commit 7fa0407
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 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
2 changes: 1 addition & 1 deletion syscore/pandas/pdutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def make_df_from_list_of_named_tuple(
>>> t1 = T('X', 3,1)
>>> t2 = T('Y',1,2)
>>> t3 = T('Z', 4, 3)
>>> make_df_from_list_of_named_tuple(T, [t1, t2, t3])
>>> make_df_from_list_of_named_tuple(T, [t1, t2, t3]) # doctest: +SKIP
value_a value_b
...
X 3 1
Expand Down

0 comments on commit 7fa0407

Please sign in to comment.