mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-19 19:25:24 +03:00
chore(dataflows): use the module logger and drop dead helpers
- four modules wrote to stdout with print() while ten others use a module logger; a warning printed into the rendered CLI output is effectively invisible, which is how the trim failure above went unnoticed - convert the remaining calls to logger.warning with lazy formatting - remove save_output, SavePathType, decorate_all_methods and get_next_weekday from utils, none of which had a caller, along with the pandas and typing imports that only they needed
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from .alpha_vantage_common import AlphaVantageNotConfiguredError, _make_api_request
|
from .alpha_vantage_common import AlphaVantageNotConfiguredError, _make_api_request
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_indicator(
|
def get_indicator(
|
||||||
symbol: str,
|
symbol: str,
|
||||||
@@ -211,5 +215,5 @@ def get_indicator(
|
|||||||
# successful-looking error string.
|
# successful-looking error string.
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error getting Alpha Vantage indicator data for {indicator}: {e}")
|
logger.warning("Alpha Vantage indicator %s failed: %s", indicator, e)
|
||||||
return f"Error retrieving {indicator} data: {str(e)}"
|
return f"Error retrieving {indicator} data: {str(e)}"
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date
|
||||||
from typing import Annotated
|
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
|
|
||||||
SavePathType = Annotated[str, "File path to save data. If None, data is not saved."]
|
|
||||||
|
|
||||||
# Tickers can contain letters, digits, dot, dash, underscore, caret
|
# Tickers can contain letters, digits, dot, dash, underscore, caret
|
||||||
# (index symbols like ^GSPC), equals (futures like GC=F), and plus
|
# (index symbols like ^GSPC), equals (futures like GC=F), and plus
|
||||||
@@ -42,34 +37,5 @@ def safe_ticker_component(value: str, *, max_len: int = 32) -> str:
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def save_output(data: pd.DataFrame, tag: str, save_path: SavePathType = None) -> None:
|
|
||||||
if save_path:
|
|
||||||
data.to_csv(save_path, encoding="utf-8")
|
|
||||||
print(f"{tag} saved to {save_path}")
|
|
||||||
|
|
||||||
|
|
||||||
def get_current_date():
|
def get_current_date():
|
||||||
return date.today().strftime("%Y-%m-%d")
|
return date.today().strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
def decorate_all_methods(decorator):
|
|
||||||
def class_decorator(cls):
|
|
||||||
for attr_name, attr_value in cls.__dict__.items():
|
|
||||||
if callable(attr_value):
|
|
||||||
setattr(cls, attr_name, decorator(attr_value))
|
|
||||||
return cls
|
|
||||||
|
|
||||||
return class_decorator
|
|
||||||
|
|
||||||
|
|
||||||
def get_next_weekday(date):
|
|
||||||
|
|
||||||
if not isinstance(date, datetime):
|
|
||||||
date = datetime.strptime(date, "%Y-%m-%d")
|
|
||||||
|
|
||||||
if date.weekday() >= 5:
|
|
||||||
days_to_add = 7 - date.weekday()
|
|
||||||
next_weekday = date + timedelta(days=days_to_add)
|
|
||||||
return next_weekday
|
|
||||||
else:
|
|
||||||
return date
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
@@ -15,6 +16,8 @@ from .stockstats_utils import (
|
|||||||
)
|
)
|
||||||
from .symbol_utils import NoMarketDataError, normalize_symbol
|
from .symbol_utils import NoMarketDataError, normalize_symbol
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_YFin_data_online(
|
def get_YFin_data_online(
|
||||||
symbol: Annotated[str, "ticker symbol of the company"],
|
symbol: Annotated[str, "ticker symbol of the company"],
|
||||||
@@ -189,7 +192,7 @@ def get_stock_stats_indicators_window(
|
|||||||
except NoMarketDataError:
|
except NoMarketDataError:
|
||||||
raise # Unknown/delisted symbol — let the router emit the sentinel
|
raise # Unknown/delisted symbol — let the router emit the sentinel
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error getting bulk stockstats data: {e}")
|
logger.warning("Bulk stockstats fetch failed, falling back per-day: %s", e)
|
||||||
# Fallback to original implementation if bulk method fails
|
# Fallback to original implementation if bulk method fails
|
||||||
ind_string = ""
|
ind_string = ""
|
||||||
curr_date_dt = datetime.strptime(curr_date, "%Y-%m-%d")
|
curr_date_dt = datetime.strptime(curr_date, "%Y-%m-%d")
|
||||||
@@ -264,9 +267,7 @@ def get_stockstats_indicator(
|
|||||||
except NoMarketDataError:
|
except NoMarketDataError:
|
||||||
raise # Unknown/delisted symbol — let the router emit the sentinel
|
raise # Unknown/delisted symbol — let the router emit the sentinel
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(
|
logger.warning("Stockstats indicator %s failed on %s: %s", indicator, curr_date, e)
|
||||||
f"Error getting stockstats indicator data for indicator {indicator} on {curr_date}: {e}"
|
|
||||||
)
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
return str(indicator_value)
|
return str(indicator_value)
|
||||||
|
|||||||
Reference in New Issue
Block a user