get_sectors_overview
Retrieve aggregated performance metrics by sector for specific stock exchanges on chosen dates to analyze market trends and sector performance.
Instructions
Get aggregated performance metrics by sector for an exchange on a specific date.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stockExchange | Yes | Stock exchange: amex, nasdaq, nyse, us-all, lse, moex, bist, hkex | |
| year | No | ||
| month | No | ||
| day | No | ||
| sector | No | Get data for specific sector only |
Implementation Reference
- src/core.ts:563-610 (handler)The asynchronous handler function that implements the core logic of the 'get_sectors_overview' tool. It fetches market data for the specified exchange and date, filters for sector entries, optionally filters by a specific sector, maps the data to a structured format, and returns a response with charts and metrics.async ({ stockExchange, year, month, day, sector, }: { stockExchange: StockExchange; year?: number; month?: number; day?: number; sector?: string; }) => { try { const formattedDate = getDate(year, month, day); const marketDataResponse = await fetchMarketData( stockExchange, formattedDate, ); const sectors = marketDataResponse.securities.data .filter( (item: any) => item[INDICES.TYPE] === "sector" && item[INDICES.SECTOR] !== "", ) .filter((item: any) => !sector || item[INDICES.TICKER] === sector) .map((item: any) => ({ name: item[INDICES.TICKER], marketCap: item[INDICES.MARKET_CAP], marketCapChangePct: item[INDICES.PRICE_CHANGE_PCT], volume: item[INDICES.VOLUME], value: item[INDICES.VALUE], numTrades: item[INDICES.NUM_TRADES], itemsPerSector: item[INDICES.ITEMS_PER_SECTOR], })); return createResponse({ info: INFO, charts: createCharts(stockExchange, formattedDate), date: formattedDate, exchange: stockExchange.toUpperCase(), currency: EXCHANGE_INFO[stockExchange as StockExchange].currency, sectors, }); } catch (error) { return createErrorResponse(error); } },
- src/core.ts:550-562 (schema)The tool metadata including title, description, and inputSchema using Zod for validation of parameters: stockExchange (enum), optional date components (year, month, day), and optional sector string.{ title: "Sector performance", description: "Get aggregated performance metrics by sector for an exchange on a specific date.", inputSchema: { stockExchange: exchangeSchema, ...dateSchema, sector: z .string() .optional() .describe("Get data for specific sector only"), }, },
- src/core.ts:548-611 (registration)The MCP server registration call for the 'get_sectors_overview' tool, including the tool name, schema/metadata, and handler function reference.server.registerTool( "get_sectors_overview", { title: "Sector performance", description: "Get aggregated performance metrics by sector for an exchange on a specific date.", inputSchema: { stockExchange: exchangeSchema, ...dateSchema, sector: z .string() .optional() .describe("Get data for specific sector only"), }, }, async ({ stockExchange, year, month, day, sector, }: { stockExchange: StockExchange; year?: number; month?: number; day?: number; sector?: string; }) => { try { const formattedDate = getDate(year, month, day); const marketDataResponse = await fetchMarketData( stockExchange, formattedDate, ); const sectors = marketDataResponse.securities.data .filter( (item: any) => item[INDICES.TYPE] === "sector" && item[INDICES.SECTOR] !== "", ) .filter((item: any) => !sector || item[INDICES.TICKER] === sector) .map((item: any) => ({ name: item[INDICES.TICKER], marketCap: item[INDICES.MARKET_CAP], marketCapChangePct: item[INDICES.PRICE_CHANGE_PCT], volume: item[INDICES.VOLUME], value: item[INDICES.VALUE], numTrades: item[INDICES.NUM_TRADES], itemsPerSector: item[INDICES.ITEMS_PER_SECTOR], })); return createResponse({ info: INFO, charts: createCharts(stockExchange, formattedDate), date: formattedDate, exchange: stockExchange.toUpperCase(), currency: EXCHANGE_INFO[stockExchange as StockExchange].currency, sectors, }); } catch (error) { return createErrorResponse(error); } }, );