Skip to main content
Glama

TradeStation MCP Server

by maven81g

getOptionExpirations

Retrieve available expiration dates for options contracts on specific stock symbols to support trading strategy planning and position management.

Instructions

Get available expiration dates for options on an underlying symbol

Input Schema

NameRequiredDescriptionDefault
underlyingYesUnderlying symbol (e.g., AAPL, SPY)

Input Schema (JSON Schema)

{ "properties": { "underlying": { "description": "Underlying symbol (e.g., AAPL, SPY)", "type": "string" } }, "required": [ "underlying" ], "type": "object" }

Implementation Reference

  • Executes the tool logic: extracts 'underlying' symbol from args, calls makeAuthenticatedRequest to TradeStation API endpoint for option expirations, returns formatted JSON response or error message.
    async (args) => { try { const { underlying } = args; const expirations = await makeAuthenticatedRequest( `/marketdata/options/expirations/${encodeURIComponent(underlying)}` ); return { content: [ { type: "text", text: JSON.stringify(expirations, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch option expirations: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } }
  • Zod schema defining the required input parameter 'underlying' as a string with description.
    const optionExpirationsSchema = { underlying: z.string().describe('Underlying symbol (e.g., AAPL, SPY)') };
  • src/index.ts:367-399 (registration)
    Registers the 'getOptionExpirations' tool with MCP server, providing name, description, input schema, and inline handler function.
    server.tool( "getOptionExpirations", "Get available expiration dates for options on an underlying symbol", optionExpirationsSchema, async (args) => { try { const { underlying } = args; const expirations = await makeAuthenticatedRequest( `/marketdata/options/expirations/${encodeURIComponent(underlying)}` ); return { content: [ { type: "text", text: JSON.stringify(expirations, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch option expirations: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } );
  • Shared utility function used by the handler to perform authenticated HTTP requests to the TradeStation API, handling token refresh automatically.
    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'); } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/maven81g/tradestation_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server