inquery-stock-history
Retrieve daily stock price history for specified symbols and date ranges using Korea Investment & Securities' REST API for accurate financial analysis and reporting.
Instructions
Get daily stock price history from Korea Investment & Securities
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | Yes | ||
| start_date | Yes | ||
| symbol | Yes |
Implementation Reference
- server.py:563-603 (handler)The main handler function implementing the 'inquery-stock-history' tool logic. It fetches daily stock price history using the Korea Investment & Securities API via an HTTP GET request.async def inquery_stock_history(symbol: str, start_date: str, end_date: str): """ Get daily stock price history from Korea Investment & Securities Args: symbol: Stock symbol (e.g. "005930") start_date: Start date (YYYYMMDD) end_date: End date (YYYYMMDD) Returns: Dictionary containing daily stock price history """ async with httpx.AsyncClient() as client: token = await get_access_token(client) # Prepare request data request_data = { "FID_COND_MRKT_DIV_CODE": "J", # 시장구분 "FID_INPUT_ISCD": symbol, # 종목코드 "FID_INPUT_DATE_1": start_date, # 시작일자 "FID_INPUT_DATE_2": end_date, # 종료일자 "FID_PERIOD_DIV_CODE": "D", # 기간분류코드 "FID_ORG_ADJ_PRC": "0", # 수정주가원구분 } response = await client.get( f"{TrIdManager.get_domain('stock_history')}{STOCK_HISTORY_PATH}", headers={ "content-type": CONTENT_TYPE, "authorization": f"{AUTH_TYPE} {token}", "appkey": os.environ["KIS_APP_KEY"], "appsecret": os.environ["KIS_APP_SECRET"], "tr_id": TrIdManager.get_tr_id("stock_history") }, params=request_data ) if response.status_code != 200: raise Exception(f"Failed to get stock history: {response.text}") return response.json()
- server.py:559-562 (registration)Registration of the MCP tool 'inquery-stock-history' using the @mcp.tool decorator.@mcp.tool( name="inquery-stock-history", description="Get daily stock price history from Korea Investment & Securities", )
- server.py:563-563 (schema)Input schema defined by the function parameters with type hints: symbol (str), start_date (str), end_date (str).async def inquery_stock_history(symbol: str, start_date: str, end_date: str):