mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-11-14 21:32:38 +02:00
refactor(dataflows): decide in one place whether a run is dated in the past
- date_window.is_historical replaces the four copies of the rule in the profile guard, Polymarket, the instrument context and the memory cutoff, which read the clock on its own
This commit is contained in:
@@ -14,6 +14,7 @@ import pandas as pd
|
||||
import pytest
|
||||
|
||||
from tradingagents.agents import tools
|
||||
from tradingagents.dataflows.date_window import get_current_date
|
||||
from tradingagents.dataflows.vendors import polymarket
|
||||
from tradingagents.dataflows.vendors.alpha_vantage import news as alpha_vantage_news
|
||||
from tradingagents.dataflows.vendors.yahoo import (
|
||||
@@ -77,7 +78,7 @@ def test_polymarket_withholds_live_odds_from_a_historical_run():
|
||||
@pytest.mark.unit
|
||||
def test_polymarket_serves_a_current_run():
|
||||
with mock.patch.object(polymarket, "_request", return_value={"events": []}) as req:
|
||||
polymarket.get_prediction_markets("Fed rate cut", as_of_date=polymarket.get_current_date())
|
||||
polymarket.get_prediction_markets("Fed rate cut", as_of_date=get_current_date())
|
||||
req.assert_called_once()
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import logging
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from tradingagents.dataflows.date_window import get_current_date
|
||||
from tradingagents.dataflows.date_window import is_historical
|
||||
from tradingagents.dataflows.vendors.yahoo.fundamentals import get_company_profile
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -135,7 +135,7 @@ def build_instrument_context(
|
||||
name = identity.get("company_name") or identity.get("name")
|
||||
label = "Name" if is_crypto else "Company"
|
||||
details = []
|
||||
if trade_date and str(trade_date) < get_current_date():
|
||||
if is_historical(trade_date):
|
||||
if name:
|
||||
details.append(
|
||||
f"{label}: {name} (its current name, given only to identify it; "
|
||||
|
||||
@@ -36,6 +36,11 @@ def get_current_date() -> str:
|
||||
return date.today().strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
def is_historical(run_date) -> bool:
|
||||
"""Whether a run is dated before today, so live-only data would come from after it."""
|
||||
return bool(run_date) and str(run_date) < get_current_date()
|
||||
|
||||
|
||||
def coverage_gap(
|
||||
dates, start_date: str, end_date: str, source: str, subject: str
|
||||
) -> str | None:
|
||||
@@ -106,10 +111,7 @@ def withhold_live_profile(as_of_date: str | None, label: str) -> str | None:
|
||||
Every fundamentals vendor withholds on this rule, so switching between them
|
||||
cannot reintroduce the leak.
|
||||
"""
|
||||
if not as_of_date:
|
||||
return None
|
||||
today = get_current_date()
|
||||
if as_of_date >= today:
|
||||
if not is_historical(as_of_date):
|
||||
return None
|
||||
return (
|
||||
f"# Company Fundamentals for {label}\n"
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ from datetime import datetime, timezone
|
||||
|
||||
import requests
|
||||
|
||||
from tradingagents.dataflows.date_window import get_current_date
|
||||
from tradingagents.dataflows.date_window import is_historical
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -83,7 +83,7 @@ def get_prediction_markets(topic: str, limit: int | None = None, as_of_date: str
|
||||
each with its implied probability, traded volume, resolution date, and
|
||||
recent (1-week) move.
|
||||
"""
|
||||
if as_of_date and as_of_date < get_current_date():
|
||||
if is_historical(as_of_date):
|
||||
return (
|
||||
f"Prediction-market odds are withheld for {as_of_date}. Polymarket serves "
|
||||
f"only live odds on open markets, with no historical vintage, so serving "
|
||||
|
||||
@@ -11,7 +11,7 @@ import tradingagents
|
||||
from tradingagents.agents.context import build_instrument_context, resolve_instrument_identity
|
||||
from tradingagents.agents.rating import run_rating
|
||||
from tradingagents.dataflows.config import run_config, run_config_context, set_config
|
||||
from tradingagents.dataflows.date_window import get_current_date
|
||||
from tradingagents.dataflows.date_window import get_current_date, is_historical
|
||||
from tradingagents.dataflows.symbols import safe_ticker_component
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
from tradingagents.llm_clients import build_llm_kwargs, create_llm_client
|
||||
@@ -152,8 +152,7 @@ class TradingAgentsGraph:
|
||||
None, disabling the filter so live behavior and pre-migration entries
|
||||
(which have no stored resolution date) are unaffected.
|
||||
"""
|
||||
td = str(trade_date)
|
||||
return td if td < datetime.now().strftime("%Y-%m-%d") else None
|
||||
return str(trade_date) if is_historical(trade_date) else None
|
||||
|
||||
def _run_signature(self, asset_type: str, portfolio=None) -> str:
|
||||
"""Run inputs that must invalidate a checkpoint if changed.
|
||||
|
||||
Reference in New Issue
Block a user