get_top_performers
Identify top-performing stocks in the Spanish IBEX 35 index over a specified time period to support investment analysis and decision-making.
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)Main handler logic for the get_top_performers tool. Fetches all companies, retrieves historical prices for the top 20, calculates percentage change over the specified period, sorts by performance, and returns 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:621-623 (handler)MCP tool call handler dispatcher that receives tool arguments and delegates to DatabaseManager.getTopPerformers.case 'get_top_performers': result = await this.db.getTopPerformers((args as any)?.days || 7, (args as any)?.limit || 10); break;
- src/index.ts:207-224 (schema)Input schema definition and tool registration for get_top_performers in the ListTools response.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/analytics.ts:291-291 (helper)Usage of getTopPerformers as a helper in natural language query analysis fallback.const top_performers = await this.db.getTopPerformers(7, 5);
- src/analytics.ts:277-277 (helper)Usage of getTopPerformers as a helper in price/trend query handling.const topPerformers = await this.db.getTopPerformers(30, 10);