create_order
Place limit or market orders on supported cryptocurrency exchanges like MEXC, Gate.io, Bitget, and Kraken for trading pairs such as BTC/USDT.
Instructions
Create a new order (limit or market) on a supported exchange
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange to query. Supported: mexc, gateio, bitget, kraken | |
| symbol | Yes | Trading pair symbol (e.g., BTC/USDT, INDY/USDT) | |
| type | Yes | Order type: limit or market | |
| side | Yes | Order side: buy or sell | |
| amount | Yes | Order amount in base currency | |
| price | No | Order price (required for limit orders, ignored for market orders) |
Implementation Reference
- src/tools/trading.ts:22-48 (handler)The main handler function that executes the create_order tool logic. It validates inputs, gets the exchange connector, calls connector.createOrder(), and returns the order result as JSON.
async ({ exchange, symbol, type, side, amount, price }) => { const validExchange = validateExchange(exchange); const validSymbol = validateSymbol(symbol); if (type === 'limit' && price === undefined) { throw new Error('Price is required for limit orders'); } const connector = await getConnectorSafe(exchange); const order = await connector.createOrder(validSymbol, type, side, amount, price); return { content: [ { type: 'text' as const, text: JSON.stringify( { order, exchange: validExchange, }, null, 2 ), }, ], }; } - src/tools/trading.ts:10-21 (schema)The input validation schema for create_order using zod. Defines exchange, symbol, type (limit/market), side (buy/sell), amount, and optional price parameters.
{ exchange: ExchangeParam, symbol: SymbolParam, type: z.enum(['limit', 'market']).describe('Order type: limit or market'), side: z.enum(['buy', 'sell']).describe('Order side: buy or sell'), amount: z.number().positive().describe('Order amount in base currency'), price: z .number() .positive() .optional() .describe('Order price (required for limit orders, ignored for market orders)'), }, - src/tools/trading.ts:7-49 (registration)The tool registration call using server.tool() that registers create_order with the MCP server, including the tool name, description, schema, and handler function.
server.tool( 'create_order', 'Create a new order (limit or market) on a supported exchange', { exchange: ExchangeParam, symbol: SymbolParam, type: z.enum(['limit', 'market']).describe('Order type: limit or market'), side: z.enum(['buy', 'sell']).describe('Order side: buy or sell'), amount: z.number().positive().describe('Order amount in base currency'), price: z .number() .positive() .optional() .describe('Order price (required for limit orders, ignored for market orders)'), }, async ({ exchange, symbol, type, side, amount, price }) => { const validExchange = validateExchange(exchange); const validSymbol = validateSymbol(symbol); if (type === 'limit' && price === undefined) { throw new Error('Price is required for limit orders'); } const connector = await getConnectorSafe(exchange); const order = await connector.createOrder(validSymbol, type, side, amount, price); return { content: [ { type: 'text' as const, text: JSON.stringify( { order, exchange: validExchange, }, null, 2 ), }, ], }; } ); - src/utils/validators.ts:3-7 (schema)Helper schemas used by create_order: ExchangeParam (validates exchange name) and SymbolParam (validates trading pair symbol format).
export const ExchangeParam = z .string() .describe('Exchange to query. Supported: mexc, gateio, bitget, kraken'); export const SymbolParam = z.string().describe('Trading pair symbol (e.g., BTC/USDT, INDY/USDT)'); - src/utils/validators.ts:23-32 (helper)The validateSymbol helper function used in the create_order handler to validate and normalize the trading pair symbol (converts to uppercase, checks format).
export function validateSymbol(symbol: string): string { if (!symbol) { throw new Error('Symbol is required'); } const upper = symbol.toUpperCase(); if (!/^[A-Z]+\/[A-Z]+$/.test(upper) && !/^[A-Z]+[A-Z]+$/.test(upper)) { throw new Error(`Invalid symbol format: ${symbol}. Expected: BTC/USDT or BTCUSDT`); } return upper; }