Skip to main content
Glama

validate_order_quantity

Validate cryptocurrency order quantities against Bybit exchange trading rules to ensure compliance and proper formatting before execution.

Instructions

Validate order quantity against Bybit trading rules and get properly formatted quantity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
symbolYesSymbol (e.g., BTCUSDT)
targetAmountYesTarget amount in quote currency (e.g., 80 for $80 worth)
currentPriceNoCurrent price (optional, will fetch if not provided)

Implementation Reference

  • Core handler function that fetches current price and instrument information, validates and adjusts order quantity according to Bybit's lot size rules (min/max/step), and returns formatted validated quantity with estimated cost.
    async validateOrderQuantity(
      category: string,
      symbol: string,
      targetAmount: number,
      currentPrice?: number
    ): Promise<{ 
      isValid: boolean; 
      validatedQty: string; 
      estimatedCost: string; 
      adjustments: string[];
      error?: string;
    }> {
      try {
        // Get current price if not provided
        let price = currentPrice;
        if (!price) {
          const ticker = await this.getTickers(category, symbol);
          if ('error' in ticker) {
            return { 
              isValid: false, 
              validatedQty: '0', 
              estimatedCost: '0', 
              adjustments: [],
              error: `Failed to get price: ${ticker.error}` 
            };
          }
          price = parseFloat(ticker.result.list[0].lastPrice);
        }
    
        // Get instrument info
        const instrumentInfo = await this.getInstrumentsInfo(category, symbol);
        if ('error' in instrumentInfo) {
          return { 
            isValid: false, 
            validatedQty: '0', 
            estimatedCost: '0', 
            adjustments: [],
            error: `Failed to get instrument info: ${instrumentInfo.error}` 
          };
        }
    
        const instrument = instrumentInfo.result.list[0];
        const lotSizeFilter = instrument.lotSizeFilter;
        const minOrderQty = parseFloat(lotSizeFilter.minOrderQty);
        const maxOrderQty = parseFloat(lotSizeFilter.maxOrderQty);
        const qtyStep = parseFloat(lotSizeFilter.qtyStep);
    
        const adjustments: string[] = [];
        let rawOrderQty = targetAmount / price;
    
        // Round to the nearest valid quantity step
        let orderQty = Math.round(rawOrderQty / qtyStep) * qtyStep;
    
        // Ensure it meets minimum requirements
        if (orderQty < minOrderQty) {
          orderQty = minOrderQty;
          adjustments.push(`Adjusted to minimum quantity: ${orderQty}`);
        }
    
        // Ensure it doesn't exceed maximum
        if (orderQty > maxOrderQty) {
          orderQty = maxOrderQty;
          adjustments.push(`Adjusted to maximum quantity: ${orderQty}`);
        }
    
        // Format to the correct decimal places based on qtyStep
        const decimalPlaces = qtyStep.toString().split('.')[1]?.length || 0;
        const validatedQty = orderQty.toFixed(decimalPlaces);
        const estimatedCost = (orderQty * price).toFixed(2);
    
        return {
          isValid: true,
          validatedQty,
          estimatedCost,
          adjustments,
        };
    
      } catch (error: any) {
        return { 
          isValid: false, 
          validatedQty: '0', 
          estimatedCost: '0', 
          adjustments: [],
          error: error.message 
        };
      }
    }
  • src/index.ts:483-508 (registration)
    MCP tool registration defining the tool name, description, and input schema for validate_order_quantity.
    {
      name: 'validate_order_quantity',
      description: 'Validate order quantity against Bybit trading rules and get properly formatted quantity',
      inputSchema: {
        type: 'object',
        properties: {
          category: {
            type: 'string',
            description: 'Category (spot, linear, inverse, etc.)',
          },
          symbol: {
            type: 'string',
            description: 'Symbol (e.g., BTCUSDT)',
          },
          targetAmount: {
            type: 'number',
            description: 'Target amount in quote currency (e.g., 80 for $80 worth)',
          },
          currentPrice: {
            type: 'number',
            description: 'Current price (optional, will fetch if not provided)',
          },
        },
        required: ['category', 'symbol', 'targetAmount'],
      },
    },
  • Tool dispatch handler in the MCP server that calls the BybitService.validateOrderQuantity method and returns the result as text content.
    case 'validate_order_quantity': {
      const result = await this.bybitService.validateOrderQuantity(
        typedArgs.category,
        typedArgs.symbol,
        typedArgs.targetAmount,
        typedArgs.currentPrice
      );
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions validation and formatting but lacks details on what happens during validation (e.g., error messages, rule checks), whether it's read-only or has side effects, rate limits, or authentication needs. This is a significant gap for a tool with no annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. Every part of the sentence earns its place by clearly stating the tool's function, making it highly concise and well-structured.

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

Completeness2/5

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

Given the complexity of a validation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., validated quantity, error details), behavioral traits, or usage context, leaving gaps that could hinder an agent's ability to use it effectively.

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?

The schema description coverage is 100%, so the schema already documents all parameters. The description adds no additional meaning beyond what's in the schema (e.g., it doesn't explain how 'targetAmount' relates to validation or formatting). With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Validate order quantity against Bybit trading rules and get properly formatted quantity.' It specifies the action (validate), the resource (order quantity), and the context (Bybit trading rules). However, it doesn't explicitly differentiate from sibling tools like 'place_order' or 'calculate_position_size' that might also involve quantity handling, which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., before placing an order), exclusions, or comparisons to siblings like 'calculate_position_size' or 'place_order', leaving the agent to infer usage context without explicit direction.

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