set-margin-mode
Configure futures trading margin mode (cross or isolated) on supported exchanges using the CCXT MCP Server. Specify exchange, symbol, and API credentials for precise margin management.
Instructions
Set margin mode for futures trading
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | Yes | API key for authentication | |
| exchange | Yes | Exchange ID (e.g., binance, bybit) | |
| marginMode | Yes | Margin mode: cross or isolated | |
| marketType | No | Market type (default: future) | future |
| passphrase | No | Passphrase for authentication (required for some exchanges like KuCoin) | |
| secret | Yes | API secret for authentication | |
| symbol | Yes | Trading pair symbol (e.g., BTC/USDT) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"apiKey": {
"description": "API key for authentication",
"type": "string"
},
"exchange": {
"description": "Exchange ID (e.g., binance, bybit)",
"type": "string"
},
"marginMode": {
"description": "Margin mode: cross or isolated",
"enum": [
"cross",
"isolated"
],
"type": "string"
},
"marketType": {
"default": "future",
"description": "Market type (default: future)",
"enum": [
"future",
"swap"
],
"type": "string"
},
"passphrase": {
"description": "Passphrase for authentication (required for some exchanges like KuCoin)",
"type": "string"
},
"secret": {
"description": "API secret for authentication",
"type": "string"
},
"symbol": {
"description": "Trading pair symbol (e.g., BTC/USDT)",
"type": "string"
}
},
"required": [
"exchange",
"symbol",
"marginMode",
"apiKey",
"secret"
],
"type": "object"
}
Implementation Reference
- src/tools/private.ts:149-176 (handler)Handler function that implements the 'set-margin-mode' tool. It authenticates with the exchange using provided credentials, applies rate limiting, logs the action, calls setMarginMode on the CCXT exchange instance for the specified symbol, and returns the result or error response.}, async ({ exchange, symbol, marginMode, apiKey, secret, passphrase, marketType }) => { try { return await rateLimiter.execute(exchange, async () => { // Get futures exchange const ex = getExchangeWithCredentials(exchange, apiKey, secret, marketType, passphrase); // Set margin mode log(LogLevel.INFO, `Setting margin mode to ${marginMode} for ${symbol} on ${exchange} (${marketType})`); const result = await ex.setMarginMode(marginMode, symbol); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error setting margin mode: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });
- src/tools/private.ts:142-148 (schema)Zod input schema defining parameters for the 'set-margin-mode' tool: exchange, symbol, marginMode (cross/isolated), credentials, and marketType.exchange: z.string().describe("Exchange ID (e.g., binance, bybit)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), marginMode: z.enum(["cross", "isolated"]).describe("Margin mode: cross or isolated"), apiKey: z.string().describe("API key for authentication"), secret: z.string().describe("API secret for authentication"), passphrase: z.string().optional().describe("Passphrase for authentication (required for some exchanges like KuCoin)"), marketType: z.enum(["future", "swap"]).default("future").describe("Market type (default: future)")
- src/tools/private.ts:141-176 (registration)Registration of the 'set-margin-mode' tool using server.tool(), providing name, description, input schema, and inline handler function within registerPrivateTools.server.tool("set-margin-mode", "Set margin mode for futures trading", { exchange: z.string().describe("Exchange ID (e.g., binance, bybit)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), marginMode: z.enum(["cross", "isolated"]).describe("Margin mode: cross or isolated"), apiKey: z.string().describe("API key for authentication"), secret: z.string().describe("API secret for authentication"), passphrase: z.string().optional().describe("Passphrase for authentication (required for some exchanges like KuCoin)"), marketType: z.enum(["future", "swap"]).default("future").describe("Market type (default: future)") }, async ({ exchange, symbol, marginMode, apiKey, secret, passphrase, marketType }) => { try { return await rateLimiter.execute(exchange, async () => { // Get futures exchange const ex = getExchangeWithCredentials(exchange, apiKey, secret, marketType, passphrase); // Set margin mode log(LogLevel.INFO, `Setting margin mode to ${marginMode} for ${symbol} on ${exchange} (${marketType})`); const result = await ex.setMarginMode(marginMode, symbol); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error setting margin mode: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });