calculate_midpoint
Calculate the midpoint price indicator for financial market analysis using TA-Lib technical analysis functions.
Instructions
Calculate Midpoint (MIDPOINT).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kwargs | Yes |
Implementation Reference
- src/mcp_talib/core/server.py:251-263 (handler)MCP tool handler for 'calculate_midpoint'. Delegates computation to the 'midpoint' indicator from the registry.@mcp.tool() async def calculate_midpoint(close: List[float], timeperiod: int = 14) -> Dict[str, Any]: try: indicator = registry.get_indicator("midpoint") if not indicator: raise ValueError("MIDPOINT indicator not found") market_data = MarketData(close=close) result = await indicator.calculate(market_data, {"timeperiod": timeperiod}) if result.success: return {"success": True, "values": result.values, "metadata": result.metadata} return {"success": False, "error": result.error_message} except Exception as e: return {"success": False, "error": str(e)}
- Core implementation of the midpoint calculation using TA-Lib's MIDPOINT function. Called by the tool handler.async def calculate(self, market_data: MarketData, options: Dict[str, Any] = None) -> IndicatorResult: if options is None: options = {} timeperiod = options.get("timeperiod", 14) close = np.asarray(market_data.close, dtype=float) try: out = ta.MIDPOINT(close, timeperiod=timeperiod) return IndicatorResult(indicator_name=self.name, success=True, values={"midpoint": out.tolist()}, metadata={"timeperiod": timeperiod, "input_points": len(close), "output_points": len(out)}) except Exception as e: return IndicatorResult(indicator_name=self.name, success=False, values={}, error_message=str(e))
- src/mcp_talib/indicators/__init__.py:36-36 (registration)Registers the MIDPOINTIndicator class in the indicator registry, making it available via registry.get_indicator('midpoint').registry.register("midpoint", MIDPOINTIndicator)
- Input schema definition for the midpoint indicator (note: tool uses 'close_prices' in tests, mapped to 'close').@property def input_schema(self) -> Dict[str, Any]: return {"type": "object", "properties": {"close_prices": {"type": "array", "items": {"type": "number"}}, "timeperiod": {"type": "integer", "default": 14}}, "required": ["close_prices"]}