execute_trade
Facilitates token trades on the Trading Simulator MCP Server by specifying source and destination tokens, amounts, and optional parameters like slippage tolerance and blockchain chains for accurate execution.
Instructions
Execute a trade between tokens
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount of fromToken to trade | |
| fromChain | No | Optional blockchain type for source token | |
| fromSpecificChain | No | Optional specific chain for source token | |
| fromToken | Yes | Source token address | |
| reason | Yes | Reason for executing this trade | |
| slippageTolerance | No | Optional slippage tolerance percentage (e.g., '0.5' for 0.5%) | |
| toChain | No | Optional blockchain type for destination token | |
| toSpecificChain | No | Optional specific chain for destination token | |
| toToken | Yes | Destination token address |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"amount": {
"description": "Amount of fromToken to trade",
"type": "string"
},
"fromChain": {
"description": "Optional blockchain type for source token",
"enum": [
"svm",
"evm"
],
"type": "string"
},
"fromSpecificChain": {
"description": "Optional specific chain for source token",
"enum": [
"eth",
"polygon",
"bsc",
"arbitrum",
"base",
"optimism",
"avalanche",
"linea",
"svm"
],
"type": "string"
},
"fromToken": {
"description": "Source token address",
"type": "string"
},
"reason": {
"description": "Reason for executing this trade",
"type": "string"
},
"slippageTolerance": {
"description": "Optional slippage tolerance percentage (e.g., '0.5' for 0.5%)",
"type": "string"
},
"toChain": {
"description": "Optional blockchain type for destination token",
"enum": [
"svm",
"evm"
],
"type": "string"
},
"toSpecificChain": {
"description": "Optional specific chain for destination token",
"enum": [
"eth",
"polygon",
"bsc",
"arbitrum",
"base",
"optimism",
"avalanche",
"linea",
"svm"
],
"type": "string"
},
"toToken": {
"description": "Destination token address",
"type": "string"
}
},
"required": [
"fromToken",
"toToken",
"amount",
"reason"
],
"type": "object"
}
Implementation Reference
- src/index.ts:550-575 (handler)The handler function for the 'execute_trade' tool. Validates the input arguments, constructs TradeParams, and calls tradingClient.executeTrade to perform the trade.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/index.ts:254-304 (schema)Tool definition including name, description, and detailed input schema for 'execute_trade'.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/index.ts:411-415 (registration)Registration of all tools, including 'execute_trade', via the ListToolsRequestSchema handler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: TRADING_SIM_TOOLS }; });
- src/types.ts:71-81 (schema)TypeScript interface defining the TradeParams used in the execute_trade handler.export interface TradeParams { fromToken: string; toToken: string; amount: string; reason: string; slippageTolerance?: string; fromChain?: BlockchainType; toChain?: BlockchainType; fromSpecificChain?: SpecificChain; toSpecificChain?: SpecificChain; }