market_data_get_bars
Retrieve historical market data as aggregated candlesticks for specified financial instruments within defined time periods and intervals to support analysis and decision-making.
Instructions
Получение исторических данных по инструменту (агрегированные свечи)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | symbol в формате: SYMBOL@MIC (например, YDEX@MISX) | |
| start_time | Yes | ||
| end_time | Yes | ||
| timeframe | Yes |
Implementation Reference
- src/servers/market_data.py:13-17 (handler)Handler function for the 'market_data_get_bars' tool. It uses type annotations for input validation (Symbol, AwareDatetime, TimeFrame) and returns BarsResponse. Proxies the call to FinamClient.get_bars via get_finam_client() utility.@market_data_mcp.tool(tags={"market_data"}) async def get_bars(symbol: Symbol, start_time: AwareDatetime, end_time: AwareDatetime, timeframe: TimeFrame) -> BarsResponse: """Получение исторических данных по инструменту (агрегированные свечи)""" return await get_finam_client().get_bars(symbol, start_time, end_time, timeframe)
- src/main.py:13-13 (registration)Registers the market_data_mcp FastMCP server with prefix 'market_data', making the get_bars tool available as 'market_data_get_bars'.finam_mcp.mount(market_data_mcp, prefix="market_data")
- src/tradeapi/models.py:8-15 (schema)Pydantic type definition for the 'symbol' input parameter, with regex validation and examples.Symbol: type[str] = Annotated[ str, Field( description="symbol в формате: SYMBOL@MIC (например, YDEX@MISX)", pattern=r"^[A-Z0-9]+@[A-Z]+$", # Regex валидация examples=["YDEX@MISX", "SBER@TQBR"] ) ]
- src/tradeapi/client.py:82-92 (helper)Core implementation of get_bars in FinamClient, which makes the actual API request to Finam Trade API for bars data and parses into BarsResponse.async def get_bars(self, symbol: str, start_time: datetime, end_time: datetime, timeframe: TimeFrame): market_client = self.client.instruments return BarsResponse(**await self._exec_request(market_client, BaseClient.RequestMethod.GET, f"{market_client._url}/{symbol}/bars", params={ "timeframe": timeframe.value, "interval.start_time": start_time.isoformat(), "interval.end_time": end_time.isoformat(), }, ))
- src/servers/utils.py:6-8 (helper)Utility function to retrieve the shared FinamClient instance from MCP context state.def get_finam_client() -> FinamClient: return get_context().get_state("finam_client")