get_stock_price_by_date
Retrieve the stock price for a specific symbol on a particular date using the YYYY-MM-DD format, providing accurate financial data for analysis or record-keeping.
Instructions
Get the stock price for a given stock symbol on a specific date.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | The date in YYYY-MM-DD format. | |
| symbol | Yes | Stock symbol in Yahoo Finance format. |
Implementation Reference
- src/mcp_yahoo_finance/server.py:210-218 (handler)The MCP tool handler function decorated with @mcp_instance.tool(), which registers the tool and executes the logic by delegating to the YahooFinance instance method.@mcp_instance.tool() def get_stock_price_by_date(symbol: str, date: str) -> str: """Get the stock price for a given stock symbol on a specific date. Args: symbol (str): Stock symbol in Yahoo Finance format. date (str): The date in YYYY-MM-DD format. """ return yf_instance.get_stock_price_by_date(symbol, date)
- The supporting method in the YahooFinance class that implements the core logic: fetches the stock ticker, retrieves 1-day history starting from the given date, and returns the closing price formatted to 4 decimals.def get_stock_price_by_date(self, symbol: str, date: str) -> str: """Get the stock price for a given stock symbol on a specific date. Args: symbol (str): Stock symbol in Yahoo Finance format. date (str): The date in YYYY-MM-DD format. """ stock = Ticker(ticker=symbol, session=self.session) price = stock.history(start=date, period="1d") return f"{price.iloc[0]['Close']:.4f}"
- src/mcp_yahoo_finance/server.py:210-210 (registration)The @mcp_instance.tool() decorator line that registers the get_stock_price_by_date function as an MCP tool.@mcp_instance.tool()