+ "code": "/**\n * Example: Get futures contract size (quanto_multiplier) and convert between\n * notional (e.g. USDT) and order size in contracts.\n *\n * Gate.io futures orders use `size` = number of CONTRACTS, not currency amount.\n * The contract details endpoint returns `quanto_multiplier`: the amount of\n * underlying (e.g. BTC) that 1 contract represents. So:\n * notional_in_settle = size * quanto_multiplier * price\n * size = notional_in_settle / (quanto_multiplier * price)\n *\n * This example:\n * 1) Fetches contract with getFuturesContract\n * 2) Reads quanto_multiplier and derives \"contract size\" in quote currency\n * 3) Converts a desired notional (e.g. 1000 USDT) to order size in contracts\n */\n\nimport { RestClient } from 'gateio-api';\n\nconst client = new RestClient({\n apiKey: process.env.API_KEY || 'your_api_key',\n apiSecret: process.env.API_SECRET || 'your_api_secret',\n});\n\nconst SETTLE = 'usdt';\nconst CONTRACT = 'BTC_USDT';\n\nasync function getContractSizeExample() {\n // 1) Get single contract (public, no auth required)\n const contract = await client.getFuturesContract({\n settle: SETTLE,\n contract: CONTRACT,\n });\n\n const quantoMult = contract.quanto_multiplier;\n const markPrice = contract.mark_price;\n const orderSizeMin = Number(contract.order_size_min ?? 1);\n const orderSizeMax =\n contract.order_size_max != null ? Number(contract.order_size_max) : null;\n const enableDecimal = contract.enable_decimal ?? false;\n\n if (!quantoMult || !markPrice) {\n throw new Error('Contract missing quanto_multiplier or mark_price');\n }\n\n const q = Number(quantoMult);\n const p = Number(markPrice);\n\n // 2) Contract size in quote (settle) currency: 1 contract = q * p\n const notionalPerContract = q * p;\n console.log('Contract:', CONTRACT);\n console.log('quanto_multiplier (underlying per 1 contract):', quantoMult);\n console.log('mark_price:', markPrice);\n console.log('Notional per 1 contract (quote):', notionalPerContract);\n console.log(\n 'order_size_min:',\n orderSizeMin,\n 'order_size_max:',\n orderSizeMax,\n 'enable_decimal:',\n enableDecimal,\n );\n\n // 3) Convert desired notional (e.g. 1000 USDT) to size in contracts\n const desiredNotionalUsdt = 1000;\n let size = desiredNotionalUsdt / notionalPerContract;\n\n if (!enableDecimal) {\n size = Math.floor(size);\n }\n size = Math.max(orderSizeMin, size);\n if (orderSizeMax != null) {\n size = Math.min(orderSizeMax, size);\n }\n\n console.log('\\nDesired notional (USDT):', desiredNotionalUsdt);\n console.log('Computed size (contracts):', size);\n console.log(\n 'Actual notional (size * quanto_multiplier * mark_price):',\n size * q * p,\n );\n\n // Example: you would pass this size to submitFuturesOrder\n // await client.submitFuturesOrder({\n // settle: SETTLE,\n // contract: CONTRACT,\n // size: size, // in contracts; positive = long, negative = short\n // price: markPrice,\n // tif: 'gtc',\n // });\n}\n\ngetContractSizeExample().catch(console.error);\n",
0 commit comments