createOrder
Place cryptocurrency buy or sell orders on exchanges by specifying account, symbol, type, side, and amount.
Instructions
Create a new order using a configured account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountName | Yes | Account name defined in the configuration file (e.g., 'bybit_main') | |
| symbol | Yes | Trading symbol (e.g., 'BTC/USDT') | |
| type | Yes | Order type: 'market' or 'limit' | |
| side | Yes | Order side: 'buy' or 'sell' | |
| amount | Yes | Amount of base currency to trade | |
| price | No | Price per unit (required for limit orders) | |
| params | No | Additional exchange-specific parameters |
Implementation Reference
- src/tools/order-tools.ts:41-98 (handler)Handler function that gets the exchange instance and calls ccxt's createOrder method, handles validation and errors.async ({ accountName, symbol, type, side, amount, price, params, }) => { try { const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 // 주문 유형이 limit인데 가격이 없는 경우 if (type === "limit" && price === undefined) { return { content: [ { type: "text", text: "Price is required for limit orders", }, ], isError: true, }; } const order = await exchange.createOrder( symbol, type, side, amount, price, params, ); return { content: [ { type: "text", text: JSON.stringify(order, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error creating order for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } },
- src/tools/order-tools.ts:20-40 (schema)Zod schema defining the input parameters for the createOrder tool.{ accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"), type: z .enum(["market", "limit"]) .describe("Order type: 'market' or 'limit'"), side: z.enum(["buy", "sell"]).describe("Order side: 'buy' or 'sell'"), amount: z.number().describe("Amount of base currency to trade"), price: z .number() .optional() .describe("Price per unit (required for limit orders)"), params: z .record(z.any()) .optional() .describe("Additional exchange-specific parameters"), },
- src/tools/order-tools.ts:18-99 (registration)Registration of the createOrder tool on the MCP server using server.tool()."createOrder", "Create a new order using a configured account", { accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"), type: z .enum(["market", "limit"]) .describe("Order type: 'market' or 'limit'"), side: z.enum(["buy", "sell"]).describe("Order side: 'buy' or 'sell'"), amount: z.number().describe("Amount of base currency to trade"), price: z .number() .optional() .describe("Price per unit (required for limit orders)"), params: z .record(z.any()) .optional() .describe("Additional exchange-specific parameters"), }, async ({ accountName, symbol, type, side, amount, price, params, }) => { try { const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 // 주문 유형이 limit인데 가격이 없는 경우 if (type === "limit" && price === undefined) { return { content: [ { type: "text", text: "Price is required for limit orders", }, ], isError: true, }; } const order = await exchange.createOrder( symbol, type, side, amount, price, params, ); return { content: [ { type: "text", text: JSON.stringify(order, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error creating order for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } }, );
- src/server.ts:373-373 (registration)Call to registerOrderTools which registers the createOrder tool among others.registerOrderTools(this.server, this);