GetTimeSeriesAdx
Retrieve Average Directional Index (ADX) time series data to measure trend strength and identify trending or ranging markets for financial instruments.
Instructions
The Average Directional Index (ADX) measures the strength of a trend, regardless of direction, helping traders determine if a market is trending or ranging.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- src/mcp_server_twelve_data/server.py:88-88 (registration)Registers all the MCP tools from Twelve Data API endpoints, including the specific tool 'GetTimeSeriesAdx' via the autogenerated tools.py.
register_all_tools(server=server, _call_endpoint=_call_endpoint) - This is the core handler logic executed for the GetTimeSeriesAdx tool (and all similar tools). It handles API key injection, path parameter resolution, HTTP request to Twelve Data API, error handling, and response validation using Pydantic model.
async def _call_endpoint( endpoint: str, params: P, response_model: Type[R], ctx: Context ) -> R: params.apikey = extract_twelve_data_apikey( twelve_data_apikey=twelve_data_apikey, transport=transport, ctx=ctx ) params_dict = params.model_dump(exclude_none=True) resolved_endpoint = resolve_path_params(endpoint, params_dict) async with httpx.AsyncClient( trust_env=False, headers={ "accept": "application/json", "user-agent": "python-httpx/0.24.0" }, ) as client: resp = await client.get( f"{api_base}/{resolved_endpoint}", params=params_dict ) resp.raise_for_status() resp_json = resp.json() if isinstance(resp_json, dict): status = resp_json.get("status") if status == "error": code = resp_json.get('code') raise HTTPException( status_code=code, detail=f"Failed to perform request," f" code = {code}, message = {resp_json.get('message')}" ) return response_model.model_validate(resp_json) - Helper function used by the handler to resolve path parameters like {symbol} in API endpoints.
def resolve_path_params(endpoint: str, params_dict: dict) -> str: def replacer(match): key = match.group(1) if key not in params_dict: raise ValueError(f"Missing path parameter: {key}") return str(params_dict.pop(key)) return re.sub(r"{(\w+)}", replacer, endpoint)