Skip to main content
Glama
jun229

truemarkets-mcp-server

by jun229

tm_execute_trade

Execute irreversible trades on True Markets by signing and submitting validated quotes within 60 seconds using Turnkey API authentication.

Instructions

Execute a trade using a quote_id from tm_get_quote.

IMPORTANT: Only call this after inspecting the quote from tm_get_quote. The quote must be less than 60 seconds old and have no issues.

This tool signs the quote payloads with the user's Turnkey API key and submits the trade. It is irreversible.

Args:

  • quote_id (string): The quote_id from tm_get_quote

Returns: { success, order_id, tx_hash, explorer_url }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
quote_idYesquote_id from tm_get_quote

Implementation Reference

  • The handler function for 'tm_execute_trade' that retrieves a cached quote, signs its payloads using the provided signer, and executes the trade via the API.
      async ({ quote_id }) => {
        const quote = getCachedQuote(quote_id);
        if (!quote) {
          return {
            isError: true,
            content: [{
              type: "text",
              text: "Quote expired or not found. Call tm_get_quote to get a fresh quote.",
            }],
          };
        }
    
        if (quote.issues.length > 0) {
          return {
            isError: true,
            content: [{
              type: "text",
              text: `Quote has issues: ${quote.issues.map((i) => i.message).join(", ")}. Cannot execute.`,
            }],
          };
        }
    
        if (!quote.payloads || quote.payloads.length === 0) {
          return {
            isError: true,
            content: [{ type: "text", text: "Quote has no payloads to sign." }],
          };
        }
    
        // Sign payloads
        const signer = getSigner();
        const signatures = signer.signAll(quote.payloads);
    
        // Execute
        const result = await api.executeTrade({
          quote_id: quote.quote_id,
          signatures,
          auth_type: "api_key",
        });
    
        // Clean up cache
        quoteCache.delete(quote_id);
    
        const chain = quote.base_asset.startsWith("0x") ? "base" : "solana";
        const explorerUrl = result.tx_hash
          ? txExplorerUrl(chain, result.tx_hash)
          : null;
    
        const output = {
          success: true,
          order_id: result.order_id ?? null,
          tx_hash: result.tx_hash ?? null,
          explorer_url: explorerUrl,
        };
    
        return {
          content: [{ type: "text", text: JSON.stringify(output, null, 2) }],
          structuredContent: output,
        };
      }
    );
  • Registration of the 'tm_execute_trade' tool within the McpServer.
      // ─── tm_execute_trade ────────────────────────────────────────
      server.registerTool(
        "tm_execute_trade",
        {
          title: "Execute a quoted trade",
          description: `Execute a trade using a quote_id from tm_get_quote.
    
    IMPORTANT: Only call this after inspecting the quote from tm_get_quote.
    The quote must be less than 60 seconds old and have no issues.
    
    This tool signs the quote payloads with the user's Turnkey API key
    and submits the trade. It is irreversible.
    
    Args:
      - quote_id (string): The quote_id from tm_get_quote
    
    Returns: { success, order_id, tx_hash, explorer_url }`,
          inputSchema: {
            quote_id: z.string().describe("quote_id from tm_get_quote"),
          },
          annotations: {
            readOnlyHint: false,
            destructiveHint: true,
            idempotentHint: false,
            openWorldHint: true,
          },
        },

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/jun229/tm-mcp-server'

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