Skip to content

Commit f2cd334

Browse files
committed
chore(): update package dependencies and add example for fetching futures contract size
1 parent fa14315 commit f2cd334

4 files changed

Lines changed: 57 additions & 46 deletions

File tree

package-lock.json

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
},
4444
"dependencies": {
4545
"@siebly/kraken-api": "^1.0.4",
46-
"binance": "^3.3.1",
47-
"bitget-api": "^3.1.3",
48-
"bitmart-api": "^2.3.2",
49-
"bybit-api": "^4.5.2",
50-
"coinbase-api": "^1.1.10",
51-
"gateio-api": "^1.4.1",
46+
"binance": "^3.3.3",
47+
"bitget-api": "^3.1.4",
48+
"bitmart-api": "^2.3.3",
49+
"bybit-api": "^4.5.3",
50+
"coinbase-api": "^1.1.11",
51+
"gateio-api": "^1.4.2",
5252
"https-proxy-agent": "latest",
53-
"kucoin-api": "^2.4.1",
54-
"okx-api": "^3.1.1",
53+
"kucoin-api": "^2.5.0",
54+
"okx-api": "^3.1.2",
5555
"socks-proxy-agent": "^8.0.5"
5656
}
5757
}

public/examples-index.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,13 @@
11031103
"code": "import { RestClient } from 'gateio-api';\n\n// Define the account object with API key and secret\nconst account = {\n key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key\n secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret\n};\n\n// Initialize the RestClient with the API credentials\nconst gateRestClient = new RestClient({\n apiKey: account.key,\n apiSecret: account.secret,\n});\n\nasync function getFuturesBalances() {\n try {\n console.log('Using API keys:', account);\n\n // Fetch the futures account balance for USDT settlement\n const result = await gateRestClient.getFuturesAccount({ settle: 'usdt' });\n\n console.log('Response: ', result); // Log the response to the console\n } catch (e) {\n console.error('Error in execution: ', e); // Log any errors that occur\n }\n}\n\n// Execute the function to get futures balances\ngetFuturesBalances();\n",
11041104
"metadata": {}
11051105
},
1106+
{
1107+
"type": "file",
1108+
"name": "getContractSize.ts",
1109+
"path": "examples/Gate/Rest/futures/getContractSize.ts",
1110+
"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",
1111+
"metadata": {}
1112+
},
11061113
{
11071114
"type": "file",
11081115
"name": "getOrders.ts",

scripts/build-examples.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ async function buildFileTree(basePath: string): Promise<ExampleFolder> {
2828
const files: string[] = glob.sync(`${basePath}/**/*.ts`);
2929
const tree: ExampleFolder = {
3030
type: 'folder',
31-
name: basePath,
32-
path: basePath,
31+
name: 'examples',
32+
path: 'examples',
3333
children: [],
3434
};
3535

3636
for (const filePath of files) {
37-
const parts = filePath.split('/');
37+
// Get relative path from basePath (examples directory)
38+
const relativePath = path.relative(basePath, filePath);
39+
const parts = relativePath.split(path.sep);
3840
let current = tree;
3941

4042
// Create folder structure
41-
for (let i = 1; i < parts.length - 1; i++) {
43+
for (let i = 0; i < parts.length - 1; i++) {
4244
let folder = current.children.find(
4345
(child) => child.type === 'folder' && child.name === parts[i],
4446
) as ExampleFolder;
4547

4648
if (!folder) {
49+
const folderPath = path.join('examples', ...parts.slice(0, i + 1));
4750
folder = {
4851
type: 'folder',
4952
name: parts[i],
50-
path: parts.slice(0, i + 1).join('/'),
53+
path: folderPath.replace(/\\/g, '/'), // Normalize to forward slashes
5154
children: [],
5255
};
5356
current.children.push(folder);
@@ -67,10 +70,11 @@ async function buildFileTree(basePath: string): Promise<ExampleFolder> {
6770
{},
6871
) || {};
6972

73+
const fileRelativePath = path.join('examples', relativePath);
7074
current.children.push({
7175
type: 'file',
7276
name: parts[parts.length - 1],
73-
path: filePath,
77+
path: fileRelativePath.replace(/\\/g, '/'), // Normalize to forward slashes
7478
code: content,
7579
metadata: {
7680
title: metadata.title,

0 commit comments

Comments
 (0)