Files
TradingAgents/tradingagents/dataflows/config.py
T
Yijia-Xiao e3bc872982 chore(lint): make the repository ruff-clean under the strict select
Clear the deferred full-repo lint backlog so the whole tree passes the strict
ruff select (E,W,F,I,B,UP,C4,SIM). Mechanical fixes dominate: import sorting,
pep585/604 annotations, dropped dead imports, and whitespace. The few semantic
changes are behavior-preserving: declare __all__ on the agent_utils and
alpha_vantage re-export hubs; expand 'from x import *' to explicit names; use
immutable tuple defaults instead of mutable list defaults; contextlib.suppress
for try/except/pass; and narrow an over-broad assertRaises.
2026-06-14 16:38:36 +00:00

42 lines
1.1 KiB
Python

from copy import deepcopy
import tradingagents.default_config as default_config
# Use default config but allow it to be overridden
_config: dict | None = None
def initialize_config():
"""Initialize the configuration with default values."""
global _config
if _config is None:
_config = deepcopy(default_config.DEFAULT_CONFIG)
def set_config(config: dict):
"""Update the configuration with custom values.
Dict-valued keys (e.g. ``data_vendors``) are merged one level deep so a
partial update like ``{"data_vendors": {"core_stock_apis": "alpha_vantage"}}``
keeps the other nested keys from the default; scalar keys are replaced.
"""
global _config
initialize_config()
incoming = deepcopy(config)
for key, value in incoming.items():
if isinstance(value, dict) and isinstance(_config.get(key), dict):
_config[key].update(value)
else:
_config[key] = value
def get_config() -> dict:
"""Get the current configuration."""
if _config is None:
initialize_config()
return deepcopy(_config)
# Initialize with default config
initialize_config()