Skip to main content
Glama

validate_order_quantity

Ensure orders comply with Bybit trading rules by validating and formatting order quantities based on category, symbol, and target amount for accurate trade execution.

Instructions

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

Input Schema

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

Implementation Reference

  • Core handler function that validates order quantity: fetches ticker and instrument info, calculates quantity from target amount, adjusts to exchange lot size rules (min, max, step), formats correctly, returns validated qty, cost, and adjustments.
    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 }; } }
  • JSON Schema defining the input parameters for the validate_order_quantity tool.
    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'], },
  • src/index.ts:955-970 (registration)
    Tool handler registration in the MCP switch statement that dispatches calls to the BybitService.validateOrderQuantity method.
    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), }, ], }; }
  • src/index.ts:483-508 (registration)
    Tool registration in the ListTools response, including name, description, and schema.
    { 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'], }, },

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