get_strategy_performance
Retrieve detailed performance metrics for a trading strategy, including returns, drawdown, Sharpe ratio, win rate, and daily NAV history for charting.
Instructions
Get detailed performance for a specific strategy — returns, drawdown, Sharpe, win rate, and daily NAV history for charting. Requires API key (get one free via register_trial).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | Yes | Your API key from register_trial (starts with 'qtg_') | |
| productId | Yes | Strategy product ID, e.g. 'PROD-E3X' | |
| includeChart | No | Include daily NAV data points for charting |
Implementation Reference
- src/index.ts:89-164 (registration)The 'get_strategy_performance' tool is registered via server.tool() inside registerTools(). It defines the schema (apiKey, productId, includeChart) and the handler function.
server.tool( "get_strategy_performance", "Get detailed performance for a specific strategy — returns, drawdown, Sharpe, win rate, and daily NAV history for charting. Requires API key (get one free via register_trial).", { apiKey: z.string().describe("Your API key from register_trial (starts with 'qtg_')"), productId: z.string().describe("Strategy product ID, e.g. 'PROD-E3X'"), includeChart: z .boolean() .optional() .default(true) .describe("Include daily NAV data points for charting"), }, async ({ apiKey, productId, includeChart }) => { const auth = await validateApiKey(apiKey); if (!auth.valid) { return { content: [{ type: "text" as const, text: auth.message }] }; } const [detailRes, chartRes] = await Promise.all([ callAPI("getProductDetail", { productId }) as Promise<{ code: number; data: Record<string, unknown>; }>, includeChart ? (callAPI("getProductChart", { productId }) as Promise<{ code: number; data: Record<string, unknown>; }>) : Promise.resolve(null), ]); if (detailRes.code !== 0 || !detailRes.data) { return { content: [ { type: "text" as const, text: `Strategy '${productId}' not found`, }, ], }; } const d = detailRes.data; const result: Record<string, unknown> = { productId: d.productId, name: d.name, market: d.market, description: d.description || d.shortDescription, totalReturn: d.totalReturn ?? d.totalReturn5Y, metricsYearLabel: d.metricsYearLabel, maxDrawdown: d.maxDrawdown, recent1dReturn: d.recent1dReturn, recent30dReturn: d.recent30dReturn, tradeCount: d.tradeCount ?? d.tradeCount5Y, status: d.status, }; if (chartRes?.data) { const cd = chartRes.data; result.chart = { totalPoints: cd.totalPoints, lastUpdated: cd.lastUpdated, dataPoints: cd.dataPoints, // [{d, nav}, ...] }; } return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2), }, ], }; } ); - src/index.ts:92-100 (schema)Input schema for get_strategy_performance: apiKey (string), productId (string), includeChart (optional boolean, defaults to true).
{ apiKey: z.string().describe("Your API key from register_trial (starts with 'qtg_')"), productId: z.string().describe("Strategy product ID, e.g. 'PROD-E3X'"), includeChart: z .boolean() .optional() .default(true) .describe("Include daily NAV data points for charting"), }, - src/index.ts:101-163 (handler)Handler function: validates API key, calls getProductDetail and optionally getProductChart APIs, formats result with strategy metrics (totalReturn, maxDrawdown, recent1dReturn, recent30dReturn, tradeCount, etc.) and optional chart data (dataPoints with NAV history). Returns JSON stringified result.
async ({ apiKey, productId, includeChart }) => { const auth = await validateApiKey(apiKey); if (!auth.valid) { return { content: [{ type: "text" as const, text: auth.message }] }; } const [detailRes, chartRes] = await Promise.all([ callAPI("getProductDetail", { productId }) as Promise<{ code: number; data: Record<string, unknown>; }>, includeChart ? (callAPI("getProductChart", { productId }) as Promise<{ code: number; data: Record<string, unknown>; }>) : Promise.resolve(null), ]); if (detailRes.code !== 0 || !detailRes.data) { return { content: [ { type: "text" as const, text: `Strategy '${productId}' not found`, }, ], }; } const d = detailRes.data; const result: Record<string, unknown> = { productId: d.productId, name: d.name, market: d.market, description: d.description || d.shortDescription, totalReturn: d.totalReturn ?? d.totalReturn5Y, metricsYearLabel: d.metricsYearLabel, maxDrawdown: d.maxDrawdown, recent1dReturn: d.recent1dReturn, recent30dReturn: d.recent30dReturn, tradeCount: d.tradeCount ?? d.tradeCount5Y, status: d.status, }; if (chartRes?.data) { const cd = chartRes.data; result.chart = { totalPoints: cd.totalPoints, lastUpdated: cd.lastUpdated, dataPoints: cd.dataPoints, // [{d, nav}, ...] }; } return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2), }, ], }; } - src/index.ts:11-19 (helper)Helper function callAPI used by the handler to make HTTP POST requests to the QuantToGo API.
async function callAPI(fn: string, body: Record<string, unknown> = {}): Promise<unknown> { const resp = await fetch(`${API_BASE}/${fn}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); if (!resp.ok) throw new Error(`API ${fn} returned ${resp.status}`); return resp.json(); } - src/index.ts:21-30 (helper)Helper function validateApiKey used by the handler to verify API key validity before fetching performance data.
async function validateApiKey(apiKey: string): Promise<{ valid: boolean; message: string }> { const res = (await callAPI("getApiStatus", { apiKey })) as { code: number; message: string; }; if (res.code === 401) return { valid: false, message: "Invalid API key. Use register_trial with your email to get a valid key." }; if (res.code === 403) return { valid: false, message: "Trial expired. Email admin@quanttogo.com to subscribe." }; if (res.code !== 0) return { valid: false, message: res.message || "API key validation failed." }; return { valid: true, message: "ok" }; }