load_all_tickers
Retrieves all ticker symbols and corresponding stock names for KOSPI and KOSDAQ, mapping them into a dictionary for efficient data access.
Instructions
Loads all ticker symbols and names for KOSPI and KOSDAQ into memory.
Returns:
Dict[str, str]: A dictionary mapping tickers to stock names.
Example: {"005930": "삼성전자", "035720": "카카오", ...}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- kospi_kosdaq_stock_server.py:26-64 (handler)The handler function for the load_all_tickers tool. Decorated with @mcp.tool() for MCP registration. Loads and caches KOSPI/KOSDAQ ticker symbols and names using pykrx APIs, returns the dictionary mapping tickers to names.@mcp.tool() def load_all_tickers() -> Dict[str, str]: """Loads all ticker symbols and names for KOSPI and KOSDAQ into memory. Returns: Dict[str, str]: A dictionary mapping tickers to stock names. Example: {"005930": "삼성전자", "035720": "카카오", ...} """ try: global TICKER_MAP # If TICKER_MAP already has data, return it if TICKER_MAP: logging.debug(f"Returning cached ticker information with {len(TICKER_MAP)} stocks") return TICKER_MAP logging.debug("No cached data found. Loading KOSPI/KOSDAQ ticker symbols") # Retrieve data based on today's date today = get_nearest_business_day_in_a_week() logging.debug(f"Reference date: {today}") # get_market_ticker_and_name() returns a Series, # where the index is the ticker and the values are the stock names kospi_series = get_market_ticker_and_name(today, market="KOSPI") kosdaq_series = get_market_ticker_and_name(today, market="KOSDAQ") # Convert Series to dictionaries and merge them TICKER_MAP.update(kospi_series.to_dict()) TICKER_MAP.update(kosdaq_series.to_dict()) logging.debug(f"Successfully stored information for {len(TICKER_MAP)} stocks") return TICKER_MAP except Exception as e: error_message = f"Failed to retrieve ticker information: {str(e)}" logging.error(error_message) return {"error": error_message}
- kospi_kosdaq_stock_server.py:27-27 (schema)Type hint defining the output schema as Dict[str, str] (ticker to name mapping). No input parameters.def load_all_tickers() -> Dict[str, str]:
- kospi_kosdaq_stock_server.py:23-24 (helper)Global dictionary used by load_all_tickers to cache ticker data persistently in memory.# Global variable to store ticker information in memory TICKER_MAP: Dict[str, str] = {}