Skip to content

Commit

Permalink
Merge pull request #1208 from bug-or-feature/python_logging_switch
Browse files Browse the repository at this point in the history
Python logging switch - replacing msg(), terse(), warn()
  • Loading branch information
robcarver17 committed Jul 4, 2023
2 parents 11351e9 + a635a92 commit 418df58
Show file tree
Hide file tree
Showing 117 changed files with 471 additions and 496 deletions.
2 changes: 1 addition & 1 deletion dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def visible_on_lan() -> bool:
visible = visible_on_lan()
if visible:
data = dataBlob()
data.log.warn(
data.log.warning(
"Starting dashboard with web page visible to all - security implications!!!!"
)
app.run(
Expand Down
4 changes: 2 additions & 2 deletions sysbrokers/IB/client/ib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def error_handler(
self.broker_message(msg=msg, log=self.log)

def broker_error(self, msg, log, myerror_type):
log.warn(msg)
log.warning(msg)

def broker_message(self, log, msg):
log.msg(msg)
log.debug(msg)

def refresh(self):
self.ib.sleep(0.00001)
Expand Down
28 changes: 14 additions & 14 deletions sysbrokers/IB/client/ib_contracts_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def broker_get_single_contract_expiry_date(
"""
specific_log = futures_contract_with_ib_data.specific_log(self.log)
if futures_contract_with_ib_data.is_spread_contract():
specific_log.warn("Can only find expiry for single leg contract!")
specific_log.warning("Can only find expiry for single leg contract!")
raise missingContract

try:
Expand All @@ -84,7 +84,7 @@ def broker_get_single_contract_expiry_date(
always_return_single_leg=True,
)
except missingContract:
specific_log.warn("Contract is missing can't get expiry")
specific_log.warning("Contract is missing can't get expiry")
raise missingContract

expiry_date = ibcontract.lastTradeDateOrContractMonth
Expand All @@ -110,7 +110,7 @@ def _ib_get_uncached_trading_hours(
contract_object_with_ib_data
)
except Exception as e:
specific_log.warn(
specific_log.warning(
"%s when getting trading hours from %s!"
% (str(e), str(contract_object_with_ib_data))
)
Expand Down Expand Up @@ -146,7 +146,7 @@ def ib_get_trading_hours_from_IB(
ib_contract_details
)
except Exception as e:
specific_log.warn(
specific_log.warning(
"%s when getting trading hours from %s!"
% (str(e), str(contract_object_with_ib_data))
)
Expand Down Expand Up @@ -220,7 +220,7 @@ def ib_get_saved_weekly_trading_hours_for_timezone_of_contract(
time_zone_id = self.ib_get_timezoneid(contract_object_with_ib_data)
except missingData:
# problem getting timezoneid
specific_log.warn(
specific_log.warning(
"No time zone ID, can't get trading hours for timezone for %s"
% str(contract_object_with_ib_data)
)
Expand Down Expand Up @@ -248,7 +248,7 @@ def ib_get_timezoneid(self, contract_object_with_ib_data: futuresContract) -> st
)
time_zone_id = ib_contract_details.timeZoneId
except Exception as e:
specific_log.warn(
specific_log.warning(
"%s when getting time zone from %s!"
% (str(e), str(contract_object_with_ib_data))
)
Expand Down Expand Up @@ -279,15 +279,15 @@ def ib_get_min_tick_size(
contract_object_with_ib_data, always_return_single_leg=True
)
except missingContract:
specific_log.warn("Can't get tick size as contract missing")
specific_log.warning("Can't get tick size as contract missing")
raise

ib_contract_details = self.ib.reqContractDetails(ib_contract)[0]

try:
min_tick = ib_contract_details.minTick
except Exception as e:
specific_log.warn(
specific_log.warning(
"%s when getting min tick size from %s!"
% (str(e), str(ib_contract_details))
)
Expand All @@ -304,15 +304,15 @@ def ib_get_price_magnifier(
contract_object_with_ib_data, always_return_single_leg=True
)
except missingContract:
specific_log.warn("Can't get price magnifier as contract missing")
specific_log.warning("Can't get price magnifier as contract missing")
raise

ib_contract_details = self.ib.reqContractDetails(ib_contract)[0]

try:
price_magnifier = ib_contract_details.priceMagnifier
except Exception as e:
specific_log.warn(
specific_log.warning(
"%s when getting price magnifier from %s!"
% (str(e), str(ib_contract_details))
)
Expand All @@ -327,7 +327,7 @@ def ib_get_contract_details(self, contract_object_with_ib_data: futuresContract)
contract_object_with_ib_data, always_return_single_leg=True
)
except missingContract:
specific_log.warn("Can't get trading hours as contract is missing")
specific_log.warning("Can't get trading hours as contract is missing")
raise

# returns a list but should only have one element
Expand Down Expand Up @@ -523,7 +523,7 @@ def _get_vanilla_ib_futures_contract(
futures_instrument_with_ib_data=futures_instrument_with_ib_data,
)
except Exception as exception:
self.log.warn(
self.log.warning(
"%s could not resolve contracts: %s"
% (str(futures_instrument_with_ib_data), exception.args[0])
)
Expand All @@ -547,14 +547,14 @@ def ib_resolve_unique_contract(self, ibcontract_pattern, log: pst_logger = None)
contract_chain = self.ib_get_contract_chain(ibcontract_pattern)

if len(contract_chain) > 1:
log.warn(
log.warning(
"Got multiple contracts for %s when only expected a single contract: Check contract date"
% str(ibcontract_pattern)
)
raise missingContract

if len(contract_chain) == 0:
log.warn("Failed to resolve contract %s" % str(ibcontract_pattern))
log.warning("Failed to resolve contract %s" % str(ibcontract_pattern))
raise missingContract

resolved_contract = contract_chain[0]
Expand Down
2 changes: 1 addition & 1 deletion sysbrokers/IB/client/ib_fx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def broker_get_daily_fx_data(
try:
ibcontract = self.ib_spotfx_contract(ccy1, ccy2=ccy2)
except missingContract:
log.warn("Can't find IB contract for %s%s" % (ccy1, ccy2))
log.warning("Can't find IB contract for %s%s" % (ccy1, ccy2))
raise missingData

# uses parent class ibClientPrices
Expand Down
14 changes: 7 additions & 7 deletions sysbrokers/IB/client/ib_price_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def broker_get_historical_futures_data_for_contract(
contract_object_with_ib_broker_config, allow_expired=allow_expired
)
except missingContract:
specific_log.warn(
specific_log.warning(
"Can't resolve IB contract %s"
% str(contract_object_with_ib_broker_config)
)
Expand All @@ -82,7 +82,7 @@ def get_ticker_object(
trade_list_for_multiple_legs=trade_list_for_multiple_legs,
)
except missingContract:
specific_log.warn(
specific_log.warning(
"Can't find matching IB contract for %s"
% str(contract_object_with_ib_data)
)
Expand Down Expand Up @@ -111,7 +111,7 @@ def cancel_market_data_for_contract_object(
trade_list_for_multiple_legs=trade_list_for_multiple_legs,
)
except missingContract:
specific_log.warn(
specific_log.warning(
"Can't find matching IB contract for %s"
% str(contract_object_with_ib_data)
)
Expand Down Expand Up @@ -141,7 +141,7 @@ def ib_get_recent_bid_ask_tick_data(
try:
ibcontract = self.ib_futures_contract(contract_object_with_ib_data)
except missingContract:
specific_log.warn(
specific_log.warning(
"Can't find matching IB contract for %s"
% str(contract_object_with_ib_data)
)
Expand Down Expand Up @@ -177,7 +177,7 @@ def _get_generic_data_for_contract(
bar_freq
)
except Exception as exception:
log.warn(exception)
log.warning(exception)
raise missingData

price_data_raw = self._ib_get_historical_data_of_duration_and_barSize(
Expand All @@ -199,7 +199,7 @@ def _raw_ib_data_to_df(
) -> pd.DataFrame:

if price_data_raw is None:
log.warn("No price data from IB")
log.warning("No price data from IB")
raise missingData

price_data_as_df = price_data_raw[["open", "high", "low", "close", "volume"]]
Expand Down Expand Up @@ -329,7 +329,7 @@ def _avoid_pacing_violation(
printed_warning_already = False
while _pause_for_pacing(last_call_datetime):
if not printed_warning_already:
log.msg(
log.debug(
"Pausing %f seconds to avoid pacing violation"
% (
last_call_datetime
Expand Down
2 changes: 1 addition & 1 deletion sysbrokers/IB/config/ib_fx_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_ib_config_from_file(log) -> pd.DataFrame:
try:
config_data = pd.read_csv(IB_CCY_CONFIG_FILE)
except Exception as e:
log.warn("Can't read file %s" % IB_CCY_CONFIG_FILE)
log.warning("Can't read file %s" % IB_CCY_CONFIG_FILE)
raise missingFile from e

return config_data
Expand Down
6 changes: 4 additions & 2 deletions sysbrokers/IB/config/ib_instrument_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_instrument_object_from_config(
try:
config = read_ib_config_from_file()
except missingFile as e:
new_log.warn(
new_log.warning(
"Can't get config for instrument %s as IB configuration file missing"
% instrument_code
)
Expand All @@ -52,7 +52,9 @@ def get_instrument_object_from_config(
try:
assert instrument_code in list_of_instruments
except:
new_log.warn("Instrument %s is not in IB configuration file" % instrument_code)
new_log.warning(
"Instrument %s is not in IB configuration file" % instrument_code
)
raise missingInstrument

futures_instrument_with_ib_data = _get_instrument_object_from_valid_config(
Expand Down
6 changes: 3 additions & 3 deletions sysbrokers/IB/ib_Fx_prices_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _get_fx_prices_without_checking(self, currency_code: str) -> fxPrices:
ib_config_for_code = self._get_config_info_for_code(currency_code)
except missingInstrument:
log = self.log.setup(**{CURRENCY_CODE_LOG_LABEL: currency_code})
log.warn("Can't get prices as missing IB config for %s" % currency_code)
log.warning("Can't get prices as missing IB config for %s" % currency_code)
return fxPrices.create_empty()

data = self._get_fx_prices_with_ib_config(currency_code, ib_config_for_code)
Expand All @@ -68,7 +68,7 @@ def _get_fx_prices_with_ib_config(
log = self.log.setup(**{CURRENCY_CODE_LOG_LABEL: currency_code})

if len(raw_fx_prices_as_series) == 0:
log.warn(
log.warning(
"No available IB prices for %s %s"
% (currency_code, str(ib_config_for_code))
)
Expand All @@ -82,7 +82,7 @@ def _get_fx_prices_with_ib_config(
# turn into a fxPrices
fx_prices = fxPrices(raw_fx_prices)

log.msg("Downloaded %d prices" % len(fx_prices))
log.debug("Downloaded %d prices" % len(fx_prices))

return fx_prices

Expand Down
4 changes: 2 additions & 2 deletions sysbrokers/IB/ib_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ def account(self):
return self._account

def close_connection(self):
self.log.msg("Terminating %s" % str(self._ib_connection_config))
self.log.debug("Terminating %s" % str(self._ib_connection_config))
try:
# Try and disconnect IB client
self.ib.disconnect()
except BaseException:
self.log.warn(
self.log.warning(
"Trying to disconnect IB client failed... ensure process is killed"
)

Expand Down
12 changes: 6 additions & 6 deletions sysbrokers/IB/ib_futures_contract_price_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _get_prices_at_frequency_for_contract_object_no_checking_with_expiry_flag(
)
)
except missingContract:
new_log.warn("Can't get data for %s" % str(futures_contract_object))
new_log.warning("Can't get data for %s" % str(futures_contract_object))
raise missingData

price_data = self._get_prices_at_frequency_for_ibcontract_object_no_checking(
Expand All @@ -256,14 +256,14 @@ def _get_prices_at_frequency_for_ibcontract_object_no_checking(
allow_expired=allow_expired,
)
except missingData:
new_log.warn(
new_log.warning(
"Something went wrong getting IB price data for %s"
% str(contract_object_with_ib_broker_config)
)
raise

if len(price_data) == 0:
new_log.warn(
new_log.warning(
"No IB price data found for %s"
% str(contract_object_with_ib_broker_config)
)
Expand All @@ -284,7 +284,7 @@ def get_ticker_object_for_order(self, order: contractOrder) -> tickerObject:
)
)
except missingContract:
new_log.warn("Can't get data for %s" % str(contract_object))
new_log.warning("Can't get data for %s" % str(contract_object))
return futuresContractPrices.create_empty()

ticker_with_bs = self.ib_client.get_ticker_object(
Expand All @@ -309,7 +309,7 @@ def cancel_market_data_for_order(self, order: ibBrokerOrder):
)
)
except missingContract:
new_log.warn("Can't get data for %s" % str(contract_object))
new_log.warning("Can't get data for %s" % str(contract_object))
return futuresContractPrices.create_empty()

self.ib_client.cancel_market_data_for_contract_object(
Expand All @@ -335,7 +335,7 @@ def get_recent_bid_ask_tick_data_for_contract_object(
)
)
except missingContract:
new_log.warn("Can't get data for %s" % str(contract_object))
new_log.warning("Can't get data for %s" % str(contract_object))
return dataFrameOfRecentTicks.create_empty()

try:
Expand Down
Loading

0 comments on commit 418df58

Please sign in to comment.