set_trading_stop
Define and manage stop-loss, take-profit, and trailing stop orders for cryptocurrency trading on Bybit. Specify category, symbol, and price levels to automate risk management and optimize trade outcomes.
Instructions
Set trading stop
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Category (spot, linear, inverse, etc.) | |
| positionIdx | No | Position index | |
| stopLoss | No | Stop loss price | |
| symbol | Yes | Symbol (e.g., BTCUSDT) | |
| takeProfit | No | Take profit price | |
| trailingStop | No | Trailing stop |
Implementation Reference
- src/bybit-service.ts:397-411 (handler)Core handler implementation that sets trading stops (TP/SL/trailing stop) by calling Bybit API endpoint /v5/position/trading-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:889-906 (handler)MCP CallToolRequest handler that dispatches 'set_trading_stop' tool calls to the BybitService.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), }, ], }; }
- src/index.ts:385-418 (registration)Tool registration in MCP server's ListTools response, including name, description, and input schema validation.{ 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 for validating parameters of 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'], },