load_all_tickers
Retrieves all stock ticker symbols and company names from KOSPI and KOSDAQ exchanges for data analysis and reference.
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:27-63 (handler)The handler function for the 'load_all_tickers' tool. It loads all KOSPI and KOSDAQ ticker symbols and names using pykrx APIs, caches them in a global TICKER_MAP dictionary, and returns the map or an error.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}