Skip to main content
Glama
maven81g

TradeStation MCP Server

by maven81g

getExecutions

Retrieve fill details and execution data for a specific TradeStation order to track trade completion and verify transaction records.

Instructions

Get fills/executions for a specific order

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdNoAccount ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided)
orderIdYesOrder ID

Implementation Reference

  • The core handler function implementing the getExecutions tool logic. It fetches order executions from the TradeStation API endpoint `/brokerage/accounts/{accountId}/orders/{orderId}/executions`, handles accountId fallback to environment variable, and returns formatted JSON response or error.
    async (args) => {
      try {
        const accountId = args.accountId || TS_ACCOUNT_ID;
        const { orderId } = args;
    
        if (!accountId) {
          throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.');
        }
    
        const executions = await makeAuthenticatedRequest(
          `/brokerage/accounts/${encodeURIComponent(accountId)}/orders/${encodeURIComponent(orderId)}/executions`
        );
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(executions, null, 2)
            }
          ]
        };
      } catch (error: unknown) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to fetch executions: ${error instanceof Error ? error.message : 'Unknown error'}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod input schema for the getExecutions tool, defining optional accountId and required orderId parameters.
    const executionsSchema = {
      accountId: z.string().optional().describe('Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided)'),
      orderId: z.string().describe('Order ID')
    };
  • src/index.ts:629-666 (registration)
    MCP server registration of the getExecutions tool, specifying name, description, input schema, and inline handler function.
    server.tool(
      "getExecutions",
      "Get fills/executions for a specific order",
      executionsSchema,
      async (args) => {
        try {
          const accountId = args.accountId || TS_ACCOUNT_ID;
          const { orderId } = args;
    
          if (!accountId) {
            throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.');
          }
    
          const executions = await makeAuthenticatedRequest(
            `/brokerage/accounts/${encodeURIComponent(accountId)}/orders/${encodeURIComponent(orderId)}/executions`
          );
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(executions, null, 2)
              }
            ]
          };
        } catch (error: unknown) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to fetch executions: ${error instanceof Error ? error.message : 'Unknown error'}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Shared helper function called by the getExecutions handler to perform authenticated HTTP requests to the 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');
        }
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions retrieving data but fails to specify if this is a read-only operation, requires authentication, has rate limits, or returns paginated results. For a data retrieval tool with zero annotation coverage, this leaves critical behavioral traits unexplained.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without any unnecessary words. It is front-loaded with the core action and resource, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is insufficient for a tool that retrieves data. It does not explain the return format (e.g., list of executions, error handling), authentication needs, or how it differs from sibling tools, leaving gaps in understanding its full context and usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema fully documents the parameters (accountId and orderId). The description adds no additional meaning beyond implying that 'orderId' is used to fetch executions, which is already clear from the schema. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('fills/executions for a specific order'), making the purpose unambiguous. However, it does not differentiate this tool from potential siblings like 'getOrderDetails' or 'getOrders', which might also retrieve order-related data, leaving room for ambiguity in tool selection.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings such as 'getOrderDetails' and 'getOrders' available, there is no indication of whether this tool is for detailed execution data versus summary order information, leading to potential misuse without additional context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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