execute_trade
Execute token trades in a simulated environment by specifying source and destination tokens, amount, and reason, with optional chain and slippage settings.
Instructions
Execute a trade between tokens
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromToken | Yes | Source token address | |
| toToken | Yes | Destination token address | |
| amount | Yes | Amount of fromToken to trade | |
| reason | Yes | Reason for executing this trade | |
| slippageTolerance | No | Optional slippage tolerance percentage (e.g., '0.5' for 0.5%) | |
| fromChain | No | Optional blockchain type for source token | |
| toChain | No | Optional blockchain type for destination token | |
| fromSpecificChain | No | Optional specific chain for source token | |
| toSpecificChain | No | Optional specific chain for destination token |
Implementation Reference
- src/index.ts:550-575 (handler)MCP CallToolRequest handler for execute_trade: validates input arguments, constructs TradeParams, calls tradingClient.executeTrade, and returns the response.case "execute_trade": { if (!args || typeof args !== "object" || !("fromToken" in args) || !("toToken" in args) || !("amount" in args) || !("reason" in args)) { throw new Error("Invalid arguments for execute_trade"); } const tradeExecParams: TradeParams = { fromToken: args.fromToken as string, toToken: args.toToken as string, amount: args.amount as string, reason: args.reason as string }; if ("slippageTolerance" in args) tradeExecParams.slippageTolerance = args.slippageTolerance as string; if ("fromChain" in args) tradeExecParams.fromChain = args.fromChain as BlockchainType; if ("toChain" in args) tradeExecParams.toChain = args.toChain as BlockchainType; if ("fromSpecificChain" in args) tradeExecParams.fromSpecificChain = args.fromSpecificChain as SpecificChain; if ("toSpecificChain" in args) tradeExecParams.toSpecificChain = args.toSpecificChain as SpecificChain; const response = await tradingClient.executeTrade(tradeExecParams); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }], isError: false }; }
- src/types.ts:71-81 (schema)TypeScript interface defining the TradeParams used for execute_trade input validation and typing.export interface TradeParams { fromToken: string; toToken: string; amount: string; reason: string; slippageTolerance?: string; fromChain?: BlockchainType; toChain?: BlockchainType; fromSpecificChain?: SpecificChain; toSpecificChain?: SpecificChain; }
- src/index.ts:253-304 (registration)MCP Tool registration definition including name, description, and JSON schema for input validation.{ name: "execute_trade", description: "Execute a trade between tokens", inputSchema: { type: "object", properties: { fromToken: { type: "string", description: "Source token address" }, toToken: { type: "string", description: "Destination token address" }, amount: { type: "string", description: "Amount of fromToken to trade" }, reason: { type: "string", description: "Reason for executing this trade" }, slippageTolerance: { type: "string", description: "Optional slippage tolerance percentage (e.g., '0.5' for 0.5%)" }, fromChain: { type: "string", enum: ["svm", "evm"], description: "Optional blockchain type for source token" }, toChain: { type: "string", enum: ["svm", "evm"], description: "Optional blockchain type for destination token" }, fromSpecificChain: { type: "string", enum: ["eth", "polygon", "bsc", "arbitrum", "base", "optimism", "avalanche", "linea", "svm"], description: "Optional specific chain for source token" }, toSpecificChain: { type: "string", enum: ["eth", "polygon", "bsc", "arbitrum", "base", "optimism", "avalanche", "linea", "svm"], description: "Optional specific chain for destination token" } }, required: ["fromToken", "toToken", "amount", "reason"], additionalProperties: false, $schema: "http://json-schema.org/draft-07/schema#" } },
- src/api-client.ts:466-477 (helper)Helper method in TradingSimulatorClient that performs the actual API POST request to execute the trade.async executeTrade(params: TradeParams): Promise<TradeResponse | ErrorResponse> { if (this.debug) { logger.info('[ApiClient] executeTrade called with params:', JSON.stringify(params, null, 2)); } return this.request<TradeResponse>( 'POST', '/api/trade/execute', params, 'execute trade' ); }