get_signal_stats
Analyze trading strategy performance by retrieving statistics like win rate, total trades, and P&L metrics for specified time periods.
Instructions
Get signal statistics and performance metrics for a strategy, including win rate, total trades, and P&L.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| strategyId | No | Strategy ID (omit for all strategies) | |
| period | No | Time period | 30d |
Implementation Reference
- src/signals-server.ts:91-112 (handler)Main handler implementation for get_signal_stats tool. Registers the tool with MCP server, defines input schema using zod (strategyId optional, period enum with default '30d'), and implements the handler that calls client.getAnalytics() and returns the statistics data as JSON.
server.tool( 'get_signal_stats', 'Get signal statistics and performance metrics for a strategy, including win rate, total trades, and P&L.', { strategyId: z.string().optional().describe('Strategy ID (omit for all strategies)'), period: z.enum(['7d', '30d', '90d', '1y', 'all']).default('30d').describe('Time period'), }, async ({ strategyId, period }) => { try { const result = await client.getAnalytics({ type: 'signals', period }); return { content: [{ type: 'text', text: JSON.stringify(result.data || { message: 'No stats available' }, null, 2), }], }; } catch (error: any) { return { content: [{ type: 'text', text: `Error: ${error.message}` }] }; } } ); - src/common/client.ts:93-95 (helper)getAnalytics client method that wraps the API call. Accepts optional 'type' and 'period' parameters and makes a POST request to '/getAnalytics' endpoint. This is called by the get_signal_stats handler with type='signals'.
async getAnalytics(params: { type?: string; period?: string } = {}) { return this.call('/getAnalytics', params); } - src/common/client.ts:15-47 (helper)Base call method that performs HTTP POST requests to the QuantToGo API. Handles authentication headers (Bearer token and x-user-id), error handling, and response parsing. Used by getAnalytics and all other client methods.
async call<T = any>(path: string, data: Record<string, any> = {}): Promise<ApiResponse<T>> { const url = `${this.apiBase}${path}`; const headers: Record<string, string> = { 'Content-Type': 'application/json', }; if (this.apiKey) { headers['Authorization'] = `Bearer ${this.apiKey}`; } if (this.userId) { headers['x-user-id'] = this.userId; } const response = await fetch(url, { method: 'POST', headers, body: JSON.stringify(data), }); if (!response.ok) { const errorText = await response.text(); throw new Error(`API error ${response.status}: ${errorText}`); } const result = await response.json() as ApiResponse<T>; if (result.code !== undefined && result.success === undefined) { result.success = result.code === 0; } return result; } - src/common/types.ts:3-8 (schema)ApiResponse type definition that defines the structure of API responses including code, data, message, and success fields. Used as the return type for all client methods including getAnalytics.
export interface ApiResponse<T = any> { code: number; data?: T; message?: string; success?: boolean; }