list_sectors
Retrieve business sectors for a specific stock exchange on a given date, including item counts for financial analysis.
Instructions
List available business sectors for an exchange on a specific date, including item counts.
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 |
Implementation Reference
- src/core.ts:275-324 (registration)Registration of the 'list_sectors' tool using server.registerTool, including title, description, input schema, and handler function.server.registerTool( "list_sectors", { title: "List sectors", description: "List available business sectors for an exchange on a specific date, including item counts.", inputSchema: { stockExchange: exchangeSchema, ...dateSchema }, }, async ({ stockExchange, year, month, day, }: { stockExchange: StockExchange; year?: number; month?: number; day?: number; }) => { try { const formattedDate = getDate(year, month, day); const marketDataResponse = await fetchMarketData( stockExchange, formattedDate, ); const sectorCounts: Record<string, number> = {}; marketDataResponse.securities.data.forEach((item: any[]) => { if (item[INDICES.TYPE] !== "sector" && item[INDICES.SECTOR]) { sectorCounts[item[INDICES.SECTOR]] = (sectorCounts[item[INDICES.SECTOR]] || 0) + 1; } }); const sectors = Object.entries(sectorCounts).map(([name, count]) => ({ name, itemsPerSector: count, })); return createResponse({ info: INFO, date: formattedDate, exchange: stockExchange.toUpperCase(), currency: EXCHANGE_INFO[stockExchange as StockExchange].currency, sectors, }); } catch (error) { return createErrorResponse(error); } }, );
- src/core.ts:283-323 (handler)The handler function that fetches market data for the given exchange and date, counts the number of items per sector, and returns a list of sectors with their item counts.async ({ stockExchange, year, month, day, }: { stockExchange: StockExchange; year?: number; month?: number; day?: number; }) => { try { const formattedDate = getDate(year, month, day); const marketDataResponse = await fetchMarketData( stockExchange, formattedDate, ); const sectorCounts: Record<string, number> = {}; marketDataResponse.securities.data.forEach((item: any[]) => { if (item[INDICES.TYPE] !== "sector" && item[INDICES.SECTOR]) { sectorCounts[item[INDICES.SECTOR]] = (sectorCounts[item[INDICES.SECTOR]] || 0) + 1; } }); const sectors = Object.entries(sectorCounts).map(([name, count]) => ({ name, itemsPerSector: count, })); return createResponse({ info: INFO, date: formattedDate, exchange: stockExchange.toUpperCase(), currency: EXCHANGE_INFO[stockExchange as StockExchange].currency, sectors, }); } catch (error) { return createErrorResponse(error); } },
- src/core.ts:277-282 (schema)Input schema definition for the 'list_sectors' tool, including title, description, and Zod-based input schema referencing exchangeSchema and dateSchema.{ title: "List sectors", description: "List available business sectors for an exchange on a specific date, including item counts.", inputSchema: { stockExchange: exchangeSchema, ...dateSchema }, },