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), }, ], };

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