getLighthousePerformanceData
Retrieve performance metrics for a Lighthouse crypto portfolio by specifying a portfolio name and optional start date to analyze historical data securely.
Instructions
Get performance data for a Lighthouse portfolio
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| portfolio | No | Optional portfolio name | |
| startDate | No | Optional start date. Formatted as YYYY-MM-DD |
Implementation Reference
- index.ts:384-453 (handler)Handler function that executes the tool logic: resolves the portfolio slug, determines start date (default 30 days ago), fetches performance data via lighthouse client, and constructs a formatted markdown text response with timeframe, period return, asset type changes, top gainers, and top losers.execute: async (args) => { const portfolio = args.portfolio ? await lighthouse.findPortfolio(args.portfolio) : await lighthouse.findPortfolio(); const startDate = args.startDate ? new Date(args.startDate) : new Date(Date.now() - 30 * 24 * 60 * 60 * 1000); const performanceData = await lighthouse.getPerformanceData( portfolio.slug, startDate.toISOString().split("T")[0] ); return { content: [ { type: "text", text: `# ${portfolio.name} Performance Data Timeframe: ${performanceData.startsAt} - ${performanceData.endsAt} Period Return: ${formatNumber( performanceData.usdValueChange )} (${formatPercentage( (performanceData.usdValueChange / performanceData.lastSnapshotUsdValue) * 100 )}) ---- Performance by asset type: ${performanceData.changeByType .sort((a, b) => b.diffUsdValue - a.diffUsdValue) .map((asset) => { return `- ${asset.type}: ${formatNumber( asset.diffUsdValue )} (${formatPercentage( asset.prevUsdValue / asset.currUsdValue )}%)`; }) .join("\n")} ---- Top 5 Gainers: ${performanceData.gainers .sort((a, b) => b.diffUsdValue - a.diffUsdValue) .slice(0, 5) .map((gainer) => { return `- ${gainer.symbol}: ${formatNumber( gainer.diffUsdValue )} (${formatPercentage( gainer.diffUsdValue / gainer.prevUsdValue )}%)`; }) .join("\n")} ---- Top 5 Losers: ${performanceData.losers .sort((a, b) => a.diffUsdValue - b.diffUsdValue) .slice(0, 5) .map((loser) => { return `- ${loser.symbol}: ${formatNumber( loser.diffUsdValue )} (${formatPercentage( loser.diffUsdValue / loser.prevUsdValue )}%)`; }) .join("\n")} `, }, ], }; },
- index.ts:377-383 (schema)Zod schema for validating the tool's input parameters: optional portfolio name and optional start date (YYYY-MM-DD format).parameters: z.object({ portfolio: z.string().optional().describe("Optional portfolio name"), startDate: z .string() .optional() .describe("Optional start date. Formatted as YYYY-MM-DD"), }),
- index.ts:374-376 (registration)Registration of the getLighthousePerformanceData tool with FastMCP server, specifying name and description.server.addTool({ name: "getLighthousePerformanceData", description: "Get performance data for a Lighthouse portfolio",
- lighthouse.ts:492-505 (helper)Helper method in the Lighthouse class that performs the actual API call to retrieve performance data for a given portfolio slug and start date from the Lighthouse API.public async getPerformanceData( portfolioSlug: string, startDate: string ): Promise<PortfolioPerformanceResponse> { const response = await this.fetcher( `https://lighthouse.one/v1/workspaces/${portfolioSlug}/performance?startsAt=${startDate}` ); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } return await response.json(); }
- lighthouse.ts:214-224 (schema)TypeScript interface defining the expected structure of the performance data returned from the Lighthouse API, used for type safety.export interface PortfolioPerformanceResponse { startsAt: string; endsAt: string; presets: TimeRangePresets; // Reusing TimeRangePresets usdValueChange: number; lastSnapshotUsdValue: number; snapshots: Snapshot[]; // Reusing Snapshot gainers: GainerLoserItem[]; // Reusing GainerLoserItem losers: GainerLoserItem[]; // Reusing GainerLoserItem changeByType: ChangeByTypeItem[]; // Reusing ChangeByTypeItem }