get_index_data
Retrieve custom China A-share momentum indices using your API key. Choose between DA-MOMENTUM and QTG-MOMENTUM, or omit indexId for a summary.
Instructions
Get custom market indices — China A-share momentum and strategy-weighted momentum. 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_') | |
| indexId | No | Index ID. Omit to get summary of all indices. |
Implementation Reference
- src/index.ts:168-169 (registration)Registration of the 'get_index_data' tool via server.tool()
server.tool( "get_index_data", - src/index.ts:171-177 (schema)Input schema for the tool: apiKey (string) and optional indexId (enum of 'DA-MOMENTUM' or 'QTG-MOMENTUM')
{ apiKey: z.string().describe("Your API key from register_trial (starts with 'qtg_')"), indexId: z .enum(["DA-MOMENTUM", "QTG-MOMENTUM"]) .optional() .describe("Index ID. Omit to get summary of all indices."), }, - src/index.ts:178-220 (handler)Handler function: validates API key, calls API 'getIndexData' in summary or detail mode, returns JSON result
async ({ apiKey, indexId }) => { const auth = await validateApiKey(apiKey); if (!auth.valid) { return { content: [{ type: "text" as const, text: auth.message }] }; } if (!indexId) { // Summary mode const res = (await callAPI("getIndexData", { action: "summary", })) as { code: number; data: Record<string, unknown>[] }; if (res.code !== 0) { return { content: [{ type: "text" as const, text: "Failed to fetch indices" }], }; } return { content: [ { type: "text" as const, text: JSON.stringify(res.data, null, 2) }, ], }; } // Detail mode const res = (await callAPI("getIndexData", { action: "detail", indexId, })) as { code: number; data: Record<string, unknown> }; if (res.code !== 0 || !res.data) { return { content: [ { type: "text" as const, text: `Index '${indexId}' not found` }, ], }; } return { content: [ { type: "text" as const, text: JSON.stringify(res.data, null, 2) }, ], }; } ); - src/index.ts:11-19 (helper)Helper function callAPI — makes POST requests to the external API endpoint
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 — validates the API key before executing the tool
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" }; }