feat(01-02): register Tradier in vendor routing and create options tools
- Add Tradier to VENDOR_LIST, TOOLS_CATEGORIES (options_chain), and VENDOR_METHODS - Update route_to_vendor to catch TradierRateLimitError for fallback - Add options_chain: tradier to DEFAULT_CONFIG data_vendors - Create options_tools.py with @tool decorated get_options_chain and get_options_expirations - Add TRADIER_API_KEY and TRADIER_SANDBOX to .env.example
This commit is contained in:
parent
212c8497f2
commit
18e1e99d46
|
|
@ -4,3 +4,7 @@ GOOGLE_API_KEY=
|
||||||
ANTHROPIC_API_KEY=
|
ANTHROPIC_API_KEY=
|
||||||
XAI_API_KEY=
|
XAI_API_KEY=
|
||||||
OPENROUTER_API_KEY=
|
OPENROUTER_API_KEY=
|
||||||
|
|
||||||
|
# Options Data Providers
|
||||||
|
TRADIER_API_KEY=
|
||||||
|
TRADIER_SANDBOX=false
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
from langchain_core.tools import tool
|
||||||
|
from typing import Annotated
|
||||||
|
from tradingagents.dataflows.interface import route_to_vendor
|
||||||
|
|
||||||
|
|
||||||
|
@tool
|
||||||
|
def get_options_chain(
|
||||||
|
symbol: Annotated[str, "ticker symbol of the company"],
|
||||||
|
min_dte: Annotated[int, "minimum days to expiration"] = 0,
|
||||||
|
max_dte: Annotated[int, "maximum days to expiration"] = 50,
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Retrieve options chain data with Greeks and IV for a given ticker symbol.
|
||||||
|
Returns strikes, expirations, bid/ask, volume, OI, 1st-order Greeks
|
||||||
|
(Delta, Gamma, Theta, Vega, Rho), and implied volatility (bid_iv,
|
||||||
|
mid_iv, ask_iv, smv_vol) filtered by DTE range.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
symbol (str): Ticker symbol of the company, e.g. AAPL, TSLA
|
||||||
|
min_dte (int): Minimum days to expiration (default 0)
|
||||||
|
max_dte (int): Maximum days to expiration (default 50)
|
||||||
|
Returns:
|
||||||
|
str: A formatted dataframe containing options chain data with Greeks and IV.
|
||||||
|
"""
|
||||||
|
return route_to_vendor("get_options_chain", symbol, min_dte, max_dte)
|
||||||
|
|
||||||
|
|
||||||
|
@tool
|
||||||
|
def get_options_expirations(
|
||||||
|
symbol: Annotated[str, "ticker symbol of the company"],
|
||||||
|
min_dte: Annotated[int, "minimum days to expiration"] = 0,
|
||||||
|
max_dte: Annotated[int, "maximum days to expiration"] = 50,
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Retrieve available options expiration dates for a given ticker symbol,
|
||||||
|
filtered by DTE range.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
symbol (str): Ticker symbol of the company, e.g. AAPL, TSLA
|
||||||
|
min_dte (int): Minimum days to expiration (default 0)
|
||||||
|
max_dte (int): Maximum days to expiration (default 50)
|
||||||
|
Returns:
|
||||||
|
str: Comma-separated list of expiration dates (YYYY-MM-DD format).
|
||||||
|
"""
|
||||||
|
result = route_to_vendor("get_options_expirations", symbol, min_dte, max_dte)
|
||||||
|
if isinstance(result, list):
|
||||||
|
return ", ".join(result)
|
||||||
|
return str(result)
|
||||||
|
|
@ -23,6 +23,11 @@ from .alpha_vantage import (
|
||||||
get_global_news as get_alpha_vantage_global_news,
|
get_global_news as get_alpha_vantage_global_news,
|
||||||
)
|
)
|
||||||
from .alpha_vantage_common import AlphaVantageRateLimitError
|
from .alpha_vantage_common import AlphaVantageRateLimitError
|
||||||
|
from .tradier import (
|
||||||
|
get_options_chain as get_tradier_options_chain,
|
||||||
|
get_options_expirations as get_tradier_options_expirations,
|
||||||
|
)
|
||||||
|
from .tradier_common import TradierRateLimitError
|
||||||
|
|
||||||
# Configuration and routing logic
|
# Configuration and routing logic
|
||||||
from .config import get_config
|
from .config import get_config
|
||||||
|
|
@ -57,12 +62,20 @@ TOOLS_CATEGORIES = {
|
||||||
"get_global_news",
|
"get_global_news",
|
||||||
"get_insider_transactions",
|
"get_insider_transactions",
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"options_chain": {
|
||||||
|
"description": "Options chain data with Greeks and IV",
|
||||||
|
"tools": [
|
||||||
|
"get_options_chain",
|
||||||
|
"get_options_expirations",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VENDOR_LIST = [
|
VENDOR_LIST = [
|
||||||
"yfinance",
|
"yfinance",
|
||||||
"alpha_vantage",
|
"alpha_vantage",
|
||||||
|
"tradier",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Mapping of methods to their vendor-specific implementations
|
# Mapping of methods to their vendor-specific implementations
|
||||||
|
|
@ -107,6 +120,13 @@ VENDOR_METHODS = {
|
||||||
"alpha_vantage": get_alpha_vantage_insider_transactions,
|
"alpha_vantage": get_alpha_vantage_insider_transactions,
|
||||||
"yfinance": get_yfinance_insider_transactions,
|
"yfinance": get_yfinance_insider_transactions,
|
||||||
},
|
},
|
||||||
|
# options_chain
|
||||||
|
"get_options_chain": {
|
||||||
|
"tradier": get_tradier_options_chain,
|
||||||
|
},
|
||||||
|
"get_options_expirations": {
|
||||||
|
"tradier": get_tradier_options_expirations,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_category_for_method(method: str) -> str:
|
def get_category_for_method(method: str) -> str:
|
||||||
|
|
@ -156,7 +176,7 @@ def route_to_vendor(method: str, *args, **kwargs):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return impl_func(*args, **kwargs)
|
return impl_func(*args, **kwargs)
|
||||||
except AlphaVantageRateLimitError:
|
except (AlphaVantageRateLimitError, TradierRateLimitError):
|
||||||
continue # Only rate limits trigger fallback
|
continue # Only rate limits trigger fallback
|
||||||
|
|
||||||
raise RuntimeError(f"No available vendor for '{method}'")
|
raise RuntimeError(f"No available vendor for '{method}'")
|
||||||
|
|
@ -27,6 +27,7 @@ DEFAULT_CONFIG = {
|
||||||
"technical_indicators": "yfinance", # Options: alpha_vantage, yfinance
|
"technical_indicators": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"fundamental_data": "yfinance", # Options: alpha_vantage, yfinance
|
"fundamental_data": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
"news_data": "yfinance", # Options: alpha_vantage, yfinance
|
"news_data": "yfinance", # Options: alpha_vantage, yfinance
|
||||||
|
"options_chain": "tradier", # Options: tradier
|
||||||
},
|
},
|
||||||
# Tool-level configuration (takes precedence over category-level)
|
# Tool-level configuration (takes precedence over category-level)
|
||||||
"tool_vendors": {
|
"tool_vendors": {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue