getSymbolDetails
Retrieve detailed information for trading symbols to access market data and make informed decisions using TradeStation's API.
Instructions
Get detailed symbol information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbols | Yes | Single symbol or comma-separated list of symbols |
Implementation Reference
- src/index.ts:668-700 (handler)Full handler implementation and registration for the getSymbolDetails tool. Calls TradeStation API endpoint /marketdata/symbols/{symbols} to retrieve detailed symbol information.server.tool( "getSymbolDetails", "Get detailed symbol information", symbolDetailsSchema, async (args) => { try { const { symbols } = args; const symbolDetails = await makeAuthenticatedRequest( `/marketdata/symbols/${encodeURIComponent(symbols)}` ); return { content: [ { type: "text", text: JSON.stringify(symbolDetails, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch symbol details: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } );
- src/index.ts:129-131 (schema)Zod input schema for getSymbolDetails tool, defining the required 'symbols' parameter as a string.const symbolDetailsSchema = { symbols: z.string().describe('Single symbol or comma-separated list of symbols') };
- src/index.ts:179-230 (helper)Shared helper function used by getSymbolDetails (and other tools) to make authenticated requests to TradeStation API, including automatic token refresh.async function makeAuthenticatedRequest( endpoint: string, method: AxiosRequestConfig['method'] = 'GET', data: any = null ): Promise<any> { const userTokens = tokenStore.get(DEFAULT_USER); if (!userTokens) { throw new Error('User not authenticated. Please set TRADESTATION_REFRESH_TOKEN in .env file.'); } // Check if token is expired or about to expire (within 60 seconds) if (userTokens.expiresAt < Date.now() + 60000) { // Refresh the token const newTokens = await refreshToken(userTokens.refreshToken); tokenStore.set(DEFAULT_USER, newTokens); } try { const options: AxiosRequestConfig = { method, url: `${TS_API_BASE}${endpoint}`, headers: { 'Authorization': `Bearer ${tokenStore.get(DEFAULT_USER)?.accessToken}`, 'Content-Type': 'application/json', 'Accept': 'application/json' }, timeout: 60000 }; if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH')) { options.data = data; } const response = await axios(options); return response.data; } catch (error: unknown) { if (error instanceof AxiosError) { const errorMessage = error.response?.data?.Message || error.response?.data?.message || error.message; const statusCode = error.response?.status; console.error(`API request error [${statusCode}]: ${errorMessage}`); console.error('Endpoint:', endpoint); throw new Error(`API Error (${statusCode}): ${errorMessage}`); } else if (error instanceof Error) { console.error('API request error:', error.message); throw error; } else { console.error('Unknown API request error:', error); throw new Error('Unknown API request error'); } } }
- src/index.ts:668-700 (registration)MCP server tool registration for getSymbolDetails using server.tool() method.server.tool( "getSymbolDetails", "Get detailed symbol information", symbolDetailsSchema, async (args) => { try { const { symbols } = args; const symbolDetails = await makeAuthenticatedRequest( `/marketdata/symbols/${encodeURIComponent(symbols)}` ); return { content: [ { type: "text", text: JSON.stringify(symbolDetails, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch symbol details: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } );