mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-06-30 03:34:19 +03:00
fix(data): normalize ticker on the news path
The yfinance news fetch queried the raw ticker while every other path uses the canonical symbol, so broker/forex/crypto aliases silently returned no news. Normalize it (XAUUSD -> GC=F) and keep the user's ticker in the report header.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
"""Symbol normalization must apply on every yfinance path, not just price fetch.
|
||||
|
||||
Regression tests for #983 (instrument identity) and #984 (reflection returns):
|
||||
a broker symbol like XAUUSD must resolve to the same Yahoo symbol (GC=F) that
|
||||
the price path uses, so identity and realized-return lookups hit the right
|
||||
instrument instead of failing/mismatching.
|
||||
Regression tests for #983 (instrument identity), #984 (reflection returns), and
|
||||
the news path: a broker symbol like XAUUSD must resolve to the same Yahoo symbol
|
||||
(GC=F) that the price path uses, so identity, realized-return, and news lookups
|
||||
hit the right instrument instead of failing/mismatching.
|
||||
"""
|
||||
import pandas as pd
|
||||
|
||||
import tradingagents.agents.utils.agent_utils as au
|
||||
import tradingagents.dataflows.yfinance_news as ynews
|
||||
import tradingagents.graph.trading_graph as tg
|
||||
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||
|
||||
@@ -52,3 +53,23 @@ def test_fetch_returns_normalizes_symbol(monkeypatch):
|
||||
assert queried[0] == "GC=F" # stock symbol normalized (#984)
|
||||
assert queried[1] == "SPY" # benchmark left as the canonical symbol
|
||||
assert raw is not None and days is not None
|
||||
|
||||
|
||||
def test_news_lookup_normalizes_symbol(monkeypatch):
|
||||
seen = {}
|
||||
|
||||
class FakeTicker:
|
||||
def __init__(self, symbol):
|
||||
seen["symbol"] = symbol
|
||||
|
||||
def get_news(self, count):
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(ynews.yf, "Ticker", FakeTicker)
|
||||
monkeypatch.setattr(ynews, "yf_retry", lambda fn: fn())
|
||||
|
||||
out = ynews.get_news_yfinance("XAUUSD", "2025-01-01", "2025-01-10")
|
||||
|
||||
assert seen["symbol"] == "GC=F" # news queried with the canonical symbol
|
||||
assert "XAUUSD" in out # the user's ticker stays in the report
|
||||
assert "GC=F" in out # provenance noted
|
||||
|
||||
Reference in New Issue
Block a user