robinhood_get_historicals
Retrieve historical price data for a stock by specifying symbol, interval, and span. Supports intervals from 5 minutes to weekly and spans up to 5 years.
Instructions
Get historical price data for a stock.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock ticker symbol | |
| interval | No | Time interval (5minute, 10minute, hour, day, week) | day |
| span | No | Time span (day, week, month, 3month, year, 5year) | month |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/robinhood_mcp/tools.py:277-303 (handler)Actual implementation of get_historicals – Normalizes the symbol, validates interval/span, and calls robin_stocks' get_stock_historicals via _safe_call.
def get_historicals( symbol: str, interval: Literal["5minute", "10minute", "hour", "day", "week"] = "day", span: Literal["day", "week", "month", "3month", "year", "5year"] = "month", ) -> list[dict[str, Any]]: """Get historical price data for a stock. Args: symbol: Stock ticker symbol. interval: Time interval (5minute, 10minute, hour, day, week). span: Time span (day, week, month, 3month, year, 5year). Returns: List of historical data points with open, close, high, low, volume. """ symbol = _normalize_symbol(symbol) valid_intervals = {"5minute", "10minute", "hour", "day", "week"} valid_spans = {"day", "week", "month", "3month", "year", "5year"} if interval not in valid_intervals: raise RobinhoodError(f"Invalid interval. Must be one of: {valid_intervals}") if span not in valid_spans: raise RobinhoodError(f"Invalid span. Must be one of: {valid_spans}") result = _safe_call(rh.stocks.get_stock_historicals, symbol, interval=interval, span=span) return result if isinstance(result, list) else [] - src/robinhood_mcp/server.py:176-192 (registration)MCP tool registration of robinhood_get_historicals using the @mcp.tool() decorator, which delegates to get_historicals in tools.py.
@mcp.tool() def robinhood_get_historicals( symbol: str, interval: Literal["5minute", "10minute", "hour", "day", "week"] = "day", span: Literal["day", "week", "month", "3month", "year", "5year"] = "month", ) -> list: """Get historical price data for a stock. Args: symbol: Stock ticker symbol interval: Time interval (5minute, 10minute, hour, day, week) span: Time span (day, week, month, 3month, year, 5year) Returns list of OHLCV data points (open, high, low, close, volume). """ _ensure_logged_in() return get_historicals(symbol, interval, span) - src/robinhood_mcp/server.py:177-181 (schema)Input parameter schema for the tool – accepts symbol: str, interval (Literal), span (Literal) with defaults.
def robinhood_get_historicals( symbol: str, interval: Literal["5minute", "10minute", "hour", "day", "week"] = "day", span: Literal["day", "week", "month", "3month", "year", "5year"] = "month", ) -> list: - src/robinhood_mcp/tools.py:49-56 (helper)Helper _normalize_symbol used by get_historicals to uppercase and strip the ticker symbol.
def _normalize_symbol(symbol: str) -> str: """Normalize and validate ticker symbols.""" if not symbol or not isinstance(symbol, str): raise RobinhoodError("Symbol must be a non-empty string") symbol = symbol.upper().strip() if not symbol: raise RobinhoodError("Symbol must be a non-empty string") return symbol - src/robinhood_mcp/tools.py:24-46 (helper)Helper _safe_call used by get_historicals to wrap the robin_stocks API call with error handling.
def _safe_call(func: Callable[..., Any], *args, **kwargs) -> Any: """Safely call a robin_stocks function with error handling. Args: func: The robin_stocks function to call. *args: Positional arguments. **kwargs: Keyword arguments. Returns: The function result. Raises: RobinhoodError: If the call fails. """ try: result = func(*args, **kwargs) if result is None: raise RobinhoodError("API returned None - you may need to login first") return result except RobinhoodError: raise except Exception as e: raise RobinhoodError(f"API call failed: {e}") from e