Skip to main content
Glama

detect_position_mode

Identify current position mode (one-way or hedge) and determine optimal positionIdx for orders on Bybit. Specify category and optional symbol to validate settings accurately.

Instructions

Detect current position mode (one-way vs hedge) and get recommended positionIdx for orders

Input Schema

NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
symbolNoSymbol (e.g., ETHUSDT) - optional, will check all positions if not provided

Input Schema (JSON Schema)

{ "properties": { "category": { "description": "Category (spot, linear, inverse, etc.)", "type": "string" }, "symbol": { "description": "Symbol (e.g., ETHUSDT) - optional, will check all positions if not provided", "type": "string" } }, "required": [ "category" ], "type": "object" }

Implementation Reference

  • Core handler function that detects the current position mode (one-way or hedge) by analyzing existing positions and recommends the appropriate positionIdx for new orders.
    async detectPositionMode( category: string, symbol?: string ): Promise<{ positionMode: 'one-way' | 'hedge'; recommendedPositionIdx: string; explanation: string; currentPositions: any[]; }> { try { // Get current positions const currentPositions = await this.getPositions(category, symbol); if ('error' in currentPositions) { return { positionMode: 'one-way', recommendedPositionIdx: '0', explanation: `Could not check positions: ${currentPositions.error}. Defaulting to one-way mode.`, currentPositions: [] }; } const positions = currentPositions.result.list; if (positions.length === 0) { return { positionMode: 'one-way', recommendedPositionIdx: '0', explanation: 'No existing positions found. Defaulting to one-way mode (positionIdx: 0).', currentPositions: [] }; } // Check if we have separate long/short positions (hedge mode) const hasLongPosition = positions.some(p => p.side === 'Buy' && parseFloat(p.size) > 0); const hasShortPosition = positions.some(p => p.side === 'Sell' && parseFloat(p.size) > 0); if (hasLongPosition && hasShortPosition) { return { positionMode: 'hedge', recommendedPositionIdx: '1', // Default to long for new orders explanation: 'Hedge mode detected (both long and short positions exist). Use positionIdx: 1 for long, 2 for short.', currentPositions: positions }; } else if (hasLongPosition || hasShortPosition) { // Check if positions have positionIdx > 0 (indicating hedge mode setup) const hasHedgePositions = positions.some(p => p.positionIdx > 0); if (hasHedgePositions) { return { positionMode: 'hedge', recommendedPositionIdx: '1', explanation: 'Hedge mode detected (positions have positionIdx > 0). Use positionIdx: 1 for long, 2 for short.', currentPositions: positions }; } else { return { positionMode: 'one-way', recommendedPositionIdx: '0', explanation: 'One-way mode detected (single position type with positionIdx: 0).', currentPositions: positions }; } } else { return { positionMode: 'one-way', recommendedPositionIdx: '0', explanation: 'One-way mode detected (no active positions, but account configured for one-way).', currentPositions: positions }; } } catch (error: any) { return { positionMode: 'one-way', recommendedPositionIdx: '0', explanation: `Error detecting position mode: ${error.message}. Defaulting to one-way mode.`, currentPositions: [] }; } }
  • src/index.ts:509-526 (registration)
    Tool registration in the MCP server's tools array, defining the name, description, and input schema for validation.
    { name: 'detect_position_mode', description: 'Detect current position mode (one-way vs hedge) and get recommended positionIdx for orders', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Category (spot, linear, inverse, etc.)', }, symbol: { type: 'string', description: 'Symbol (e.g., ETHUSDT) - optional, will check all positions if not provided', }, }, required: ['category'], }, },
  • MCP tool request handler that extracts arguments and delegates execution to BybitService.detectPositionMode, then formats the response.
    case 'detect_position_mode': { const result = await this.bybitService.detectPositionMode( typedArgs.category, typedArgs.symbol ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kondisettyravi/mcp-bybit-node'

If you have feedback or need assistance with the MCP directory API, please join our Discord server