set_trading_stop
Configure stop-loss and take-profit orders to manage risk and secure profits on Bybit cryptocurrency trades.
Instructions
Set trading stop
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Category (spot, linear, inverse, etc.) | |
| symbol | Yes | Symbol (e.g., BTCUSDT) | |
| takeProfit | No | Take profit price | |
| stopLoss | No | Stop loss price | |
| trailingStop | No | Trailing stop | |
| positionIdx | No | Position index |
Implementation Reference
- src/bybit-service.ts:397-411 (handler)Core implementation of the setTradingStop function that prepares parameters and makes authenticated POST request to Bybit's /v5/position/trading-stop endpoint to set take profit, stop loss, and/or trailing stop.async setTradingStop( category: string, symbol: string, takeProfit?: string, stopLoss?: string, trailingStop?: string, positionIdx?: number ): Promise<BybitResponse<any> | { error: string }> { const params: any = { category, symbol }; if (takeProfit) params.takeProfit = takeProfit; if (stopLoss) params.stopLoss = stopLoss; if (trailingStop) params.trailingStop = trailingStop; if (positionIdx !== undefined) params.positionIdx = positionIdx; return this.makeBybitRequest('/v5/position/trading-stop', 'POST', params); }
- src/index.ts:385-418 (registration)MCP tool registration entry in the server's listTools response, defining the tool name, description, and input schema.{ name: 'set_trading_stop', description: 'Set trading stop', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Category (spot, linear, inverse, etc.)', }, symbol: { type: 'string', description: 'Symbol (e.g., BTCUSDT)', }, takeProfit: { type: 'string', description: 'Take profit price', }, stopLoss: { type: 'string', description: 'Stop loss price', }, trailingStop: { type: 'string', description: 'Trailing stop', }, positionIdx: { type: 'number', description: 'Position index', }, }, required: ['category', 'symbol'], }, },
- src/index.ts:388-417 (schema)Input schema/parameter validation definition for the set_trading_stop tool.inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Category (spot, linear, inverse, etc.)', }, symbol: { type: 'string', description: 'Symbol (e.g., BTCUSDT)', }, takeProfit: { type: 'string', description: 'Take profit price', }, stopLoss: { type: 'string', description: 'Stop loss price', }, trailingStop: { type: 'string', description: 'Trailing stop', }, positionIdx: { type: 'number', description: 'Position index', }, }, required: ['category', 'symbol'], },
- src/index.ts:889-906 (handler)MCP server dispatch handler that receives tool call parameters and delegates to BybitService.setTradingStop, returning the result as MCP content.case 'set_trading_stop': { const result = await this.bybitService.setTradingStop( typedArgs.category, typedArgs.symbol, typedArgs.takeProfit, typedArgs.stopLoss, typedArgs.trailingStop, typedArgs.positionIdx ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }