# Customizing Data Vendor Configuration in TradingAgents: yfinance vs Alpha Vantage

> Learn how to customize data vendor configuration in TradingAgents using yfinance or Alpha Vantage without code changes. Explore the flexible three-layer system.

- Repository: [Tauric Research/TradingAgents](https://github.com/TauricResearch/TradingAgents)
- Tags: how-to-guide
- Published: 2026-03-23

---

**TradingAgents uses a three-layer configuration system defined in [`default_config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/default_config.py) and runtime helpers in [`config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/config.py) to route data requests to either yfinance or Alpha Vantage without modifying application code.**

TradingAgents separates data requirements from data sources through a flexible vendor configuration system. Whether you need free real-time data from yfinance or premium fundamental data from Alpha Vantage, you can customize the data vendor configuration in TradingAgents without touching the core trading logic. This guide covers the three-layer configuration system implemented in `TauricResearch/TradingAgents`.

## Understanding the Three-Layer Configuration System

The framework routes every data request through a cascading decision tree controlled by three distinct configuration layers.

### Category-Level Defaults (data_vendors)

The `data_vendors` dictionary in [`tradingagents/default_config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/default_config.py) assigns a default vendor to entire categories of data operations. The default mapping covers:

- `core_stock_apis` – OHLCV price data
- `technical_indicators` – indicator calculations
- `fundamental_data` – balance sheets, cashflow statements
- `news_data` – news and insider transactions

By default, all categories point to `"yfinance"`.

### Tool-Level Overrides (tool_vendors)

The `tool_vendors` dictionary allows granular overrides for individual method names. For example, you can route `get_stock_data` to Alpha Vantage while keeping all other price tools on yfinance.

### Runtime Configuration Changes

For single-run modifications without editing source files, [`tradingagents/dataflows/config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/config.py) provides:

- `initialize_config()` – loads a fresh copy of `DEFAULT_CONFIG`
- `set_config(custom_dict)` – merges user overrides into the running config
- `get_config()` – returns the current configuration state

## How Data Vendor Routing Works

The routing logic lives in [`tradingagents/dataflows/interface.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/interface.py). When a public method like `get_stock_data` is invoked, the system executes the following sequence:

1. **Categorize the method** via `get_category_for_method` (e.g., `get_stock_data` → `core_stock_apis`).
2. **Select the vendor** via `get_vendor`, which first checks `tool_vendors` for an explicit override, then falls back to the category entry in `data_vendors`.
3. **Build a fallback chain** – the configuration value may contain comma-separated vendors (e.g., `"yfinance,alpha_vantage"`).
4. **Execute with failover** – `route_to_vendor` iterates through the chain, calling the vendor-specific implementation (e.g., `get_YFin_data_online` in [`y_finance.py`](https://github.com/TauricResearch/TradingAgents/blob/main/y_finance.py) or `get_AV_stock_data` in [`alpha_vantage_stock.py`](https://github.com/TauricResearch/TradingAgents/blob/main/alpha_vantage_stock.py)). If an `AlphaVantageRateLimitError` is raised, the system automatically proceeds to the next vendor in the list.

This architecture makes the system both **configurable** and **resilient**, allowing automatic failover between yfinance and Alpha Vantage based on API quotas or rate limits.

## Configuring yfinance vs Alpha Vantage

### Switching All Stock APIs to Alpha Vantage

To route all core stock price requests to Alpha Vantage at runtime:

```python
from tradingagents.dataflows.config import set_config, get_config

set_config({
    "data_vendors": {
        "core_stock_apis": "alpha_vantage"
    }
})

print(get_config()["data_vendors"]["core_stock_apis"])

# Output: alpha_vantage

```

### Overriding a Single Tool Method

To use Alpha Vantage only for `get_stock_data` while keeping other tools on yfinance:

```python
from tradingagents.dataflows.config import set_config

set_config({
    "tool_vendors": {
        "get_stock_data": "alpha_vantage"
    }
})

```

### Setting Up Fallback Chains

Configure automatic failover by providing a comma-separated list. The system tries yfinance first, then falls back to Alpha Vantage if rate-limited:

```python
from tradingagents.dataflows.config import set_config

set_config({
    "data_vendors": {
        "technical_indicators": "yfinance,alpha_vantage"
    }
})

```

### Import-Time Configuration for Scripts

For persistent changes in analysis scripts, set the configuration immediately after import:

```python

# my_strategy.py

from tradingagents.dataflows.config import set_config

set_config({
    "data_vendors": {
        "fundamental_data": "alpha_vantage"
    }
})

from tradingagents.dataflows.interface import route_to_vendor

# This call now uses Alpha Vantage

balance_sheet = route_to_vendor("get_fundamentals", "AAPL")

```

## Key Source Files and Implementation Details

| File | Role |
|------|------|
| [`tradingagents/default_config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/default_config.py) | Defines `DEFAULT_CONFIG` with `data_vendors` and `tool_vendors` mappings. |
| [`tradingagents/dataflows/config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/config.py) | Provides `initialize_config()`, `set_config()`, and `get_config()` for runtime manipulation. |
| [`tradingagents/dataflows/interface.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/interface.py) | Contains `route_to_vendor()`, `get_vendor()`, and `get_category_for_method()` routing logic. |
| [`tradingagents/dataflows/y_finance.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/y_finance.py) | yfinance implementation for price data and fundamentals. |
| [`tradingagents/dataflows/yfinance_news.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/yfinance_news.py) | yfinance news and insider data implementation. |
| [`tradingagents/dataflows/alpha_vantage_stock.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/alpha_vantage_stock.py) | Alpha Vantage stock price API wrapper. |
| [`tradingagents/dataflows/alpha_vantage_indicator.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/alpha_vantage_indicator.py) | Alpha Vantage technical indicators. |
| [`tradingagents/dataflows/alpha_vantage_fundamentals.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/alpha_vantage_fundamentals.py) | Alpha Vantage balance sheet and cashflow data. |
| [`tradingagents/dataflows/alpha_vantage_news.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/alpha_vantage_news.py) | Alpha Vantage news and sentiment APIs. |

## Summary

- **TradingAgents** separates data logic from vendor implementation through a configuration-driven architecture in [`tradingagents/default_config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/default_config.py).
- **Three configuration layers** control routing: category-level defaults (`data_vendors`), tool-level overrides (`tool_vendors`), and runtime changes via `set_config()`.
- **Automatic failover** supports comma-separated vendor lists (e.g., `"yfinance,alpha_vantage"`), allowing the system to fall back to Alpha Vantage when yfinance is unavailable or vice versa.
- **Routing logic** in [`tradingagents/dataflows/interface.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/interface.py) maps method calls to vendor-specific implementations based on the active configuration.

## Frequently Asked Questions

### How do I change the default data vendor for all price data in TradingAgents?

Update the `core_stock_apis` entry in the `data_vendors` configuration using `set_config()` from `tradingagents.dataflows.config`. This redirects all OHLCV price requests to your chosen vendor without modifying individual tool calls.

### Can I use both yfinance and Alpha Vantage in the same TradingAgents workflow?

Yes. Configure a fallback chain by providing a comma-separated string like `"yfinance,alpha_vantage"` in the configuration. The routing logic in [`interface.py`](https://github.com/TauricResearch/TradingAgents/blob/main/interface.py) will attempt yfinance first and automatically switch to Alpha Vantage if the first vendor fails or hits a rate limit.

### What happens if Alpha Vantage hits a rate limit during a TradingAgents data call?

When `AlphaVantageRateLimitError` is raised, the `route_to_vendor` function in [`tradingagents/dataflows/interface.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/interface.py) catches the exception and proceeds to the next vendor in the fallback chain. If no vendors remain, the error propagates to the caller.

### Where is the vendor routing logic implemented in the TradingAgents source code?

The central routing mechanism resides in [`tradingagents/dataflows/interface.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/interface.py), which contains `route_to_vendor`, `get_vendor`, and `get_category_for_method`. Configuration management is handled in [`tradingagents/dataflows/config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/dataflows/config.py), while default mappings are defined in [`tradingagents/default_config.py`](https://github.com/TauricResearch/TradingAgents/blob/main/tradingagents/default_config.py).