Skip to content

Commit

Permalink
Custom logging level fix so we do not spam backtest, update TS
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Oct 25, 2024
1 parent 2ddbd0e commit 1717d84
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trading-strategy = {path = "deps/trading-strategy", develop = true}
requests = "^2.27.1"
matplotlib = "^3.6.0"
jupyterlab = "^4.0.7"
pandas = "^2.2.3"
pandas = "<3"
pandas-ta = "^0.3.14b" # Unmaintained, still stick to old Pandas
tqdm-loggable = "^0.2"
numpy = "<2" # https://stackoverflow.com/a/78638258/315168
Expand Down
6 changes: 5 additions & 1 deletion tradeexecutor/cli/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ def start(
# Don't touch any log levels, but
# make sure we have logger.trading() available when
# log_level is "disabled"
logger = setup_logging(log_level, in_memory_buffer=True)
logger = setup_logging(
log_level,
in_memory_buffer=True,
enable_trade_high=True,
)

if discord_webhook_url and asset_management_mode.is_live_trading():
# TODO: Move backtesting to its own console command
Expand Down
22 changes: 17 additions & 5 deletions tradeexecutor/cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@


def setup_logging(
log_level: None | str | int=logging.INFO,
in_memory_buffer=False) -> Logger:
log_level: None | str | int=logging.INFO,
in_memory_buffer=False,
enable_trade_high=False,
) -> Logger:
"""Setup root logger and quiet some levels.
:param log_level:
Expand All @@ -37,7 +39,7 @@ def setup_logging(
:param in_memory_buffer:
Setup in-memory log buffer used to fetch log messages to the frontend.
"""
setup_custom_log_levels()
setup_custom_log_levels(enable_trade_high=enable_trade_high)

if log_level == "disabled":
# Special unit test marker, don't mess with loggers
Expand Down Expand Up @@ -273,7 +275,9 @@ def setup_strategy_logging(default_log_level: str | int=logging.WARNING) -> logg
return logger


def setup_custom_log_levels():
def setup_custom_log_levels(
enable_trade_high=False,
):
"""Create a new logging level TRADE that is between INFO and WARNING.
This level is used to log trade execution to Discord etc.
Expand All @@ -285,6 +289,9 @@ def setup_custom_log_levels():
- `logging.TRADE_HIGH`: Log level made trade decisions - this only logs
successful trade decisions, not any errors. It is designed for the Teleegram bot.
:param enable_trade_high:
Enable special TRADE_HIGH logging level in live trade execution.
"""

if hasattr(logging, "TRADE"):
Expand All @@ -296,7 +303,12 @@ def setup_custom_log_levels():
# Log level for verbose trade output for Discord diagnostics
logging.TRADE = logging.INFO + 1 # Info is 20, TRADE is 21, Warning is 30

logging.TRADE_HIGH = logging.FATAL + 1
if enable_trade_high:
# A level that shows trade output but no errors in live exec
logging.TRADE_HIGH = logging.FATAL + 1
else:
# Otherwise the same as trade
logging.TRADE_HIGH = logging.TRADE + 1

# Log level
logging.addLevelName(logging.TRADE, "TRADE")
Expand Down

0 comments on commit 1717d84

Please sign in to comment.