get_top_performers
Identify top-performing stocks in the Spanish stock exchange over a specified period to inform investment decisions.
Instructions
Get top performing stocks over a specified period
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | Period in days | |
| limit | No | Maximum number of results |
Implementation Reference
- src/database.ts:217-247 (handler)The core handler function that implements get_top_performers by fetching all companies, retrieving historical prices for the top 20, calculating percentage change over the specified days, sorting by performance, and returning the top limit performers.async getTopPerformers(days: number = 7, limit: number = 10): Promise<any[]> { const companies = await this.getAllCompanies(); // Get recent performance data for each company const performances = []; for (const company of companies.slice(0, 20)) { // Limit to avoid too many requests try { const historical = await this.getHistoricalPrices(company.id, days); if (historical.length >= 2) { const recent = historical[0]; const old = historical[historical.length - 1]; const changePercent = ((recent.close - old.close) / old.close) * 100; performances.push({ symbol: company.symbol, name: company.name, sector: company.sector, current_price: recent.close, period_change: changePercent }); } } catch (error) { // Skip companies with no data continue; } } return performances .sort((a, b) => b.period_change - a.period_change) .slice(0, limit); }
- src/index.ts:206-224 (schema)The tool schema definition including name, description, and input schema for parameters 'days' (default 7) and 'limit' (default 10), registered in the ListTools handler.{ name: 'get_top_performers', description: 'Get top performing stocks over a specified period', inputSchema: { type: 'object', properties: { days: { type: 'number', description: 'Period in days', default: 7, }, limit: { type: 'number', description: 'Maximum number of results', default: 10, }, }, }, },
- src/index.ts:621-623 (registration)The registration/dispatcher in the CallToolRequest handler that routes calls to get_top_performers to the DatabaseManager's getTopPerformers method.case 'get_top_performers': result = await this.db.getTopPerformers((args as any)?.days || 7, (args as any)?.limit || 10); break;