Skip to main content
Glama

rank_stocks

Analyze and rank stocks by market cap, price change, volume, or other metrics across global exchanges for specific dates to identify top performers.

Instructions

Rank stocks on an exchange by a chosen metric (marketCap, priceChangePct, volume, value, numTrades) for a specific date with order and limit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stockExchangeYesStock exchange: amex, nasdaq, nyse, us-all, lse, moex, bist, hkex
yearNo
monthNo
dayNo
sortByYesSort by: marketCap, priceChangePct, volume, value, numTrades
orderNoSort order: asc or descdesc
limitNoNumber of results
sectorNoFilter by specific sector

Implementation Reference

  • The handler function that executes the 'rank_stocks' tool logic: fetches market data, filters stocks by sector if specified, sorts by chosen metric and order, applies limit, and formats the response.
    async ({ stockExchange, year, month, day, sortBy, order, limit, sector, }: { stockExchange: StockExchange; year?: number; month?: number; day?: number; sortBy: SortField; order?: SortOrder; limit?: number; sector?: string; }) => { try { const formattedDate = getDate(year, month, day); const marketDataResponse = await fetchMarketData( stockExchange, formattedDate, ); const stocks = marketDataResponse.securities.data .filter( (item: any[]) => item[INDICES.TYPE] !== "sector" && item[INDICES.SECTOR] !== "", ) .filter((item: any[]) => !sector || item[INDICES.SECTOR] === sector) .map((item: any[]) => ({ ticker: item[INDICES.TICKER], name: item[INDICES.NAME_ENG], sector: item[INDICES.SECTOR], priceLastSale: item[INDICES.PRICE_LAST_SALE], priceChangePct: item[INDICES.PRICE_CHANGE_PCT], marketCap: item[INDICES.MARKET_CAP], volume: item[INDICES.VOLUME], value: item[INDICES.VALUE], numTrades: item[INDICES.NUM_TRADES], })) .sort((a: any, b: any) => { const aVal = a[sortBy], bVal = b[sortBy]; return order === "desc" ? bVal - aVal : aVal - bVal; }) .slice(0, limit); return createResponse({ info: INFO, charts: createCharts(stockExchange, formattedDate), date: formattedDate, exchange: stockExchange.toUpperCase(), currency: EXCHANGE_INFO[stockExchange as StockExchange].currency, sortBy, order, limit, count: stocks.length, stocks, }); } catch (error) { return createErrorResponse(error); } }, );
  • Input schema for 'rank_stocks' tool using Zod-like validation for parameters: stockExchange, date components, sortBy (enum), order (default desc), limit (1-500, default 10), optional sector.
    inputSchema: { stockExchange: exchangeSchema, ...dateSchema, sortBy: z .enum(SORT_FIELDS) .describe( "Sort by: marketCap, priceChangePct, volume, value, numTrades", ), order: z .enum(SORT_ORDERS) .default("desc") .describe("Sort order: asc or desc"), limit: z .number() .int() .min(1) .max(500) .default(10) .describe("Number of results"), sector: z.string().optional().describe("Filter by specific sector"), },
  • src/core.ts:682-682 (registration)
    Registration of the 'rank_stocks' tool in the registerFinmapTools function using server.registerTool.
    server.registerTool(
  • Type definitions for sortable fields and orders used in the rank_stocks tool.
    const SORT_FIELDS = [ "priceChangePct", "marketCap", "value", "volume", "numTrades", ] as const;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BACH-AI-Tools/bach-finmap-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server