GetMarketState
Check stock exchange operating status, including open/close times and availability across global markets. Retrieve current market state data for trading decisions.
Instructions
Check the state of all available exchanges, time to open, and time to close. Returns all available stock exchanges by default.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- Generic HTTP client handler used by all tools, including GetMarketState, to call the corresponding Twelve Data API endpoint (/market_state). Handles param resolution, API key injection, error handling, and response validation.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)
- scripts/generate_tools.py:58-68 (registration)Code generator template that creates the specific registration for GetMarketState (and all tools) via @server.tool decorator, mapping operationId to tool name, with generic handler call to /market_state endpoint.lines.append('def register_all_tools(server: FastMCP, _call_endpoint):') for op, desc, key in ops: fixed_op = fix_case(op) lines += [ f' @server.tool(name="{op}",', f' description="{desc}")', f' async def {op}(params: {fixed_op}Request, ctx: Context) -> {fixed_op}200Response:', f' return await _call_endpoint("{key}", params, {fixed_op}200Response, ctx)', '' ] return '\n'.join(lines)
- src/mcp_server_twelve_data/server.py:87-89 (registration)Where register_all_tools is invoked to register all tools including GetMarketState.if vector_db_exists(): register_all_tools(server=server, _call_endpoint=_call_endpoint) u_tool = register_u_tool(
- Generator for response Pydantic models from OpenAPI spec, used by GetMarketState (though example shows alias for another tool). GetMarketState200Response would be similarly generated.alias_lines = [ '', '# Aliases for response models', 'GetMarketMovers200Response = MarketMoversResponseBody',
- test/endpoint_pairs.py:122-122 (helper)Test pairing confirming GetMarketState tool exists for market status queries.("Is the NASDAQ market currently open?", "GetMarketState"),