Skip to main content
Glama

place_order

Execute cryptocurrency trades on Bybit exchange by submitting buy or sell orders with configurable parameters for market, limit, and conditional orders.

Instructions

Execute order

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
symbolYesSymbol (e.g., BTCUSDT)
sideYesOrder direction (Buy, Sell)
orderTypeYesOrder type (Market, Limit)
qtyYesOrder quantity
priceNoOrder price (for limit orders)
positionIdxNoPosition index (1: Long, 2: Short)
timeInForceNoTime in force (GTC, IOC, FOK, PostOnly)
orderLinkIdNoOrder link ID
isLeverageNoUse leverage (0: No, 1: Yes)
orderFilterNoOrder filter (Order, tpslOrder, StopOrder)
triggerPriceNoTrigger price
triggerByNoTrigger basis
orderIvNoOrder volatility
takeProfitNoTake profit price
stopLossNoStop loss price
tpTriggerByNoTake profit trigger basis
slTriggerByNoStop loss trigger basis
tpLimitPriceNoTake profit limit price
slLimitPriceNoStop loss limit price
tpOrderTypeNoTake profit order type (Market, Limit)
slOrderTypeNoStop loss order type (Market, Limit)

Implementation Reference

  • Core handler function that implements the place_order tool logic: auto-detects position mode for futures, validates parameters, sets defaults, and calls Bybit V5 order create API.
    async placeOrder(orderRequest: OrderRequest): Promise<BybitResponse<OrderResponse> | { error: string }> {
      // Auto-detect position mode for futures trading if positionIdx not provided
      if (['linear', 'inverse'].includes(orderRequest.category) && !orderRequest.positionIdx) {
        console.log('Auto-detecting position mode for futures trading...');
        
        // Check current positions to determine position mode
        const currentPositions = await this.getPositions(orderRequest.category, orderRequest.symbol);
        
        let detectedPositionIdx = '0'; // Default to one-way mode
        
        if ('result' in currentPositions && currentPositions.result.list.length > 0) {
          // Check if we have separate long/short positions (hedge mode)
          const positions = currentPositions.result.list;
          const hasLongPosition = positions.some(p => p.side === 'Buy');
          const hasShortPosition = positions.some(p => p.side === 'Sell');
          
          if (hasLongPosition || hasShortPosition) {
            // Hedge mode detected - use appropriate position index
            detectedPositionIdx = orderRequest.side === 'Buy' ? '1' : '2';
            console.log(`Hedge mode detected, using positionIdx: ${detectedPositionIdx}`);
          } else {
            console.log('One-way mode detected, using positionIdx: 0');
          }
        } else {
          console.log('No existing positions, defaulting to one-way mode (positionIdx: 0)');
        }
        
        // Set the detected position index
        orderRequest.positionIdx = detectedPositionIdx;
      }
      
      // Validate positionIdx for futures trading (after auto-detection)
      if (['linear', 'inverse'].includes(orderRequest.category)) {
        if (!orderRequest.positionIdx || !['0', '1', '2'].includes(orderRequest.positionIdx)) {
          return { error: 'Invalid positionIdx. Use 0 for one-way mode, 1 for long position, or 2 for short position in hedge mode' };
        }
      }
    
      // Set defaults
      const requestData = {
        ...orderRequest,
        timeInForce: orderRequest.timeInForce || (orderRequest.orderType === 'Market' ? 'IOC' : 'GTC'),
        orderFilter: orderRequest.orderFilter || 'Order',
        isLeverage: orderRequest.isLeverage || 0
      };
    
      // Remove positionIdx for spot trading
      if (orderRequest.category === 'spot') {
        delete requestData.positionIdx;
      }
    
      return this.makeBybitRequest('/v5/order/create', 'POST', requestData);
    }
  • src/index.ts:175-272 (registration)
    MCP tool registration for 'place_order' including name, description, and detailed input schema.
    {
      name: 'place_order',
      description: 'Execute order',
      inputSchema: {
        type: 'object',
        properties: {
          category: {
            type: 'string',
            description: 'Category (spot, linear, inverse, etc.)',
          },
          symbol: {
            type: 'string',
            description: 'Symbol (e.g., BTCUSDT)',
          },
          side: {
            type: 'string',
            description: 'Order direction (Buy, Sell)',
          },
          orderType: {
            type: 'string',
            description: 'Order type (Market, Limit)',
          },
          qty: {
            type: 'string',
            description: 'Order quantity',
          },
          price: {
            type: 'string',
            description: 'Order price (for limit orders)',
          },
          positionIdx: {
            type: 'string',
            description: 'Position index (1: Long, 2: Short)',
          },
          timeInForce: {
            type: 'string',
            description: 'Time in force (GTC, IOC, FOK, PostOnly)',
          },
          orderLinkId: {
            type: 'string',
            description: 'Order link ID',
          },
          isLeverage: {
            type: 'number',
            description: 'Use leverage (0: No, 1: Yes)',
          },
          orderFilter: {
            type: 'string',
            description: 'Order filter (Order, tpslOrder, StopOrder)',
          },
          triggerPrice: {
            type: 'string',
            description: 'Trigger price',
          },
          triggerBy: {
            type: 'string',
            description: 'Trigger basis',
          },
          orderIv: {
            type: 'string',
            description: 'Order volatility',
          },
          takeProfit: {
            type: 'string',
            description: 'Take profit price',
          },
          stopLoss: {
            type: 'string',
            description: 'Stop loss price',
          },
          tpTriggerBy: {
            type: 'string',
            description: 'Take profit trigger basis',
          },
          slTriggerBy: {
            type: 'string',
            description: 'Stop loss trigger basis',
          },
          tpLimitPrice: {
            type: 'string',
            description: 'Take profit limit price',
          },
          slLimitPrice: {
            type: 'string',
            description: 'Stop loss limit price',
          },
          tpOrderType: {
            type: 'string',
            description: 'Take profit order type (Market, Limit)',
          },
          slOrderType: {
            type: 'string',
            description: 'Stop loss order type (Market, Limit)',
          },
        },
        required: ['category', 'symbol', 'side', 'orderType', 'qty'],
      },
    },
  • MCP server request handler switch case that maps input arguments to OrderRequest and delegates to BybitService.placeOrder.
    case 'place_order': {
      const orderRequest: OrderRequest = {
        category: typedArgs.category,
        symbol: typedArgs.symbol,
        side: typedArgs.side,
        orderType: typedArgs.orderType,
        qty: typedArgs.qty,
        price: typedArgs.price,
        timeInForce: typedArgs.timeInForce,
        orderLinkId: typedArgs.orderLinkId,
        isLeverage: typedArgs.isLeverage,
        orderFilter: typedArgs.orderFilter,
        triggerPrice: typedArgs.triggerPrice,
        triggerBy: typedArgs.triggerBy,
        orderIv: typedArgs.orderIv,
        positionIdx: typedArgs.positionIdx,
        takeProfit: typedArgs.takeProfit,
        stopLoss: typedArgs.stopLoss,
        tpTriggerBy: typedArgs.tpTriggerBy,
        slTriggerBy: typedArgs.slTriggerBy,
        tpLimitPrice: typedArgs.tpLimitPrice,
        slLimitPrice: typedArgs.slLimitPrice,
        tpOrderType: typedArgs.tpOrderType,
        slOrderType: typedArgs.slOrderType,
      };
    
      const result = await this.bybitService.placeOrder(orderRequest);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • TypeScript interface definition for OrderRequest used in place_order implementation for type safety and validation.
    export interface OrderRequest {
      category: string;
      symbol: string;
      side: 'Buy' | 'Sell';
      orderType: 'Market' | 'Limit';
      qty: string;
      price?: string;
      timeInForce?: 'GTC' | 'IOC' | 'FOK' | 'PostOnly';
      orderLinkId?: string;
      isLeverage?: number;
      orderFilter?: 'Order' | 'tpslOrder' | 'StopOrder';
      triggerPrice?: string;
      triggerBy?: string;
      orderIv?: string;
      positionIdx?: string;
      takeProfit?: string;
      stopLoss?: string;
      tpTriggerBy?: string;
      slTriggerBy?: string;
      tpLimitPrice?: string;
      slLimitPrice?: string;
      tpOrderType?: 'Market' | 'Limit';
      slOrderType?: 'Market' | 'Limit';
    }
  • Helper logic within placeOrder for automatic positionIdx detection using current positions to support hedge/one-way modes.
    if (['linear', 'inverse'].includes(orderRequest.category) && !orderRequest.positionIdx) {
      console.log('Auto-detecting position mode for futures trading...');
      
      // Check current positions to determine position mode
      const currentPositions = await this.getPositions(orderRequest.category, orderRequest.symbol);
      
      let detectedPositionIdx = '0'; // Default to one-way mode
      
      if ('result' in currentPositions && currentPositions.result.list.length > 0) {
        // Check if we have separate long/short positions (hedge mode)
        const positions = currentPositions.result.list;
        const hasLongPosition = positions.some(p => p.side === 'Buy');
        const hasShortPosition = positions.some(p => p.side === 'Sell');
        
        if (hasLongPosition || hasShortPosition) {
          // Hedge mode detected - use appropriate position index
          detectedPositionIdx = orderRequest.side === 'Buy' ? '1' : '2';
          console.log(`Hedge mode detected, using positionIdx: ${detectedPositionIdx}`);
        } else {
          console.log('One-way mode detected, using positionIdx: 0');
        }
      } else {
        console.log('No existing positions, defaulting to one-way mode (positionIdx: 0)');
      }
      
      // Set the detected position index
      orderRequest.positionIdx = detectedPositionIdx;
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but fails completely. 'Execute order' implies a potentially destructive financial transaction but doesn't disclose critical behavioral traits: whether this commits real funds, requires authentication, has rate limits, returns confirmation details, or what happens on failure. For a 22-parameter trading tool, this is dangerously inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

While technically concise with just two words, this is under-specification rather than effective conciseness. The description fails to front-load essential information and doesn't earn its place - it provides no value beyond the tool name itself. For a complex trading tool, this brevity is harmful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex trading order placement tool with 22 parameters, no annotations, and no output schema, the description is completely inadequate. It doesn't explain what the tool does beyond the obvious, provides no behavioral context, no usage guidance, and no information about return values or error conditions. This leaves the agent dangerously uninformed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 22 parameters thoroughly. The description adds zero parameter information beyond what's in the schema. According to scoring rules, with high schema coverage (>80%), the baseline is 3 even with no param info in description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Execute order' is a tautology that merely restates the tool name 'place_order' without adding meaningful context. It doesn't specify what type of order (trading order), what resource is affected (trading positions), or distinguish it from sibling tools like 'place_order_with_trailing_stop' or 'cancel_order'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides absolutely no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, appropriate contexts, or differentiate from related tools like 'place_order_with_trailing_stop' for trailing stop orders or 'validate_order_quantity' for validation before execution.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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