marketData
Retrieve real-time market quotes for financial symbols to access current pricing data through TradeStation's trading platform.
Instructions
Get quotes for symbols
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbols | Yes | Comma-separated list of symbols |
Input Schema (JSON Schema)
{
"properties": {
"symbols": {
"description": "Comma-separated list of symbols",
"type": "string"
}
},
"required": [
"symbols"
],
"type": "object"
}
Implementation Reference
- index.js:426-455 (handler)The handler function for the 'marketData' tool. It takes comma-separated symbols, makes an authenticated API request to TradeStation's /marketdata/quotes endpoint, and returns the JSON response or an error message.async ({ arguments: args }) => { try { const { symbols } = args; const userId = args.userId; // You might need to pass this differently const quotes = await makeAuthenticatedRequest( userId, `/marketdata/quotes?symbols=${encodeURIComponent(symbols)}` ); return { content: [ { type: "text", text: JSON.stringify(quotes, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Failed to fetch market data: ${error.message}` } ], isError: true }; } }
- index.js:74-76 (schema)Zod input schema for the 'marketData' tool, defining the required 'symbols' parameter as a string.const marketDataSchema = z.object({ symbols: z.string().describe('Comma-separated list of symbols') });
- index.js:422-456 (registration)Registration of the 'marketData' tool with the MCP server using server.tool(), including name, description, schema, and handler function.server.tool( "marketData", "Get quotes for symbols", marketDataSchema, async ({ arguments: args }) => { try { const { symbols } = args; const userId = args.userId; // You might need to pass this differently const quotes = await makeAuthenticatedRequest( userId, `/marketdata/quotes?symbols=${encodeURIComponent(symbols)}` ); return { content: [ { type: "text", text: JSON.stringify(quotes, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Failed to fetch market data: ${error.message}` } ], isError: true }; } } );
- index.js:129-163 (helper)Helper function used by the marketData handler to make authenticated requests to the TradeStation API, handling token refresh if needed.async function makeAuthenticatedRequest(userId, endpoint, method = 'GET', data = null) { const userTokens = tokenStore.get(userId); if (!userTokens) { throw new Error('User not authenticated'); } // 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(userId, newTokens); } try { const options = { method, url: `${TS_API_BASE}${endpoint}`, headers: { 'Authorization': `Bearer ${tokenStore.get(userId).accessToken}`, 'Content-Type': 'application/json' } }; if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH')) { options.data = data; } const response = await axios(options); return response.data; } catch (error) { console.error('API request error:', error.response?.data || error.message); throw error; } }