@okx_ai/okx-trade-cli 1.2.4-beta.2 → 1.2.4-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1367,6 +1367,14 @@ function normalizeResponse(response) {
1367
1367
  data: response.data
1368
1368
  };
1369
1369
  }
1370
+ function buildAttachAlgoOrds(source) {
1371
+ const tpTriggerPx = readString(source, "tpTriggerPx");
1372
+ const tpOrdPx = readString(source, "tpOrdPx");
1373
+ const slTriggerPx = readString(source, "slTriggerPx");
1374
+ const slOrdPx = readString(source, "slOrdPx");
1375
+ const entry = compactObject({ tpTriggerPx, tpOrdPx, slTriggerPx, slOrdPx });
1376
+ return Object.keys(entry).length > 0 ? [entry] : void 0;
1377
+ }
1370
1378
  var OKX_CANDLE_BARS = [
1371
1379
  "1m",
1372
1380
  "3m",
@@ -1414,19 +1422,12 @@ function assertNotDemo(config, endpoint) {
1414
1422
  );
1415
1423
  }
1416
1424
  }
1417
- function normalize(response) {
1418
- return {
1419
- endpoint: response.endpoint,
1420
- requestTime: response.requestTime,
1421
- data: response.data
1422
- };
1423
- }
1424
1425
  function registerAccountTools() {
1425
1426
  return [
1426
1427
  {
1427
1428
  name: "account_get_balance",
1428
1429
  module: "account",
1429
- description: "Get account balance for trading account. Returns balances for all currencies or a specific one. Private endpoint. Rate limit: 10 req/s.",
1430
+ description: "Get account balance for trading account. Returns balances for all currencies or a specific one.",
1430
1431
  isWrite: false,
1431
1432
  inputSchema: {
1432
1433
  type: "object",
@@ -1444,13 +1445,13 @@ function registerAccountTools() {
1444
1445
  compactObject({ ccy: readString(args, "ccy") }),
1445
1446
  privateRateLimit("account_get_balance", 10)
1446
1447
  );
1447
- return normalize(response);
1448
+ return normalizeResponse(response);
1448
1449
  }
1449
1450
  },
1450
1451
  {
1451
1452
  name: "account_transfer",
1452
1453
  module: "account",
1453
- description: "Transfer funds between accounts (trading, funding, etc.). [CAUTION] Moves real funds. Private endpoint. Rate limit: 2 req/s.",
1454
+ description: "Transfer funds between accounts (trading, funding, etc.). [CAUTION] Moves real funds.",
1454
1455
  isWrite: true,
1455
1456
  inputSchema: {
1456
1457
  type: "object",
@@ -1501,13 +1502,13 @@ function registerAccountTools() {
1501
1502
  }),
1502
1503
  privateRateLimit("account_transfer", 2)
1503
1504
  );
1504
- return normalize(response);
1505
+ return normalizeResponse(response);
1505
1506
  }
1506
1507
  },
1507
1508
  {
1508
1509
  name: "account_get_max_size",
1509
1510
  module: "account",
1510
- description: "Get max buy/sell order size for a SWAP/FUTURES instrument given current balance and leverage. Useful before placing orders. Private. Rate limit: 20 req/s.",
1511
+ description: "Get max buy/sell order size for a SWAP/FUTURES instrument given current balance and leverage. Useful before placing orders.",
1511
1512
  isWrite: false,
1512
1513
  inputSchema: {
1513
1514
  type: "object",
@@ -1548,13 +1549,13 @@ function registerAccountTools() {
1548
1549
  }),
1549
1550
  privateRateLimit("account_get_max_size", 20)
1550
1551
  );
1551
- return normalize(response);
1552
+ return normalizeResponse(response);
1552
1553
  }
1553
1554
  },
1554
1555
  {
1555
1556
  name: "account_get_asset_balance",
1556
1557
  module: "account",
1557
- description: "Get funding account balance (asset account). Different from account_get_balance which queries the trading account. Private. Rate limit: 6 req/s.",
1558
+ description: "Get funding account balance (asset account). Different from account_get_balance which queries the trading account.",
1558
1559
  isWrite: false,
1559
1560
  inputSchema: {
1560
1561
  type: "object",
@@ -1572,13 +1573,13 @@ function registerAccountTools() {
1572
1573
  compactObject({ ccy: readString(args, "ccy") }),
1573
1574
  privateRateLimit("account_get_asset_balance", 6)
1574
1575
  );
1575
- return normalize(response);
1576
+ return normalizeResponse(response);
1576
1577
  }
1577
1578
  },
1578
1579
  {
1579
1580
  name: "account_get_bills",
1580
1581
  module: "account",
1581
- description: "Get account ledger: fees paid, funding charges, realized PnL, transfers, etc. Default 20 records (last 7 days), max 100. Private endpoint. Rate limit: 6 req/s.",
1582
+ description: "Get account ledger: fees paid, funding charges, realized PnL, transfers, etc. Default 20 records (last 7 days), max 100.",
1582
1583
  isWrite: false,
1583
1584
  inputSchema: {
1584
1585
  type: "object",
@@ -1638,13 +1639,13 @@ function registerAccountTools() {
1638
1639
  }),
1639
1640
  privateRateLimit("account_get_bills", 6)
1640
1641
  );
1641
- return normalize(response);
1642
+ return normalizeResponse(response);
1642
1643
  }
1643
1644
  },
1644
1645
  {
1645
1646
  name: "account_get_positions_history",
1646
1647
  module: "account",
1647
- description: "Get closed position history for SWAP or FUTURES. Default 20 records, max 100. Private endpoint. Rate limit: 1 req/s.",
1648
+ description: "Get closed position history for SWAP or FUTURES. Default 20 records, max 100.",
1648
1649
  isWrite: false,
1649
1650
  inputSchema: {
1650
1651
  type: "object",
@@ -1699,13 +1700,13 @@ function registerAccountTools() {
1699
1700
  }),
1700
1701
  privateRateLimit("account_get_positions_history", 1)
1701
1702
  );
1702
- return normalize(response);
1703
+ return normalizeResponse(response);
1703
1704
  }
1704
1705
  },
1705
1706
  {
1706
1707
  name: "account_get_trade_fee",
1707
1708
  module: "account",
1708
- description: "Get maker/taker fee rates for the account. Useful to understand your fee tier before trading. Private endpoint. Rate limit: 5 req/s.",
1709
+ description: "Get maker/taker fee rates for the account. Useful to understand your fee tier before trading.",
1709
1710
  isWrite: false,
1710
1711
  inputSchema: {
1711
1712
  type: "object",
@@ -1731,13 +1732,13 @@ function registerAccountTools() {
1731
1732
  }),
1732
1733
  privateRateLimit("account_get_trade_fee", 5)
1733
1734
  );
1734
- return normalize(response);
1735
+ return normalizeResponse(response);
1735
1736
  }
1736
1737
  },
1737
1738
  {
1738
1739
  name: "account_get_config",
1739
1740
  module: "account",
1740
- description: "Get account configuration: position mode (net vs hedge), account level, auto-loan settings, etc. Private endpoint. Rate limit: 5 req/s.",
1741
+ description: "Get account configuration: position mode (net vs hedge), account level, auto-loan settings, etc.",
1741
1742
  isWrite: false,
1742
1743
  inputSchema: {
1743
1744
  type: "object",
@@ -1749,13 +1750,13 @@ function registerAccountTools() {
1749
1750
  {},
1750
1751
  privateRateLimit("account_get_config", 5)
1751
1752
  );
1752
- return normalize(response);
1753
+ return normalizeResponse(response);
1753
1754
  }
1754
1755
  },
1755
1756
  {
1756
1757
  name: "account_get_max_withdrawal",
1757
1758
  module: "account",
1758
- description: "Get maximum withdrawable amount for a currency from the trading account. Useful before initiating a transfer or withdrawal. Private endpoint. Rate limit: 20 req/s.",
1759
+ description: "Get maximum withdrawable amount for a currency from the trading account. Useful before initiating a transfer or withdrawal.",
1759
1760
  isWrite: false,
1760
1761
  inputSchema: {
1761
1762
  type: "object",
@@ -1773,13 +1774,13 @@ function registerAccountTools() {
1773
1774
  compactObject({ ccy: readString(args, "ccy") }),
1774
1775
  privateRateLimit("account_get_max_withdrawal", 20)
1775
1776
  );
1776
- return normalize(response);
1777
+ return normalizeResponse(response);
1777
1778
  }
1778
1779
  },
1779
1780
  {
1780
1781
  name: "account_get_max_avail_size",
1781
1782
  module: "account",
1782
- description: "Get maximum available size for opening or reducing a position. Different from account_get_max_size which calculates new order size. Private endpoint. Rate limit: 20 req/s.",
1783
+ description: "Get maximum available size for opening or reducing a position. Different from account_get_max_size which calculates new order size.",
1783
1784
  isWrite: false,
1784
1785
  inputSchema: {
1785
1786
  type: "object",
@@ -1817,13 +1818,13 @@ function registerAccountTools() {
1817
1818
  }),
1818
1819
  privateRateLimit("account_get_max_avail_size", 20)
1819
1820
  );
1820
- return normalize(response);
1821
+ return normalizeResponse(response);
1821
1822
  }
1822
1823
  },
1823
1824
  {
1824
1825
  name: "account_get_positions",
1825
1826
  module: "account",
1826
- description: "Get current open positions across all instrument types (MARGIN, SWAP, FUTURES, OPTION). Use swap_get_positions for SWAP/FUTURES-only queries when the swap module is loaded. Private endpoint. Rate limit: 10 req/s.",
1827
+ description: "Get current open positions across all instrument types (MARGIN, SWAP, FUTURES, OPTION). Use swap_get_positions for SWAP/FUTURES-only queries.",
1827
1828
  isWrite: false,
1828
1829
  inputSchema: {
1829
1830
  type: "object",
@@ -1852,13 +1853,13 @@ function registerAccountTools() {
1852
1853
  }),
1853
1854
  privateRateLimit("account_get_positions", 10)
1854
1855
  );
1855
- return normalize(response);
1856
+ return normalizeResponse(response);
1856
1857
  }
1857
1858
  },
1858
1859
  {
1859
1860
  name: "account_get_bills_archive",
1860
1861
  module: "account",
1861
- description: "Get archived account ledger (bills older than 7 days, up to 3 months). Use account_get_bills for recent 7-day records. Default 20 records, max 100. Private endpoint. Rate limit: 6 req/s.",
1862
+ description: "Get archived account ledger (bills older than 7 days, up to 3 months). Use account_get_bills for recent 7-day records. Default 20 records, max 100.",
1862
1863
  isWrite: false,
1863
1864
  inputSchema: {
1864
1865
  type: "object",
@@ -1918,13 +1919,13 @@ function registerAccountTools() {
1918
1919
  }),
1919
1920
  privateRateLimit("account_get_bills_archive", 6)
1920
1921
  );
1921
- return normalize(response);
1922
+ return normalizeResponse(response);
1922
1923
  }
1923
1924
  },
1924
1925
  {
1925
1926
  name: "account_set_position_mode",
1926
1927
  module: "account",
1927
- description: "Switch between net position mode and long/short hedge mode. net: one position per instrument (default for most accounts). long_short_mode: separate long and short positions. [CAUTION] Requires no open positions or pending orders. Private endpoint. Rate limit: 5 req/s.",
1928
+ description: "Switch between net position mode and long/short hedge mode. net: one position per instrument (default). long_short_mode: separate long and short positions. [CAUTION] Requires no open positions or pending orders.",
1928
1929
  isWrite: true,
1929
1930
  inputSchema: {
1930
1931
  type: "object",
@@ -1944,24 +1945,17 @@ function registerAccountTools() {
1944
1945
  { posMode: requireString(args, "posMode") },
1945
1946
  privateRateLimit("account_set_position_mode", 5)
1946
1947
  );
1947
- return normalize(response);
1948
+ return normalizeResponse(response);
1948
1949
  }
1949
1950
  }
1950
1951
  ];
1951
1952
  }
1952
- function normalize2(response) {
1953
- return {
1954
- endpoint: response.endpoint,
1955
- requestTime: response.requestTime,
1956
- data: response.data
1957
- };
1958
- }
1959
1953
  function registerAlgoTradeTools() {
1960
1954
  return [
1961
1955
  {
1962
1956
  name: "swap_place_algo_order",
1963
1957
  module: "swap",
1964
- description: "Place a SWAP/FUTURES take-profit or stop-loss algo order. [CAUTION] Executes real trades. Use ordType='conditional' for a single TP, single SL, or combined TP+SL on one order. Use ordType='oco' (one-cancels-other) to place TP and SL simultaneously \u2014 whichever triggers first cancels the other. Set tpOrdPx='-1' or slOrdPx='-1' to execute the closing leg as a market order. Private endpoint. Rate limit: 20 req/s per UID.",
1958
+ description: "Place a SWAP/FUTURES algo order: TP/SL (conditional/oco) or trailing stop (move_order_stop). [CAUTION] Executes real trades. conditional: single TP, single SL, or both on one order. oco: TP+SL simultaneously \u2014 first trigger cancels the other. move_order_stop: provide callbackRatio (e.g. '0.01'=1%) OR callbackSpread, and optionally activePx. Set tpOrdPx='-1' or slOrdPx='-1' for market execution.",
1965
1959
  isWrite: true,
1966
1960
  inputSchema: {
1967
1961
  type: "object",
@@ -1987,8 +1981,8 @@ function registerAlgoTradeTools() {
1987
1981
  },
1988
1982
  ordType: {
1989
1983
  type: "string",
1990
- enum: ["conditional", "oco"],
1991
- description: "conditional=single TP/SL or both; oco=TP+SL pair (first trigger cancels other)"
1984
+ enum: ["conditional", "oco", "move_order_stop"],
1985
+ description: "conditional=single TP/SL or both; oco=TP+SL pair (first trigger cancels other); move_order_stop=trailing stop"
1992
1986
  },
1993
1987
  sz: {
1994
1988
  type: "string",
@@ -1996,29 +1990,41 @@ function registerAlgoTradeTools() {
1996
1990
  },
1997
1991
  tpTriggerPx: {
1998
1992
  type: "string",
1999
- description: "TP trigger price"
1993
+ description: "TP trigger price (conditional/oco only)"
2000
1994
  },
2001
1995
  tpOrdPx: {
2002
1996
  type: "string",
2003
- description: "TP order price; -1=market"
1997
+ description: "TP order price; -1=market (conditional/oco only)"
2004
1998
  },
2005
1999
  tpTriggerPxType: {
2006
2000
  type: "string",
2007
2001
  enum: ["last", "index", "mark"],
2008
- description: "last(default)|index|mark"
2002
+ description: "last(default)|index|mark (conditional/oco only)"
2009
2003
  },
2010
2004
  slTriggerPx: {
2011
2005
  type: "string",
2012
- description: "SL trigger price"
2006
+ description: "SL trigger price (conditional/oco only)"
2013
2007
  },
2014
2008
  slOrdPx: {
2015
2009
  type: "string",
2016
- description: "SL order price; -1=market (recommended)"
2010
+ description: "SL order price; -1=market (recommended) (conditional/oco only)"
2017
2011
  },
2018
2012
  slTriggerPxType: {
2019
2013
  type: "string",
2020
2014
  enum: ["last", "index", "mark"],
2021
- description: "last(default)|index|mark"
2015
+ description: "last(default)|index|mark (conditional/oco only)"
2016
+ },
2017
+ callbackRatio: {
2018
+ type: "string",
2019
+ description: "Callback ratio (e.g. '0.01'=1%); provide either ratio or spread (move_order_stop only)"
2020
+ },
2021
+ callbackSpread: {
2022
+ type: "string",
2023
+ description: "Callback spread in price units; provide either ratio or spread (move_order_stop only)"
2024
+ },
2025
+ activePx: {
2026
+ type: "string",
2027
+ description: "Activation price; tracking starts after market reaches this level (move_order_stop only)"
2022
2028
  },
2023
2029
  reduceOnly: {
2024
2030
  type: "boolean",
@@ -2049,19 +2055,22 @@ function registerAlgoTradeTools() {
2049
2055
  slTriggerPx: readString(args, "slTriggerPx"),
2050
2056
  slOrdPx: readString(args, "slOrdPx"),
2051
2057
  slTriggerPxType: readString(args, "slTriggerPxType"),
2058
+ callBackRatio: readString(args, "callbackRatio"),
2059
+ callBackSpread: readString(args, "callbackSpread"),
2060
+ activePx: readString(args, "activePx"),
2052
2061
  reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
2053
2062
  clOrdId: readString(args, "clOrdId"),
2054
2063
  tag: context.config.sourceTag
2055
2064
  }),
2056
2065
  privateRateLimit("swap_place_algo_order", 20)
2057
2066
  );
2058
- return normalize2(response);
2067
+ return normalizeResponse(response);
2059
2068
  }
2060
2069
  },
2061
2070
  {
2062
2071
  name: "swap_place_move_stop_order",
2063
2072
  module: "swap",
2064
- description: "Place a SWAP/FUTURES trailing stop order (move_order_stop). [CAUTION] Executes real trades. The order tracks the market price and triggers when the price reverses by the callback amount. Specify either callbackRatio (e.g. '0.01' for 1%) or callbackSpread (fixed price distance), not both. Optionally set activePx so tracking only starts once the market reaches that price. Private endpoint. Rate limit: 20 req/s per UID.",
2073
+ description: "[DEPRECATED] Use swap_place_algo_order with ordType='move_order_stop' instead. Place a SWAP/FUTURES trailing stop order. [CAUTION] Executes real trades. Specify callbackRatio (e.g. '0.01'=1%) or callbackSpread (fixed price distance), not both. Optionally set activePx so tracking starts once market reaches that price.",
2065
2074
  isWrite: true,
2066
2075
  inputSchema: {
2067
2076
  type: "object",
@@ -2124,21 +2133,21 @@ function registerAlgoTradeTools() {
2124
2133
  posSide: readString(args, "posSide"),
2125
2134
  ordType: "move_order_stop",
2126
2135
  sz: requireString(args, "sz"),
2127
- callbackRatio: readString(args, "callbackRatio"),
2128
- callbackSpread: readString(args, "callbackSpread"),
2136
+ callBackRatio: readString(args, "callbackRatio"),
2137
+ callBackSpread: readString(args, "callbackSpread"),
2129
2138
  activePx: readString(args, "activePx"),
2130
2139
  reduceOnly: typeof reduceOnly === "boolean" ? String(reduceOnly) : void 0,
2131
2140
  clOrdId: readString(args, "clOrdId")
2132
2141
  }),
2133
2142
  privateRateLimit("swap_place_move_stop_order", 20)
2134
2143
  );
2135
- return normalize2(response);
2144
+ return normalizeResponse(response);
2136
2145
  }
2137
2146
  },
2138
2147
  {
2139
2148
  name: "swap_cancel_algo_orders",
2140
2149
  module: "swap",
2141
- description: "Cancel one or more pending SWAP/FUTURES algo orders (TP/SL). Accepts a list of {algoId, instId} objects. Private endpoint. Rate limit: 20 req/s per UID.",
2150
+ description: "Cancel one or more pending SWAP/FUTURES algo orders (TP/SL). Accepts a list of {algoId, instId} objects.",
2142
2151
  isWrite: true,
2143
2152
  inputSchema: {
2144
2153
  type: "object",
@@ -2175,13 +2184,13 @@ function registerAlgoTradeTools() {
2175
2184
  orders,
2176
2185
  privateRateLimit("swap_cancel_algo_orders", 20)
2177
2186
  );
2178
- return normalize2(response);
2187
+ return normalizeResponse(response);
2179
2188
  }
2180
2189
  },
2181
2190
  {
2182
2191
  name: "swap_get_algo_orders",
2183
2192
  module: "swap",
2184
- description: "Query pending or completed SWAP/FUTURES algo orders (TP/SL, OCO, trailing stop). Private endpoint. Rate limit: 20 req/s.",
2193
+ description: "Query pending or completed SWAP/FUTURES algo orders (TP/SL, OCO, trailing stop).",
2185
2194
  isWrite: false,
2186
2195
  inputSchema: {
2187
2196
  type: "object",
@@ -2245,7 +2254,7 @@ function registerAlgoTradeTools() {
2245
2254
  { ...baseParams, ordType },
2246
2255
  privateRateLimit("swap_get_algo_orders", 20)
2247
2256
  );
2248
- return normalize2(response);
2257
+ return normalizeResponse(response);
2249
2258
  }
2250
2259
  const [r1, r2, r3] = await Promise.all([
2251
2260
  context.client.privateGet(path4, { ...baseParams, ordType: "conditional" }, privateRateLimit("swap_get_algo_orders", 20)),
@@ -2350,13 +2359,6 @@ function registerAuditTools() {
2350
2359
  }
2351
2360
  ];
2352
2361
  }
2353
- function normalize3(response) {
2354
- return {
2355
- endpoint: response.endpoint,
2356
- requestTime: response.requestTime,
2357
- data: response.data
2358
- };
2359
- }
2360
2362
  function normalizeWrite(response) {
2361
2363
  const data = response.data;
2362
2364
  if (Array.isArray(data) && data.length > 0) {
@@ -2384,7 +2386,7 @@ function registerGridTools() {
2384
2386
  {
2385
2387
  name: "grid_get_orders",
2386
2388
  module: "bot.grid",
2387
- description: "Query grid trading bot list. Use status='active' for running bots, status='history' for completed/stopped bots. Covers Spot Grid, Contract Grid, and Moon Grid. Private endpoint. Rate limit: 20 req/2s per UID.",
2389
+ description: "Query grid trading bot list. status='active' for running bots; status='history' for completed/stopped. Covers Spot Grid, Contract Grid, and Moon Grid.",
2388
2390
  isWrite: false,
2389
2391
  inputSchema: {
2390
2392
  type: "object",
@@ -2439,13 +2441,13 @@ function registerGridTools() {
2439
2441
  }),
2440
2442
  privateRateLimit("grid_get_orders", 20)
2441
2443
  );
2442
- return normalize3(response);
2444
+ return normalizeResponse(response);
2443
2445
  }
2444
2446
  },
2445
2447
  {
2446
2448
  name: "grid_get_order_details",
2447
2449
  module: "bot.grid",
2448
- description: "Query details of a single grid trading bot by its algo ID. Returns configuration, current status, PnL, and position info. Private endpoint. Rate limit: 20 req/2s per UID.",
2450
+ description: "Query details of a single grid trading bot by its algo ID. Returns configuration, current status, PnL, and position info.",
2449
2451
  isWrite: false,
2450
2452
  inputSchema: {
2451
2453
  type: "object",
@@ -2472,13 +2474,13 @@ function registerGridTools() {
2472
2474
  },
2473
2475
  privateRateLimit("grid_get_order_details", 20)
2474
2476
  );
2475
- return normalize3(response);
2477
+ return normalizeResponse(response);
2476
2478
  }
2477
2479
  },
2478
2480
  {
2479
2481
  name: "grid_get_sub_orders",
2480
2482
  module: "bot.grid",
2481
- description: "Query individual sub-orders (grid trades) generated by a grid bot. Use type='filled' for executed trades, type='live' for pending orders. Private endpoint. Rate limit: 20 req/2s per UID.",
2483
+ description: "Query individual sub-orders (grid trades) generated by a grid bot. type='filled' for executed trades; type='live' for pending orders.",
2482
2484
  isWrite: false,
2483
2485
  inputSchema: {
2484
2486
  type: "object",
@@ -2531,13 +2533,13 @@ function registerGridTools() {
2531
2533
  }),
2532
2534
  privateRateLimit("grid_get_sub_orders", 20)
2533
2535
  );
2534
- return normalize3(response);
2536
+ return normalizeResponse(response);
2535
2537
  }
2536
2538
  },
2537
2539
  {
2538
2540
  name: "grid_create_order",
2539
2541
  module: "bot.grid",
2540
- description: "Create a new grid trading bot. [CAUTION] Executes real trades and locks funds. Supports Spot Grid ('grid') and Contract Grid ('contract_grid'). For spot grid, provide quoteSz (invest in quote currency) or baseSz (invest in base currency). For contract grids, provide direction, lever, and sz (investment amount in margin currency, e.g. USDT for USDT-margined contracts). Private endpoint. Rate limit: 20 req/2s per UID.",
2542
+ description: "Create a new grid trading bot. [CAUTION] Executes real trades and locks funds. Supports Spot Grid ('grid') and Contract Grid ('contract_grid'). For spot: provide quoteSz or baseSz. For contract: provide direction, lever, and sz.",
2541
2543
  isWrite: true,
2542
2544
  inputSchema: {
2543
2545
  type: "object",
@@ -2628,7 +2630,7 @@ function registerGridTools() {
2628
2630
  {
2629
2631
  name: "grid_stop_order",
2630
2632
  module: "bot.grid",
2631
- description: "Stop a running grid trading bot. [CAUTION] This will close or cancel the bot's orders. For contract grids, stopType controls whether open positions are closed ('1') or only orders are cancelled ('2'). Private endpoint. Rate limit: 20 req/2s per UID.",
2633
+ description: "Stop a running grid trading bot. [CAUTION] This will close or cancel the bot's orders. For contract grids, stopType controls whether positions are closed ('1') or only orders cancelled ('2').",
2632
2634
  isWrite: true,
2633
2635
  inputSchema: {
2634
2636
  type: "object",
@@ -2672,13 +2674,6 @@ function registerGridTools() {
2672
2674
  ];
2673
2675
  }
2674
2676
  var BASE = "/api/v5/tradingBot/dca";
2675
- function normalize4(response) {
2676
- return {
2677
- endpoint: response.endpoint,
2678
- requestTime: response.requestTime,
2679
- data: response.data
2680
- };
2681
- }
2682
2677
  function normalizeWrite2(response) {
2683
2678
  const data = response.data;
2684
2679
  if (Array.isArray(data) && data.length > 0) {
@@ -2706,7 +2701,7 @@ function registerDcaTools() {
2706
2701
  {
2707
2702
  name: "dca_create_order",
2708
2703
  module: "bot.dca",
2709
- description: "Create a Contract DCA (Martingale) bot order with leverage on futures/swaps. Required: instId, lever, direction, initOrdAmt, maxSafetyOrds, tpPct. Conditionally required (when maxSafetyOrds > 0): safetyOrdAmt, pxSteps, pxStepsMult, volMult. Optional: slPct, slMode, allowReinvest, triggerStrategy, triggerPx. [CAUTION] Executes real trades. Private endpoint. Rate limit: 20 req/2s.",
2704
+ description: "Create a Contract DCA (Martingale) bot order with leverage on futures/swaps. Required: instId, lever, direction, initOrdAmt, maxSafetyOrds, tpPct. When maxSafetyOrds > 0: also provide safetyOrdAmt, pxSteps, pxStepsMult, volMult. [CAUTION] Executes real trades.",
2710
2705
  isWrite: true,
2711
2706
  inputSchema: {
2712
2707
  type: "object",
@@ -2767,7 +2762,7 @@ function registerDcaTools() {
2767
2762
  {
2768
2763
  name: "dca_stop_order",
2769
2764
  module: "bot.dca",
2770
- description: "Stop a running Contract DCA bot. [CAUTION] This will stop the bot. Private endpoint. Rate limit: 20 req/2s.",
2765
+ description: "Stop a running Contract DCA bot. [CAUTION] This will stop the bot.",
2771
2766
  isWrite: true,
2772
2767
  inputSchema: {
2773
2768
  type: "object",
@@ -2793,7 +2788,7 @@ function registerDcaTools() {
2793
2788
  {
2794
2789
  name: "dca_get_orders",
2795
2790
  module: "bot.dca",
2796
- description: "Query Contract DCA bot orders. Use status='active' for running bots, status='history' for completed/stopped. Private endpoint. Rate limit: 20 req/2s.",
2791
+ description: "Query Contract DCA bot orders. status='active' for running bots; status='history' for completed/stopped.",
2797
2792
  isWrite: false,
2798
2793
  inputSchema: {
2799
2794
  type: "object",
@@ -2830,13 +2825,13 @@ function registerDcaTools() {
2830
2825
  }),
2831
2826
  privateRateLimit("dca_get_orders", 20)
2832
2827
  );
2833
- return normalize4(response);
2828
+ return normalizeResponse(response);
2834
2829
  }
2835
2830
  },
2836
2831
  {
2837
2832
  name: "dca_get_order_details",
2838
2833
  module: "bot.dca",
2839
- description: "Query details of a single Contract DCA bot by algo ID. Returns current position details. Private endpoint. Rate limit: 20 req/2s.",
2834
+ description: "Query details of a single Contract DCA bot by algo ID. Returns current position details.",
2840
2835
  isWrite: false,
2841
2836
  inputSchema: {
2842
2837
  type: "object",
@@ -2856,13 +2851,13 @@ function registerDcaTools() {
2856
2851
  { algoId, algoOrdType: "contract_dca" },
2857
2852
  privateRateLimit("dca_get_order_details", 20)
2858
2853
  );
2859
- return normalize4(response);
2854
+ return normalizeResponse(response);
2860
2855
  }
2861
2856
  },
2862
2857
  {
2863
2858
  name: "dca_get_sub_orders",
2864
2859
  module: "bot.dca",
2865
- description: "Query cycles or orders within a cycle of a Contract DCA bot. Returns cycle list when cycleId is omitted; returns orders within a specific cycle when cycleId is provided. Private endpoint. Rate limit: 20 req/2s.",
2860
+ description: "Query cycles or orders within a cycle of a Contract DCA bot. Omit cycleId for cycle list; provide cycleId for orders within a cycle.",
2866
2861
  isWrite: false,
2867
2862
  inputSchema: {
2868
2863
  type: "object",
@@ -2893,7 +2888,7 @@ function registerDcaTools() {
2893
2888
  }),
2894
2889
  privateRateLimit("dca_get_sub_orders", 20)
2895
2890
  );
2896
- return normalize4(response2);
2891
+ return normalizeResponse(response2);
2897
2892
  }
2898
2893
  const response = await context.client.privateGet(
2899
2894
  `${BASE}/cycle-list`,
@@ -2906,7 +2901,7 @@ function registerDcaTools() {
2906
2901
  }),
2907
2902
  privateRateLimit("dca_get_sub_orders", 20)
2908
2903
  );
2909
- return normalize4(response);
2904
+ return normalizeResponse(response);
2910
2905
  }
2911
2906
  }
2912
2907
  ];
@@ -3712,19 +3707,12 @@ function registerAllEarnTools() {
3712
3707
  ];
3713
3708
  }
3714
3709
  var FUTURES_INST_TYPES = ["FUTURES", "SWAP"];
3715
- function normalize5(response) {
3716
- return {
3717
- endpoint: response.endpoint,
3718
- requestTime: response.requestTime,
3719
- data: response.data
3720
- };
3721
- }
3722
3710
  function registerFuturesTools() {
3723
3711
  return [
3724
3712
  {
3725
3713
  name: "futures_place_order",
3726
3714
  module: "futures",
3727
- description: "Place a FUTURES delivery contract order (e.g. instId: BTC-USDT-240329). Optionally attach TP/SL via tpTriggerPx/slTriggerPx. [CAUTION] Executes real trades. Private endpoint. Rate limit: 60 req/s.",
3715
+ description: "Place a FUTURES delivery contract order (e.g. instId: BTC-USDT-240329). Optionally attach TP/SL via tpTriggerPx/slTriggerPx. [CAUTION] Executes real trades.",
3728
3716
  isWrite: true,
3729
3717
  inputSchema: {
3730
3718
  type: "object",
@@ -3791,12 +3779,7 @@ function registerFuturesTools() {
3791
3779
  handler: async (rawArgs, context) => {
3792
3780
  const args = asRecord(rawArgs);
3793
3781
  const reduceOnly = args.reduceOnly;
3794
- const tpTriggerPx = readString(args, "tpTriggerPx");
3795
- const tpOrdPx = readString(args, "tpOrdPx");
3796
- const slTriggerPx = readString(args, "slTriggerPx");
3797
- const slOrdPx = readString(args, "slOrdPx");
3798
- const algoEntry = compactObject({ tpTriggerPx, tpOrdPx, slTriggerPx, slOrdPx });
3799
- const attachAlgoOrds = Object.keys(algoEntry).length > 0 ? [algoEntry] : void 0;
3782
+ const attachAlgoOrds = buildAttachAlgoOrds(args);
3800
3783
  const response = await context.client.privatePost(
3801
3784
  "/api/v5/trade/order",
3802
3785
  compactObject({
@@ -3814,13 +3797,13 @@ function registerFuturesTools() {
3814
3797
  }),
3815
3798
  privateRateLimit("futures_place_order", 60)
3816
3799
  );
3817
- return normalize5(response);
3800
+ return normalizeResponse(response);
3818
3801
  }
3819
3802
  },
3820
3803
  {
3821
3804
  name: "futures_cancel_order",
3822
3805
  module: "futures",
3823
- description: "Cancel an unfilled FUTURES delivery order. Private endpoint. Rate limit: 60 req/s.",
3806
+ description: "Cancel an unfilled FUTURES delivery order.",
3824
3807
  isWrite: true,
3825
3808
  inputSchema: {
3826
3809
  type: "object",
@@ -3850,13 +3833,13 @@ function registerFuturesTools() {
3850
3833
  }),
3851
3834
  privateRateLimit("futures_cancel_order", 60)
3852
3835
  );
3853
- return normalize5(response);
3836
+ return normalizeResponse(response);
3854
3837
  }
3855
3838
  },
3856
3839
  {
3857
3840
  name: "futures_get_order",
3858
3841
  module: "futures",
3859
- description: "Get details of a single FUTURES delivery order by ordId or clOrdId. Private endpoint. Rate limit: 60 req/s.",
3842
+ description: "Get details of a single FUTURES delivery order by ordId or clOrdId.",
3860
3843
  isWrite: false,
3861
3844
  inputSchema: {
3862
3845
  type: "object",
@@ -3887,13 +3870,13 @@ function registerFuturesTools() {
3887
3870
  }),
3888
3871
  privateRateLimit("futures_get_order", 60)
3889
3872
  );
3890
- return normalize5(response);
3873
+ return normalizeResponse(response);
3891
3874
  }
3892
3875
  },
3893
3876
  {
3894
3877
  name: "futures_get_orders",
3895
3878
  module: "futures",
3896
- description: "Query FUTURES open orders, history (last 7 days), or archive (up to 3 months). Private. Rate limit: 20 req/s.",
3879
+ description: "Query FUTURES open orders, history (last 7 days), or archive (up to 3 months).",
3897
3880
  isWrite: false,
3898
3881
  inputSchema: {
3899
3882
  type: "object",
@@ -3963,13 +3946,13 @@ function registerFuturesTools() {
3963
3946
  }),
3964
3947
  privateRateLimit("futures_get_orders", 20)
3965
3948
  );
3966
- return normalize5(response);
3949
+ return normalizeResponse(response);
3967
3950
  }
3968
3951
  },
3969
3952
  {
3970
3953
  name: "futures_get_positions",
3971
3954
  module: "futures",
3972
- description: "Get current FUTURES delivery contract positions. Private endpoint. Rate limit: 10 req/s.",
3955
+ description: "Get current FUTURES delivery contract positions.",
3973
3956
  isWrite: false,
3974
3957
  inputSchema: {
3975
3958
  type: "object",
@@ -4001,13 +3984,13 @@ function registerFuturesTools() {
4001
3984
  }),
4002
3985
  privateRateLimit("futures_get_positions", 10)
4003
3986
  );
4004
- return normalize5(response);
3987
+ return normalizeResponse(response);
4005
3988
  }
4006
3989
  },
4007
3990
  {
4008
3991
  name: "futures_get_fills",
4009
3992
  module: "futures",
4010
- description: "Get FUTURES fill details. archive=false: last 3 days. archive=true: up to 3 months. Private. Rate limit: 20 req/s.",
3993
+ description: "Get FUTURES fill details. archive=false: last 3 days; archive=true: up to 3 months.",
4011
3994
  isWrite: false,
4012
3995
  inputSchema: {
4013
3996
  type: "object",
@@ -4071,24 +4054,17 @@ function registerFuturesTools() {
4071
4054
  }),
4072
4055
  privateRateLimit("futures_get_fills", 20)
4073
4056
  );
4074
- return normalize5(response);
4057
+ return normalizeResponse(response);
4075
4058
  }
4076
4059
  }
4077
4060
  ];
4078
4061
  }
4079
- function normalize6(response) {
4080
- return {
4081
- endpoint: response.endpoint,
4082
- requestTime: response.requestTime,
4083
- data: response.data
4084
- };
4085
- }
4086
4062
  function registerMarketTools() {
4087
4063
  return [
4088
4064
  {
4089
4065
  name: "market_get_ticker",
4090
4066
  module: "market",
4091
- description: "Get ticker data for a single instrument. Public endpoint, no authentication required. Rate limit: 20 req/s.",
4067
+ description: "Get ticker data for a single instrument.",
4092
4068
  isWrite: false,
4093
4069
  inputSchema: {
4094
4070
  type: "object",
@@ -4107,13 +4083,13 @@ function registerMarketTools() {
4107
4083
  { instId: requireString(args, "instId") },
4108
4084
  publicRateLimit("market_get_ticker", 20)
4109
4085
  );
4110
- return normalize6(response);
4086
+ return normalizeResponse(response);
4111
4087
  }
4112
4088
  },
4113
4089
  {
4114
4090
  name: "market_get_tickers",
4115
4091
  module: "market",
4116
- description: "Get ticker data for all instruments of a given type. Public endpoint, no authentication required. Rate limit: 20 req/s.",
4092
+ description: "Get ticker data for all instruments of a given type.",
4117
4093
  isWrite: false,
4118
4094
  inputSchema: {
4119
4095
  type: "object",
@@ -4144,13 +4120,13 @@ function registerMarketTools() {
4144
4120
  }),
4145
4121
  publicRateLimit("market_get_tickers", 20)
4146
4122
  );
4147
- return normalize6(response);
4123
+ return normalizeResponse(response);
4148
4124
  }
4149
4125
  },
4150
4126
  {
4151
4127
  name: "market_get_orderbook",
4152
4128
  module: "market",
4153
- description: "Get the order book (bids/asks) for an instrument. Public endpoint, no authentication required. Rate limit: 20 req/s.",
4129
+ description: "Get the order book (bids/asks) for an instrument.",
4154
4130
  isWrite: false,
4155
4131
  inputSchema: {
4156
4132
  type: "object",
@@ -4176,13 +4152,13 @@ function registerMarketTools() {
4176
4152
  }),
4177
4153
  publicRateLimit("market_get_orderbook", 20)
4178
4154
  );
4179
- return normalize6(response);
4155
+ return normalizeResponse(response);
4180
4156
  }
4181
4157
  },
4182
4158
  {
4183
4159
  name: "market_get_candles",
4184
4160
  module: "market",
4185
- description: "Get candlestick (OHLCV) data for an instrument. history=false (default): recent candles up to 1440 bars. history=true: older historical data beyond the recent window. Public endpoint, no authentication required. Rate limit: 40 req/s.",
4161
+ description: "Get candlestick (OHLCV) data for an instrument. history=false (default): recent candles up to 1440 bars; history=true: older historical data.",
4186
4162
  isWrite: false,
4187
4163
  inputSchema: {
4188
4164
  type: "object",
@@ -4230,13 +4206,13 @@ function registerMarketTools() {
4230
4206
  }),
4231
4207
  publicRateLimit("market_get_candles", 40)
4232
4208
  );
4233
- return normalize6(response);
4209
+ return normalizeResponse(response);
4234
4210
  }
4235
4211
  },
4236
4212
  {
4237
4213
  name: "market_get_instruments",
4238
4214
  module: "market",
4239
- description: "Get tradable instruments for a given type. Returns contract specs: min order size, lot size, tick size, contract value, settlement currency, listing/expiry time. Essential before placing orders. Public endpoint. Rate limit: 20 req/s.",
4215
+ description: "Get tradable instruments for a given type. Returns contract specs: min order size, lot size, tick size, contract value, settlement currency, listing/expiry time. Essential before placing orders.",
4240
4216
  isWrite: false,
4241
4217
  inputSchema: {
4242
4218
  type: "object",
@@ -4272,13 +4248,13 @@ function registerMarketTools() {
4272
4248
  }),
4273
4249
  publicRateLimit("market_get_instruments", 20)
4274
4250
  );
4275
- return normalize6(response);
4251
+ return normalizeResponse(response);
4276
4252
  }
4277
4253
  },
4278
4254
  {
4279
4255
  name: "market_get_funding_rate",
4280
4256
  module: "market",
4281
- description: "Get funding rate for a SWAP instrument. history=false (default): current rate and estimated next rate + settlement time. history=true: historical rates, default 20 records, max 100. Public endpoint. Rate limit: 20 req/s.",
4257
+ description: "Get funding rate for a SWAP instrument. history=false (default): current rate + next estimated rate; history=true: historical rates.",
4282
4258
  isWrite: false,
4283
4259
  inputSchema: {
4284
4260
  type: "object",
@@ -4320,20 +4296,20 @@ function registerMarketTools() {
4320
4296
  }),
4321
4297
  publicRateLimit("market_get_funding_rate", 20)
4322
4298
  );
4323
- return normalize6(response2);
4299
+ return normalizeResponse(response2);
4324
4300
  }
4325
4301
  const response = await context.client.publicGet(
4326
4302
  "/api/v5/public/funding-rate",
4327
4303
  { instId: requireString(args, "instId") },
4328
4304
  publicRateLimit("market_get_funding_rate", 20)
4329
4305
  );
4330
- return normalize6(response);
4306
+ return normalizeResponse(response);
4331
4307
  }
4332
4308
  },
4333
4309
  {
4334
4310
  name: "market_get_mark_price",
4335
4311
  module: "market",
4336
- description: "Get mark price for SWAP, FUTURES, or MARGIN instruments. Mark price is used for liquidation calculations and unrealized PnL. Public endpoint. Rate limit: 10 req/s.",
4312
+ description: "Get mark price for SWAP, FUTURES, or MARGIN instruments. Used for liquidation calculations and unrealized PnL.",
4337
4313
  isWrite: false,
4338
4314
  inputSchema: {
4339
4315
  type: "object",
@@ -4368,13 +4344,13 @@ function registerMarketTools() {
4368
4344
  }),
4369
4345
  publicRateLimit("market_get_mark_price", 10)
4370
4346
  );
4371
- return normalize6(response);
4347
+ return normalizeResponse(response);
4372
4348
  }
4373
4349
  },
4374
4350
  {
4375
4351
  name: "market_get_trades",
4376
4352
  module: "market",
4377
- description: "Get recent trades for an instrument. Default 20 records, max 500. Public endpoint, no authentication required. Rate limit: 20 req/s.",
4353
+ description: "Get recent trades for an instrument. Default 20 records, max 500.",
4378
4354
  isWrite: false,
4379
4355
  inputSchema: {
4380
4356
  type: "object",
@@ -4400,13 +4376,13 @@ function registerMarketTools() {
4400
4376
  }),
4401
4377
  publicRateLimit("market_get_trades", 20)
4402
4378
  );
4403
- return normalize6(response);
4379
+ return normalizeResponse(response);
4404
4380
  }
4405
4381
  },
4406
4382
  {
4407
4383
  name: "market_get_index_ticker",
4408
4384
  module: "market",
4409
- description: "Get index ticker data (e.g. BTC-USD, ETH-USD index prices). Index prices are used for mark price calculation and are independent of any single exchange. Public endpoint. Rate limit: 20 req/s.",
4385
+ description: "Get index ticker data (e.g. BTC-USD, ETH-USD index prices). Independent of any single exchange.",
4410
4386
  isWrite: false,
4411
4387
  inputSchema: {
4412
4388
  type: "object",
@@ -4431,13 +4407,13 @@ function registerMarketTools() {
4431
4407
  }),
4432
4408
  publicRateLimit("market_get_index_ticker", 20)
4433
4409
  );
4434
- return normalize6(response);
4410
+ return normalizeResponse(response);
4435
4411
  }
4436
4412
  },
4437
4413
  {
4438
4414
  name: "market_get_index_candles",
4439
4415
  module: "market",
4440
- description: "Get candlestick data for an index (e.g. BTC-USD index). history=false (default): recent candles up to 1440 bars. history=true: older historical data beyond the recent window. Public endpoint. Rate limit: 20 req/s.",
4416
+ description: "Get candlestick data for an index (e.g. BTC-USD index). history=false: recent up to 1440 bars; history=true: older data.",
4441
4417
  isWrite: false,
4442
4418
  inputSchema: {
4443
4419
  type: "object",
@@ -4485,13 +4461,13 @@ function registerMarketTools() {
4485
4461
  }),
4486
4462
  publicRateLimit("market_get_index_candles", 20)
4487
4463
  );
4488
- return normalize6(response);
4464
+ return normalizeResponse(response);
4489
4465
  }
4490
4466
  },
4491
4467
  {
4492
4468
  name: "market_get_price_limit",
4493
4469
  module: "market",
4494
- description: "Get the current price limit (upper and lower bands) for a SWAP or FUTURES instrument. Orders placed outside these limits will be rejected by OKX. Public endpoint. Rate limit: 20 req/s.",
4470
+ description: "Get the current price limit (upper and lower bands) for a SWAP or FUTURES instrument. Orders outside these limits will be rejected.",
4495
4471
  isWrite: false,
4496
4472
  inputSchema: {
4497
4473
  type: "object",
@@ -4510,13 +4486,13 @@ function registerMarketTools() {
4510
4486
  { instId: requireString(args, "instId") },
4511
4487
  publicRateLimit("market_get_price_limit", 20)
4512
4488
  );
4513
- return normalize6(response);
4489
+ return normalizeResponse(response);
4514
4490
  }
4515
4491
  },
4516
4492
  {
4517
4493
  name: "market_get_open_interest",
4518
4494
  module: "market",
4519
- description: "Get open interest for SWAP, FUTURES, or OPTION instruments. Useful for gauging market sentiment and positioning. Public endpoint. Rate limit: 20 req/s.",
4495
+ description: "Get open interest for SWAP, FUTURES, or OPTION instruments. Useful for gauging market sentiment and positioning.",
4520
4496
  isWrite: false,
4521
4497
  inputSchema: {
4522
4498
  type: "object",
@@ -4551,13 +4527,13 @@ function registerMarketTools() {
4551
4527
  }),
4552
4528
  publicRateLimit("market_get_open_interest", 20)
4553
4529
  );
4554
- return normalize6(response);
4530
+ return normalizeResponse(response);
4555
4531
  }
4556
4532
  },
4557
4533
  {
4558
4534
  name: "market_get_stock_tokens",
4559
4535
  module: "market",
4560
- description: "Get all stock token instruments (instCategory=3). Stock tokens track real-world stock prices on OKX (e.g. AAPL-USDT-SWAP, TSLA-USDT-SWAP). Fetches all instruments of the given type and filters client-side by instCategory=3. Public endpoint. Rate limit: 20 req/s.",
4536
+ description: "Get all stock token instruments (instCategory=3). Stock tokens track real-world stock prices on OKX (e.g. AAPL-USDT-SWAP). Filters client-side by instCategory=3.",
4561
4537
  isWrite: false,
4562
4538
  inputSchema: {
4563
4539
  type: "object",
@@ -4585,24 +4561,17 @@ function registerMarketTools() {
4585
4561
  );
4586
4562
  const data = response.data;
4587
4563
  const filtered = Array.isArray(data) ? data.filter((item) => item.instCategory === "3") : data;
4588
- return normalize6({ ...response, data: filtered });
4564
+ return normalizeResponse({ ...response, data: filtered });
4589
4565
  }
4590
4566
  }
4591
4567
  ];
4592
4568
  }
4593
- function normalize7(response) {
4594
- return {
4595
- endpoint: response.endpoint,
4596
- requestTime: response.requestTime,
4597
- data: response.data
4598
- };
4599
- }
4600
4569
  function registerOptionTools() {
4601
4570
  return [
4602
4571
  {
4603
4572
  name: "option_place_order",
4604
4573
  module: "option",
4605
- description: "Place an OPTION order (buy/sell call or put). instId format: {uly}-{expiry}-{strike}-{C|P}, e.g. BTC-USD-241227-50000-C. tdMode: cash (buyer) or cross/isolated (seller). [CAUTION] Executes real trades. Private endpoint. Rate limit: 60 req/s.",
4574
+ description: "Place an OPTION order (buy/sell call or put). instId format: {uly}-{expiry}-{strike}-{C|P}, e.g. BTC-USD-241227-50000-C. tdMode: cash (buyer) or cross/isolated (seller). [CAUTION] Executes real trades.",
4606
4575
  isWrite: true,
4607
4576
  inputSchema: {
4608
4577
  type: "object",
@@ -4662,13 +4631,13 @@ function registerOptionTools() {
4662
4631
  }),
4663
4632
  privateRateLimit("option_place_order", 60)
4664
4633
  );
4665
- return normalize7(response);
4634
+ return normalizeResponse(response);
4666
4635
  }
4667
4636
  },
4668
4637
  {
4669
4638
  name: "option_cancel_order",
4670
4639
  module: "option",
4671
- description: "Cancel an unfilled OPTION order. Provide ordId or clOrdId. Private endpoint. Rate limit: 60 req/s.",
4640
+ description: "Cancel an unfilled OPTION order. Provide ordId or clOrdId.",
4672
4641
  isWrite: true,
4673
4642
  inputSchema: {
4674
4643
  type: "object",
@@ -4690,13 +4659,13 @@ function registerOptionTools() {
4690
4659
  }),
4691
4660
  privateRateLimit("option_cancel_order", 60)
4692
4661
  );
4693
- return normalize7(response);
4662
+ return normalizeResponse(response);
4694
4663
  }
4695
4664
  },
4696
4665
  {
4697
4666
  name: "option_batch_cancel",
4698
4667
  module: "option",
4699
- description: "[CAUTION] Batch cancel up to 20 OPTION orders. Each item: {instId, ordId?, clOrdId?}. Private endpoint. Rate limit: 60 req/s.",
4668
+ description: "[CAUTION] Batch cancel up to 20 OPTION orders. Each item: {instId, ordId?, clOrdId?}.",
4700
4669
  isWrite: true,
4701
4670
  inputSchema: {
4702
4671
  type: "object",
@@ -4720,13 +4689,13 @@ function registerOptionTools() {
4720
4689
  orders,
4721
4690
  privateRateLimit("option_batch_cancel", 60)
4722
4691
  );
4723
- return normalize7(response);
4692
+ return normalizeResponse(response);
4724
4693
  }
4725
4694
  },
4726
4695
  {
4727
4696
  name: "option_amend_order",
4728
4697
  module: "option",
4729
- description: "Amend an unfilled OPTION order (price and/or size). Provide ordId or clOrdId. Private endpoint. Rate limit: 60 req/s.",
4698
+ description: "Amend an unfilled OPTION order (price and/or size). Provide ordId or clOrdId.",
4730
4699
  isWrite: true,
4731
4700
  inputSchema: {
4732
4701
  type: "object",
@@ -4752,13 +4721,13 @@ function registerOptionTools() {
4752
4721
  }),
4753
4722
  privateRateLimit("option_amend_order", 60)
4754
4723
  );
4755
- return normalize7(response);
4724
+ return normalizeResponse(response);
4756
4725
  }
4757
4726
  },
4758
4727
  {
4759
4728
  name: "option_get_order",
4760
4729
  module: "option",
4761
- description: "Get details of a single OPTION order by ordId or clOrdId. Private endpoint. Rate limit: 60 req/s.",
4730
+ description: "Get details of a single OPTION order by ordId or clOrdId.",
4762
4731
  isWrite: false,
4763
4732
  inputSchema: {
4764
4733
  type: "object",
@@ -4780,13 +4749,13 @@ function registerOptionTools() {
4780
4749
  }),
4781
4750
  privateRateLimit("option_get_order", 60)
4782
4751
  );
4783
- return normalize7(response);
4752
+ return normalizeResponse(response);
4784
4753
  }
4785
4754
  },
4786
4755
  {
4787
4756
  name: "option_get_orders",
4788
4757
  module: "option",
4789
- description: "List OPTION orders. status: live=pending (default), history=7d, archive=3mo. Private endpoint. Rate limit: 20 req/s.",
4758
+ description: "List OPTION orders. status: live=pending (default), history=7d, archive=3mo.",
4790
4759
  isWrite: false,
4791
4760
  inputSchema: {
4792
4761
  type: "object",
@@ -4827,13 +4796,13 @@ function registerOptionTools() {
4827
4796
  }),
4828
4797
  privateRateLimit("option_get_orders", 20)
4829
4798
  );
4830
- return normalize7(response);
4799
+ return normalizeResponse(response);
4831
4800
  }
4832
4801
  },
4833
4802
  {
4834
4803
  name: "option_get_positions",
4835
4804
  module: "option",
4836
- description: "Get current OPTION positions including Greeks (delta, gamma, theta, vega). Private endpoint. Rate limit: 10 req/s.",
4805
+ description: "Get current OPTION positions including Greeks (delta, gamma, theta, vega).",
4837
4806
  isWrite: false,
4838
4807
  inputSchema: {
4839
4808
  type: "object",
@@ -4853,13 +4822,13 @@ function registerOptionTools() {
4853
4822
  }),
4854
4823
  privateRateLimit("option_get_positions", 10)
4855
4824
  );
4856
- return normalize7(response);
4825
+ return normalizeResponse(response);
4857
4826
  }
4858
4827
  },
4859
4828
  {
4860
4829
  name: "option_get_fills",
4861
4830
  module: "option",
4862
- description: "Get OPTION fill history. archive=false: last 3 days (default). archive=true: up to 3 months. Private endpoint. Rate limit: 20 req/s.",
4831
+ description: "Get OPTION fill history. archive=false: last 3 days (default); archive=true: up to 3 months.",
4863
4832
  isWrite: false,
4864
4833
  inputSchema: {
4865
4834
  type: "object",
@@ -4895,13 +4864,13 @@ function registerOptionTools() {
4895
4864
  }),
4896
4865
  privateRateLimit("option_get_fills", 20)
4897
4866
  );
4898
- return normalize7(response);
4867
+ return normalizeResponse(response);
4899
4868
  }
4900
4869
  },
4901
4870
  {
4902
4871
  name: "option_get_instruments",
4903
4872
  module: "option",
4904
- description: "List available OPTION contracts for a given underlying (option chain). Use to find valid instIds before placing orders. Public endpoint. Rate limit: 20 req/s.",
4873
+ description: "List available OPTION contracts for a given underlying (option chain). Use to find valid instIds before placing orders.",
4905
4874
  isWrite: false,
4906
4875
  inputSchema: {
4907
4876
  type: "object",
@@ -4928,13 +4897,13 @@ function registerOptionTools() {
4928
4897
  }),
4929
4898
  privateRateLimit("option_get_instruments", 20)
4930
4899
  );
4931
- return normalize7(response);
4900
+ return normalizeResponse(response);
4932
4901
  }
4933
4902
  },
4934
4903
  {
4935
4904
  name: "option_get_greeks",
4936
4905
  module: "option",
4937
- description: "Get implied volatility and Greeks (delta, gamma, theta, vega) for OPTION contracts by underlying. Public endpoint. Rate limit: 20 req/s.",
4906
+ description: "Get implied volatility and Greeks (delta, gamma, theta, vega) for OPTION contracts by underlying.",
4938
4907
  isWrite: false,
4939
4908
  inputSchema: {
4940
4909
  type: "object",
@@ -4960,24 +4929,17 @@ function registerOptionTools() {
4960
4929
  }),
4961
4930
  privateRateLimit("option_get_greeks", 20)
4962
4931
  );
4963
- return normalize7(response);
4932
+ return normalizeResponse(response);
4964
4933
  }
4965
4934
  }
4966
4935
  ];
4967
4936
  }
4968
- function normalize8(response) {
4969
- return {
4970
- endpoint: response.endpoint,
4971
- requestTime: response.requestTime,
4972
- data: response.data
4973
- };
4974
- }
4975
4937
  function registerSpotTradeTools() {
4976
4938
  return [
4977
4939
  {
4978
4940
  name: "spot_place_order",
4979
4941
  module: "spot",
4980
- description: "Place a spot order. Optionally attach take-profit/stop-loss via tpTriggerPx/slTriggerPx (assembled into attachAlgoOrds automatically). [CAUTION] Executes real trades. Private endpoint. Rate limit: 60 req/s per UID.",
4942
+ description: "Place a spot order. Optionally attach TP/SL via tpTriggerPx/slTriggerPx (assembled into attachAlgoOrds automatically). [CAUTION] Executes real trades.",
4981
4943
  isWrite: true,
4982
4944
  inputSchema: {
4983
4945
  type: "object",
@@ -5033,12 +4995,7 @@ function registerSpotTradeTools() {
5033
4995
  },
5034
4996
  handler: async (rawArgs, context) => {
5035
4997
  const args = asRecord(rawArgs);
5036
- const tpTriggerPx = readString(args, "tpTriggerPx");
5037
- const tpOrdPx = readString(args, "tpOrdPx");
5038
- const slTriggerPx = readString(args, "slTriggerPx");
5039
- const slOrdPx = readString(args, "slOrdPx");
5040
- const algoEntry = compactObject({ tpTriggerPx, tpOrdPx, slTriggerPx, slOrdPx });
5041
- const attachAlgoOrds = Object.keys(algoEntry).length > 0 ? [algoEntry] : void 0;
4998
+ const attachAlgoOrds = buildAttachAlgoOrds(args);
5042
4999
  const response = await context.client.privatePost(
5043
5000
  "/api/v5/trade/order",
5044
5001
  compactObject({
@@ -5054,13 +5011,13 @@ function registerSpotTradeTools() {
5054
5011
  }),
5055
5012
  privateRateLimit("spot_place_order", 60)
5056
5013
  );
5057
- return normalize8(response);
5014
+ return normalizeResponse(response);
5058
5015
  }
5059
5016
  },
5060
5017
  {
5061
5018
  name: "spot_cancel_order",
5062
5019
  module: "spot",
5063
- description: "Cancel an unfilled spot order by order ID or client order ID. Private endpoint. Rate limit: 60 req/s per UID.",
5020
+ description: "Cancel an unfilled spot order by order ID or client order ID.",
5064
5021
  isWrite: true,
5065
5022
  inputSchema: {
5066
5023
  type: "object",
@@ -5090,13 +5047,13 @@ function registerSpotTradeTools() {
5090
5047
  }),
5091
5048
  privateRateLimit("spot_cancel_order", 60)
5092
5049
  );
5093
- return normalize8(response);
5050
+ return normalizeResponse(response);
5094
5051
  }
5095
5052
  },
5096
5053
  {
5097
5054
  name: "spot_amend_order",
5098
5055
  module: "spot",
5099
- description: "Amend an unfilled spot order (modify price or size). Private endpoint. Rate limit: 60 req/s per UID.",
5056
+ description: "Amend an unfilled spot order (modify price or size).",
5100
5057
  isWrite: true,
5101
5058
  inputSchema: {
5102
5059
  type: "object",
@@ -5142,13 +5099,13 @@ function registerSpotTradeTools() {
5142
5099
  }),
5143
5100
  privateRateLimit("spot_amend_order", 60)
5144
5101
  );
5145
- return normalize8(response);
5102
+ return normalizeResponse(response);
5146
5103
  }
5147
5104
  },
5148
5105
  {
5149
5106
  name: "spot_get_orders",
5150
5107
  module: "spot",
5151
- description: "Query spot open orders, order history (last 7 days), or order archive (up to 3 months). Private endpoint. Rate limit: 20 req/s.",
5108
+ description: "Query spot open orders, order history (last 7 days), or order archive (up to 3 months).",
5152
5109
  isWrite: false,
5153
5110
  inputSchema: {
5154
5111
  type: "object",
@@ -5211,13 +5168,13 @@ function registerSpotTradeTools() {
5211
5168
  }),
5212
5169
  privateRateLimit("spot_get_orders", 20)
5213
5170
  );
5214
- return normalize8(response);
5171
+ return normalizeResponse(response);
5215
5172
  }
5216
5173
  },
5217
5174
  {
5218
5175
  name: "spot_place_algo_order",
5219
5176
  module: "spot",
5220
- description: "Place a spot algo order with take-profit and/or stop-loss. [CAUTION] Executes real trades. Private endpoint. Rate limit: 20 req/s per UID.",
5177
+ description: "Place a spot algo order: TP/SL (conditional/oco) or trailing stop (move_order_stop). For conditional/oco: use tpTriggerPx, tpOrdPx, slTriggerPx, slOrdPx. For move_order_stop: use callbackRatio (e.g. '0.01'=1%) OR callbackSpread, and optionally activePx. [CAUTION] Executes real trades.",
5221
5178
  isWrite: true,
5222
5179
  inputSchema: {
5223
5180
  type: "object",
@@ -5237,8 +5194,8 @@ function registerSpotTradeTools() {
5237
5194
  },
5238
5195
  ordType: {
5239
5196
  type: "string",
5240
- enum: ["conditional", "oco"],
5241
- description: "conditional=single TP/SL; oco=TP+SL pair (one-cancels-other)"
5197
+ enum: ["conditional", "oco", "move_order_stop"],
5198
+ description: "conditional=single TP/SL; oco=TP+SL pair (one-cancels-other); move_order_stop=trailing stop"
5242
5199
  },
5243
5200
  sz: {
5244
5201
  type: "string",
@@ -5246,19 +5203,31 @@ function registerSpotTradeTools() {
5246
5203
  },
5247
5204
  tpTriggerPx: {
5248
5205
  type: "string",
5249
- description: "TP trigger price"
5206
+ description: "TP trigger price (conditional/oco only)"
5250
5207
  },
5251
5208
  tpOrdPx: {
5252
5209
  type: "string",
5253
- description: "TP order price; -1=market"
5210
+ description: "TP order price; -1=market (conditional/oco only)"
5254
5211
  },
5255
5212
  slTriggerPx: {
5256
5213
  type: "string",
5257
- description: "SL trigger price"
5214
+ description: "SL trigger price (conditional/oco only)"
5258
5215
  },
5259
5216
  slOrdPx: {
5260
5217
  type: "string",
5261
- description: "SL order price; -1=market"
5218
+ description: "SL order price; -1=market (conditional/oco only)"
5219
+ },
5220
+ callbackRatio: {
5221
+ type: "string",
5222
+ description: "Callback ratio (e.g. '0.01'=1%); provide either ratio or spread (move_order_stop only)"
5223
+ },
5224
+ callbackSpread: {
5225
+ type: "string",
5226
+ description: "Callback spread in price units; provide either ratio or spread (move_order_stop only)"
5227
+ },
5228
+ activePx: {
5229
+ type: "string",
5230
+ description: "Activation price; tracking starts after market reaches this level (move_order_stop only)"
5262
5231
  }
5263
5232
  },
5264
5233
  required: ["instId", "side", "ordType", "sz"]
@@ -5277,17 +5246,20 @@ function registerSpotTradeTools() {
5277
5246
  tpOrdPx: readString(args, "tpOrdPx"),
5278
5247
  slTriggerPx: readString(args, "slTriggerPx"),
5279
5248
  slOrdPx: readString(args, "slOrdPx"),
5249
+ callbackRatio: readString(args, "callbackRatio"),
5250
+ callbackSpread: readString(args, "callbackSpread"),
5251
+ activePx: readString(args, "activePx"),
5280
5252
  tag: context.config.sourceTag
5281
5253
  }),
5282
5254
  privateRateLimit("spot_place_algo_order", 20)
5283
5255
  );
5284
- return normalize8(response);
5256
+ return normalizeResponse(response);
5285
5257
  }
5286
5258
  },
5287
5259
  {
5288
5260
  name: "spot_amend_algo_order",
5289
5261
  module: "spot",
5290
- description: "Amend a pending spot algo order (modify TP/SL prices or size). Private endpoint. Rate limit: 20 req/s.",
5262
+ description: "Amend a pending spot algo order (modify TP/SL prices or size).",
5291
5263
  isWrite: true,
5292
5264
  inputSchema: {
5293
5265
  type: "object",
@@ -5317,13 +5289,13 @@ function registerSpotTradeTools() {
5317
5289
  }),
5318
5290
  privateRateLimit("spot_amend_algo_order", 20)
5319
5291
  );
5320
- return normalize8(response);
5292
+ return normalizeResponse(response);
5321
5293
  }
5322
5294
  },
5323
5295
  {
5324
5296
  name: "spot_cancel_algo_order",
5325
5297
  module: "spot",
5326
- description: "Cancel a spot algo order (TP/SL). Private endpoint. Rate limit: 20 req/s per UID.",
5298
+ description: "Cancel a spot algo order (TP/SL).",
5327
5299
  isWrite: true,
5328
5300
  inputSchema: {
5329
5301
  type: "object",
@@ -5351,13 +5323,13 @@ function registerSpotTradeTools() {
5351
5323
  ],
5352
5324
  privateRateLimit("spot_cancel_algo_order", 20)
5353
5325
  );
5354
- return normalize8(response);
5326
+ return normalizeResponse(response);
5355
5327
  }
5356
5328
  },
5357
5329
  {
5358
5330
  name: "spot_get_algo_orders",
5359
5331
  module: "spot",
5360
- description: "Query spot algo orders (TP/SL) \u2014 pending or history. Private endpoint. Rate limit: 20 req/s.",
5332
+ description: "Query spot algo orders (TP/SL) \u2014 pending or history.",
5361
5333
  isWrite: false,
5362
5334
  inputSchema: {
5363
5335
  type: "object",
@@ -5373,7 +5345,7 @@ function registerSpotTradeTools() {
5373
5345
  },
5374
5346
  ordType: {
5375
5347
  type: "string",
5376
- enum: ["conditional", "oco"],
5348
+ enum: ["conditional", "oco", "move_order_stop"],
5377
5349
  description: "Filter by type; omit for all"
5378
5350
  },
5379
5351
  after: {
@@ -5416,15 +5388,17 @@ function registerSpotTradeTools() {
5416
5388
  { ...baseParams, ordType },
5417
5389
  privateRateLimit("spot_get_algo_orders", 20)
5418
5390
  );
5419
- return normalize8(response);
5391
+ return normalizeResponse(response);
5420
5392
  }
5421
- const [r1, r2] = await Promise.all([
5393
+ const [r1, r2, r3] = await Promise.all([
5422
5394
  context.client.privateGet(path4, { ...baseParams, ordType: "conditional" }, privateRateLimit("spot_get_algo_orders", 20)),
5423
- context.client.privateGet(path4, { ...baseParams, ordType: "oco" }, privateRateLimit("spot_get_algo_orders", 20))
5395
+ context.client.privateGet(path4, { ...baseParams, ordType: "oco" }, privateRateLimit("spot_get_algo_orders", 20)),
5396
+ context.client.privateGet(path4, { ...baseParams, ordType: "move_order_stop" }, privateRateLimit("spot_get_algo_orders", 20))
5424
5397
  ]);
5425
5398
  const merged = [
5426
5399
  ...r1.data ?? [],
5427
- ...r2.data ?? []
5400
+ ...r2.data ?? [],
5401
+ ...r3.data ?? []
5428
5402
  ];
5429
5403
  return { endpoint: r1.endpoint, requestTime: r1.requestTime, data: merged };
5430
5404
  }
@@ -5432,7 +5406,7 @@ function registerSpotTradeTools() {
5432
5406
  {
5433
5407
  name: "spot_get_fills",
5434
5408
  module: "spot",
5435
- description: "Get spot transaction fill details. archive=false (default): last 3 days. archive=true: up to 3 months, default limit 20. Private endpoint. Rate limit: 20 req/s.",
5409
+ description: "Get spot transaction fill details. archive=false (default): last 3 days; archive=true: up to 3 months.",
5436
5410
  isWrite: false,
5437
5411
  inputSchema: {
5438
5412
  type: "object",
@@ -5489,7 +5463,7 @@ function registerSpotTradeTools() {
5489
5463
  }),
5490
5464
  privateRateLimit("spot_get_fills", 20)
5491
5465
  );
5492
- return normalize8(response);
5466
+ return normalizeResponse(response);
5493
5467
  }
5494
5468
  },
5495
5469
  {
@@ -5530,12 +5504,7 @@ function registerSpotTradeTools() {
5530
5504
  };
5531
5505
  const body = action === "place" ? orders.map((order) => {
5532
5506
  const o = asRecord(order);
5533
- const tpTriggerPx = readString(o, "tpTriggerPx");
5534
- const tpOrdPx = readString(o, "tpOrdPx");
5535
- const slTriggerPx = readString(o, "slTriggerPx");
5536
- const slOrdPx = readString(o, "slOrdPx");
5537
- const algoEntry = compactObject({ tpTriggerPx, tpOrdPx, slTriggerPx, slOrdPx });
5538
- const attachAlgoOrds = Object.keys(algoEntry).length > 0 ? [algoEntry] : void 0;
5507
+ const attachAlgoOrds = buildAttachAlgoOrds(o);
5539
5508
  return compactObject({
5540
5509
  instId: requireString(o, "instId"),
5541
5510
  tdMode: readString(o, "tdMode") ?? "cash",
@@ -5553,13 +5522,13 @@ function registerSpotTradeTools() {
5553
5522
  body,
5554
5523
  privateRateLimit("spot_batch_orders", 60)
5555
5524
  );
5556
- return normalize8(response);
5525
+ return normalizeResponse(response);
5557
5526
  }
5558
5527
  },
5559
5528
  {
5560
5529
  name: "spot_get_order",
5561
5530
  module: "spot",
5562
- description: "Get details of a single spot order by order ID or client order ID. Private endpoint. Rate limit: 60 req/s.",
5531
+ description: "Get details of a single spot order by order ID or client order ID.",
5563
5532
  isWrite: false,
5564
5533
  inputSchema: {
5565
5534
  type: "object",
@@ -5590,13 +5559,13 @@ function registerSpotTradeTools() {
5590
5559
  }),
5591
5560
  privateRateLimit("spot_get_order", 60)
5592
5561
  );
5593
- return normalize8(response);
5562
+ return normalizeResponse(response);
5594
5563
  }
5595
5564
  },
5596
5565
  {
5597
5566
  name: "spot_batch_amend",
5598
5567
  module: "spot",
5599
- description: "[CAUTION] Batch amend up to 20 unfilled spot orders in one request. Modify price and/or size per order. Private endpoint. Rate limit: 60 req/s.",
5568
+ description: "[CAUTION] Batch amend up to 20 unfilled spot orders in one request. Modify price and/or size per order.",
5600
5569
  isWrite: true,
5601
5570
  inputSchema: {
5602
5571
  type: "object",
@@ -5620,13 +5589,13 @@ function registerSpotTradeTools() {
5620
5589
  orders,
5621
5590
  privateRateLimit("spot_batch_amend", 60)
5622
5591
  );
5623
- return normalize8(response);
5592
+ return normalizeResponse(response);
5624
5593
  }
5625
5594
  },
5626
5595
  {
5627
5596
  name: "spot_batch_cancel",
5628
5597
  module: "spot",
5629
- description: "[CAUTION] Batch cancel up to 20 spot orders in one request. Provide instId plus ordId or clOrdId for each order. Private endpoint. Rate limit: 60 req/s.",
5598
+ description: "[CAUTION] Batch cancel up to 20 spot orders in one request. Provide instId plus ordId or clOrdId for each order.",
5630
5599
  isWrite: true,
5631
5600
  inputSchema: {
5632
5601
  type: "object",
@@ -5650,25 +5619,18 @@ function registerSpotTradeTools() {
5650
5619
  orders,
5651
5620
  privateRateLimit("spot_batch_cancel", 60)
5652
5621
  );
5653
- return normalize8(response);
5622
+ return normalizeResponse(response);
5654
5623
  }
5655
5624
  }
5656
5625
  ];
5657
5626
  }
5658
5627
  var SWAP_INST_TYPES = ["SWAP", "FUTURES"];
5659
- function normalize9(response) {
5660
- return {
5661
- endpoint: response.endpoint,
5662
- requestTime: response.requestTime,
5663
- data: response.data
5664
- };
5665
- }
5666
5628
  function registerSwapTradeTools() {
5667
5629
  return [
5668
5630
  {
5669
5631
  name: "swap_place_order",
5670
5632
  module: "swap",
5671
- description: "Place a SWAP or FUTURES perpetual/delivery contract order. Optionally attach take-profit/stop-loss via tpTriggerPx/slTriggerPx (assembled into attachAlgoOrds automatically). [CAUTION] Executes real trades. Private endpoint. Rate limit: 60 req/s per UID.",
5633
+ description: "Place a SWAP or FUTURES contract order. Optionally attach TP/SL via tpTriggerPx/slTriggerPx (assembled into attachAlgoOrds automatically). [CAUTION] Executes real trades.",
5672
5634
  isWrite: true,
5673
5635
  inputSchema: {
5674
5636
  type: "object",
@@ -5735,12 +5697,7 @@ function registerSwapTradeTools() {
5735
5697
  handler: async (rawArgs, context) => {
5736
5698
  const args = asRecord(rawArgs);
5737
5699
  const reduceOnly = args.reduceOnly;
5738
- const tpTriggerPx = readString(args, "tpTriggerPx");
5739
- const tpOrdPx = readString(args, "tpOrdPx");
5740
- const slTriggerPx = readString(args, "slTriggerPx");
5741
- const slOrdPx = readString(args, "slOrdPx");
5742
- const algoEntry = compactObject({ tpTriggerPx, tpOrdPx, slTriggerPx, slOrdPx });
5743
- const attachAlgoOrds = Object.keys(algoEntry).length > 0 ? [algoEntry] : void 0;
5700
+ const attachAlgoOrds = buildAttachAlgoOrds(args);
5744
5701
  const response = await context.client.privatePost(
5745
5702
  "/api/v5/trade/order",
5746
5703
  compactObject({
@@ -5758,13 +5715,13 @@ function registerSwapTradeTools() {
5758
5715
  }),
5759
5716
  privateRateLimit("swap_place_order", 60)
5760
5717
  );
5761
- return normalize9(response);
5718
+ return normalizeResponse(response);
5762
5719
  }
5763
5720
  },
5764
5721
  {
5765
5722
  name: "swap_cancel_order",
5766
5723
  module: "swap",
5767
- description: "Cancel an unfilled SWAP or FUTURES order. Private endpoint. Rate limit: 60 req/s per UID.",
5724
+ description: "Cancel an unfilled SWAP or FUTURES order.",
5768
5725
  isWrite: true,
5769
5726
  inputSchema: {
5770
5727
  type: "object",
@@ -5794,13 +5751,13 @@ function registerSwapTradeTools() {
5794
5751
  }),
5795
5752
  privateRateLimit("swap_cancel_order", 60)
5796
5753
  );
5797
- return normalize9(response);
5754
+ return normalizeResponse(response);
5798
5755
  }
5799
5756
  },
5800
5757
  {
5801
5758
  name: "swap_get_orders",
5802
5759
  module: "swap",
5803
- description: "Query SWAP or FUTURES open orders, order history (last 7 days), or order archive (up to 3 months). Private endpoint. Rate limit: 20 req/s.",
5760
+ description: "Query SWAP or FUTURES open orders, history (last 7 days), or archive (up to 3 months).",
5804
5761
  isWrite: false,
5805
5762
  inputSchema: {
5806
5763
  type: "object",
@@ -5870,13 +5827,13 @@ function registerSwapTradeTools() {
5870
5827
  }),
5871
5828
  privateRateLimit("swap_get_orders", 20)
5872
5829
  );
5873
- return normalize9(response);
5830
+ return normalizeResponse(response);
5874
5831
  }
5875
5832
  },
5876
5833
  {
5877
5834
  name: "swap_get_positions",
5878
5835
  module: "swap",
5879
- description: "Get current SWAP or FUTURES positions. Private endpoint. Rate limit: 10 req/s.",
5836
+ description: "Get current SWAP or FUTURES positions.",
5880
5837
  isWrite: false,
5881
5838
  inputSchema: {
5882
5839
  type: "object",
@@ -5908,13 +5865,13 @@ function registerSwapTradeTools() {
5908
5865
  }),
5909
5866
  privateRateLimit("swap_get_positions", 10)
5910
5867
  );
5911
- return normalize9(response);
5868
+ return normalizeResponse(response);
5912
5869
  }
5913
5870
  },
5914
5871
  {
5915
5872
  name: "swap_set_leverage",
5916
5873
  module: "swap",
5917
- description: "Set leverage for a SWAP or FUTURES instrument or position. [CAUTION] Changes risk parameters. Private endpoint. Rate limit: 20 req/s.",
5874
+ description: "Set leverage for a SWAP or FUTURES instrument or position. [CAUTION] Changes risk parameters.",
5918
5875
  isWrite: true,
5919
5876
  inputSchema: {
5920
5877
  type: "object",
@@ -5951,13 +5908,13 @@ function registerSwapTradeTools() {
5951
5908
  }),
5952
5909
  privateRateLimit("swap_set_leverage", 20)
5953
5910
  );
5954
- return normalize9(response);
5911
+ return normalizeResponse(response);
5955
5912
  }
5956
5913
  },
5957
5914
  {
5958
5915
  name: "swap_amend_algo_order",
5959
5916
  module: "swap",
5960
- description: "Amend a pending SWAP/FUTURES algo order (modify TP/SL prices or size). Private endpoint. Rate limit: 20 req/s.",
5917
+ description: "Amend a pending SWAP/FUTURES algo order (modify TP/SL prices or size).",
5961
5918
  isWrite: true,
5962
5919
  inputSchema: {
5963
5920
  type: "object",
@@ -5987,13 +5944,13 @@ function registerSwapTradeTools() {
5987
5944
  }),
5988
5945
  privateRateLimit("swap_amend_algo_order", 20)
5989
5946
  );
5990
- return normalize9(response);
5947
+ return normalizeResponse(response);
5991
5948
  }
5992
5949
  },
5993
5950
  {
5994
5951
  name: "swap_get_fills",
5995
5952
  module: "swap",
5996
- description: "Get SWAP or FUTURES transaction fill details. archive=false (default): last 3 days. archive=true: up to 3 months, default limit 20. Private endpoint. Rate limit: 20 req/s.",
5953
+ description: "Get SWAP or FUTURES fill details. archive=false (default): last 3 days; archive=true: up to 3 months.",
5997
5954
  isWrite: false,
5998
5955
  inputSchema: {
5999
5956
  type: "object",
@@ -6057,13 +6014,13 @@ function registerSwapTradeTools() {
6057
6014
  }),
6058
6015
  privateRateLimit("swap_get_fills", 20)
6059
6016
  );
6060
- return normalize9(response);
6017
+ return normalizeResponse(response);
6061
6018
  }
6062
6019
  },
6063
6020
  {
6064
6021
  name: "swap_get_order",
6065
6022
  module: "swap",
6066
- description: "Get details of a single SWAP or FUTURES order by order ID or client order ID. Private endpoint. Rate limit: 60 req/s.",
6023
+ description: "Get details of a single SWAP or FUTURES order by order ID or client order ID.",
6067
6024
  isWrite: false,
6068
6025
  inputSchema: {
6069
6026
  type: "object",
@@ -6094,7 +6051,7 @@ function registerSwapTradeTools() {
6094
6051
  }),
6095
6052
  privateRateLimit("swap_get_order", 60)
6096
6053
  );
6097
- return normalize9(response);
6054
+ return normalizeResponse(response);
6098
6055
  }
6099
6056
  },
6100
6057
  {
@@ -6144,7 +6101,7 @@ function registerSwapTradeTools() {
6144
6101
  }),
6145
6102
  privateRateLimit("swap_close_position", 20)
6146
6103
  );
6147
- return normalize9(response);
6104
+ return normalizeResponse(response);
6148
6105
  }
6149
6106
  },
6150
6107
  {
@@ -6184,12 +6141,7 @@ function registerSwapTradeTools() {
6184
6141
  };
6185
6142
  const body = action === "place" ? orders.map((order) => {
6186
6143
  const o = asRecord(order);
6187
- const tpTriggerPx = readString(o, "tpTriggerPx");
6188
- const tpOrdPx = readString(o, "tpOrdPx");
6189
- const slTriggerPx = readString(o, "slTriggerPx");
6190
- const slOrdPx = readString(o, "slOrdPx");
6191
- const algoEntry = compactObject({ tpTriggerPx, tpOrdPx, slTriggerPx, slOrdPx });
6192
- const attachAlgoOrds = Object.keys(algoEntry).length > 0 ? [algoEntry] : void 0;
6144
+ const attachAlgoOrds = buildAttachAlgoOrds(o);
6193
6145
  const reduceOnly = o.reduceOnly;
6194
6146
  return compactObject({
6195
6147
  instId: requireString(o, "instId"),
@@ -6210,13 +6162,13 @@ function registerSwapTradeTools() {
6210
6162
  body,
6211
6163
  privateRateLimit("swap_batch_orders", 60)
6212
6164
  );
6213
- return normalize9(response);
6165
+ return normalizeResponse(response);
6214
6166
  }
6215
6167
  },
6216
6168
  {
6217
6169
  name: "swap_get_leverage",
6218
6170
  module: "swap",
6219
- description: "Get current leverage for a SWAP/FUTURES instrument. Call before swap_place_order to verify leverage. Private. Rate limit: 20 req/s.",
6171
+ description: "Get current leverage for a SWAP/FUTURES instrument. Call before swap_place_order to verify leverage.",
6220
6172
  isWrite: false,
6221
6173
  inputSchema: {
6222
6174
  type: "object",
@@ -6242,13 +6194,13 @@ function registerSwapTradeTools() {
6242
6194
  }),
6243
6195
  privateRateLimit("swap_get_leverage", 20)
6244
6196
  );
6245
- return normalize9(response);
6197
+ return normalizeResponse(response);
6246
6198
  }
6247
6199
  },
6248
6200
  {
6249
6201
  name: "swap_batch_amend",
6250
6202
  module: "swap",
6251
- description: "[CAUTION] Batch amend up to 20 unfilled SWAP/FUTURES orders in one request. Modify price and/or size per order. Private endpoint. Rate limit: 60 req/s.",
6203
+ description: "[CAUTION] Batch amend up to 20 unfilled SWAP/FUTURES orders in one request. Modify price and/or size per order.",
6252
6204
  isWrite: true,
6253
6205
  inputSchema: {
6254
6206
  type: "object",
@@ -6272,13 +6224,13 @@ function registerSwapTradeTools() {
6272
6224
  orders,
6273
6225
  privateRateLimit("swap_batch_amend", 60)
6274
6226
  );
6275
- return normalize9(response);
6227
+ return normalizeResponse(response);
6276
6228
  }
6277
6229
  },
6278
6230
  {
6279
6231
  name: "swap_batch_cancel",
6280
6232
  module: "swap",
6281
- description: "[CAUTION] Batch cancel up to 20 SWAP/FUTURES orders in one request. Provide instId plus ordId or clOrdId for each order. Private endpoint. Rate limit: 60 req/s.",
6233
+ description: "[CAUTION] Batch cancel up to 20 SWAP/FUTURES orders in one request. Provide instId plus ordId or clOrdId for each order.",
6282
6234
  isWrite: true,
6283
6235
  inputSchema: {
6284
6236
  type: "object",
@@ -6302,7 +6254,7 @@ function registerSwapTradeTools() {
6302
6254
  orders,
6303
6255
  privateRateLimit("swap_batch_cancel", 60)
6304
6256
  );
6305
- return normalize9(response);
6257
+ return normalizeResponse(response);
6306
6258
  }
6307
6259
  }
6308
6260
  ];
@@ -6354,11 +6306,8 @@ function writeFullConfig(config) {
6354
6306
  }
6355
6307
  writeFileSync(path4, stringify(config), "utf-8");
6356
6308
  }
6357
- var BASE_MODULES = MODULES.filter(
6358
- (m) => !BOT_SUB_MODULE_IDS.includes(m) && !EARN_SUB_MODULE_IDS.includes(m)
6359
- );
6360
6309
  function expandShorthand(moduleId) {
6361
- if (moduleId === "all") return [...BASE_MODULES, ...BOT_SUB_MODULE_IDS];
6310
+ if (moduleId === "all") return [...MODULES];
6362
6311
  if (moduleId === "earn" || moduleId === "earn.all") return [...EARN_SUB_MODULE_IDS];
6363
6312
  if (moduleId === "bot") return [...BOT_DEFAULT_SUB_MODULES];
6364
6313
  if (moduleId === "bot.all") return [...BOT_SUB_MODULE_IDS];
@@ -6369,9 +6318,6 @@ function parseModuleList(rawModules) {
6369
6318
  return [...DEFAULT_MODULES];
6370
6319
  }
6371
6320
  const trimmed = rawModules.trim().toLowerCase();
6372
- if (trimmed === "all") {
6373
- return [...BASE_MODULES, ...BOT_SUB_MODULE_IDS];
6374
- }
6375
6321
  const requested = trimmed.split(",").map((s) => s.trim()).filter(Boolean);
6376
6322
  if (requested.length === 0) {
6377
6323
  return [...DEFAULT_MODULES];
@@ -6691,7 +6637,7 @@ function readCliVersion() {
6691
6637
  return "0.0.0";
6692
6638
  }
6693
6639
  var CLI_VERSION = readCliVersion();
6694
- var GIT_HASH = true ? "1df90cc" : "dev";
6640
+ var GIT_HASH = true ? "a880395" : "dev";
6695
6641
  var Report = class {
6696
6642
  lines = [];
6697
6643
  add(key, value) {
@@ -7272,7 +7218,7 @@ var HELP_TREE = {
7272
7218
  }
7273
7219
  },
7274
7220
  futures: {
7275
- description: "Futures trading (orders, positions)",
7221
+ description: "Futures trading (orders, positions, algo orders, leverage)",
7276
7222
  commands: {
7277
7223
  orders: {
7278
7224
  usage: "okx futures orders [--instId <id>] [--history] [--archive]",
@@ -7294,9 +7240,56 @@ var HELP_TREE = {
7294
7240
  usage: "okx futures cancel <instId> --ordId <id>",
7295
7241
  description: "Cancel a pending futures order"
7296
7242
  },
7243
+ amend: {
7244
+ usage: "okx futures amend --instId <id> [--ordId <id>] [--clOrdId <id>] [--newSz <n>] [--newPx <price>]",
7245
+ description: "Amend a pending futures order"
7246
+ },
7297
7247
  get: {
7298
7248
  usage: "okx futures get --instId <id> --ordId <id>",
7299
7249
  description: "Get details of a specific futures order"
7250
+ },
7251
+ close: {
7252
+ usage: "okx futures close --instId <id> --mgnMode <cross|isolated> [--posSide <net|long|short>] [--autoCxl]",
7253
+ description: "Close a futures position"
7254
+ },
7255
+ "get-leverage": {
7256
+ usage: "okx futures get-leverage --instId <id> --mgnMode <cross|isolated>",
7257
+ description: "Get current leverage for a futures instrument"
7258
+ },
7259
+ leverage: {
7260
+ usage: "okx futures leverage --instId <id> --lever <n> --mgnMode <cross|isolated> [--posSide <net|long|short>]",
7261
+ description: "Set leverage for a futures instrument"
7262
+ },
7263
+ batch: {
7264
+ usage: "okx futures batch --action <place|amend|cancel> --orders '<json>'",
7265
+ description: "Batch place, amend, or cancel futures orders"
7266
+ }
7267
+ },
7268
+ subgroups: {
7269
+ algo: {
7270
+ description: "Futures algo orders (trailing stop, conditional, OCO)",
7271
+ commands: {
7272
+ orders: {
7273
+ usage: "okx futures algo orders [--instId <id>] [--history] [--ordType <conditional|oco>]",
7274
+ description: "List futures algo orders"
7275
+ },
7276
+ trail: {
7277
+ usage: "okx futures algo trail --instId <id> --side <buy|sell> --sz <n> --callbackRatio <ratio>\n [--activePx <price>] [--posSide <net|long|short>] [--tdMode <cross|isolated>] [--reduceOnly]",
7278
+ description: "Place a trailing stop algo order for futures"
7279
+ },
7280
+ place: {
7281
+ usage: "okx futures algo place --instId <id> --side <buy|sell> --sz <n> [--ordType <conditional|oco>]\n [--tpTriggerPx <price>] [--tpOrdPx <price|-1>]\n [--slTriggerPx <price>] [--slOrdPx <price|-1>]\n [--posSide <net|long|short>] [--tdMode <cross|isolated>] [--reduceOnly]",
7282
+ description: "Place a futures algo order (take-profit/stop-loss)"
7283
+ },
7284
+ amend: {
7285
+ usage: "okx futures algo amend --instId <id> --algoId <id> [--newSz <n>]\n [--newTpTriggerPx <price>] [--newTpOrdPx <price|-1>]\n [--newSlTriggerPx <price>] [--newSlOrdPx <price|-1>]",
7286
+ description: "Amend a pending futures algo order"
7287
+ },
7288
+ cancel: {
7289
+ usage: "okx futures algo cancel --instId <id> --algoId <id>",
7290
+ description: "Cancel a pending futures algo order"
7291
+ }
7292
+ }
7300
7293
  }
7301
7294
  }
7302
7295
  },
@@ -8474,6 +8467,25 @@ async function cmdSpotFills(run, opts) {
8474
8467
  }))
8475
8468
  );
8476
8469
  }
8470
+ async function cmdSpotAlgoTrailPlace(run, opts) {
8471
+ const result = await run("spot_place_algo_order", {
8472
+ instId: opts.instId,
8473
+ tdMode: opts.tdMode ?? "cash",
8474
+ side: opts.side,
8475
+ ordType: "move_order_stop",
8476
+ sz: opts.sz,
8477
+ callbackRatio: opts.callbackRatio,
8478
+ callbackSpread: opts.callbackSpread,
8479
+ activePx: opts.activePx
8480
+ });
8481
+ const data = getData3(result);
8482
+ if (opts.json) return printJson(data);
8483
+ const order = data?.[0];
8484
+ process.stdout.write(
8485
+ `Trailing stop placed: ${order?.["algoId"]} (${order?.["sCode"] === "0" ? "OK" : order?.["sMsg"]})
8486
+ `
8487
+ );
8488
+ }
8477
8489
  async function cmdSpotBatch(run, opts) {
8478
8490
  let parsed;
8479
8491
  try {
@@ -8908,6 +8920,16 @@ async function cmdFuturesGet(run, opts) {
8908
8920
  cTime: new Date(Number(o["cTime"])).toLocaleString()
8909
8921
  });
8910
8922
  }
8923
+ var cmdFuturesAmend = cmdSwapAmend;
8924
+ var cmdFuturesAlgoPlace = cmdSwapAlgoPlace;
8925
+ var cmdFuturesAlgoAmend = cmdSwapAlgoAmend;
8926
+ var cmdFuturesAlgoCancel = cmdSwapAlgoCancel;
8927
+ var cmdFuturesAlgoOrders = cmdSwapAlgoOrders;
8928
+ var cmdFuturesBatch = cmdSwapBatch;
8929
+ var cmdFuturesClose = cmdSwapClose;
8930
+ var cmdFuturesGetLeverage = cmdSwapGetLeverage;
8931
+ var cmdFuturesSetLeverage = cmdSwapSetLeverage;
8932
+ var cmdFuturesAlgoTrailPlace = cmdSwapAlgoTrailPlace;
8911
8933
 
8912
8934
  // src/commands/option.ts
8913
8935
  function getData6(result) {
@@ -10168,7 +10190,7 @@ async function cmdDcdQuoteAndBuy(run, opts) {
10168
10190
  // src/index.ts
10169
10191
  var _require2 = createRequire2(import.meta.url);
10170
10192
  var CLI_VERSION2 = _require2("../package.json").version;
10171
- var GIT_HASH2 = true ? "1df90cc" : "dev";
10193
+ var GIT_HASH2 = true ? "a880395" : "dev";
10172
10194
  function handleConfigCommand(action, rest, json, lang, force) {
10173
10195
  if (action === "init") return cmdConfigInit(lang === "zh" ? "zh" : "en");
10174
10196
  if (action === "show") return cmdConfigShow(json);
@@ -10280,6 +10302,17 @@ function handleAccountCommand(run, action, rest, v, json) {
10280
10302
  return handleAccountWriteCommand(run, action, v, json);
10281
10303
  }
10282
10304
  function handleSpotAlgoCommand(run, subAction, v, json) {
10305
+ if (subAction === "trail")
10306
+ return cmdSpotAlgoTrailPlace(run, {
10307
+ instId: v.instId,
10308
+ side: v.side,
10309
+ sz: v.sz,
10310
+ callbackRatio: v.callbackRatio,
10311
+ callbackSpread: v.callbackSpread,
10312
+ activePx: v.activePx,
10313
+ tdMode: v.tdMode,
10314
+ json
10315
+ });
10283
10316
  if (subAction === "place")
10284
10317
  return cmdSpotAlgoPlace(run, {
10285
10318
  instId: v.instId,
@@ -10515,6 +10548,56 @@ function handleOptionCommand(run, action, _rest, v, json) {
10515
10548
  if (action === "batch-cancel")
10516
10549
  return cmdOptionBatchCancel(run, { orders: v.orders, json });
10517
10550
  }
10551
+ function handleFuturesAlgoCommand(run, subAction, v, json) {
10552
+ if (subAction === "trail")
10553
+ return cmdFuturesAlgoTrailPlace(run, {
10554
+ instId: v.instId,
10555
+ side: v.side,
10556
+ sz: v.sz,
10557
+ callbackRatio: v.callbackRatio,
10558
+ callbackSpread: v.callbackSpread,
10559
+ activePx: v.activePx,
10560
+ posSide: v.posSide,
10561
+ tdMode: v.tdMode ?? "cross",
10562
+ reduceOnly: v.reduceOnly,
10563
+ json
10564
+ });
10565
+ if (subAction === "place")
10566
+ return cmdFuturesAlgoPlace(run, {
10567
+ instId: v.instId,
10568
+ side: v.side,
10569
+ ordType: v.ordType ?? "conditional",
10570
+ sz: v.sz,
10571
+ posSide: v.posSide,
10572
+ tdMode: v.tdMode ?? "cross",
10573
+ tpTriggerPx: v.tpTriggerPx,
10574
+ tpOrdPx: v.tpOrdPx,
10575
+ slTriggerPx: v.slTriggerPx,
10576
+ slOrdPx: v.slOrdPx,
10577
+ reduceOnly: v.reduceOnly,
10578
+ json
10579
+ });
10580
+ if (subAction === "amend")
10581
+ return cmdFuturesAlgoAmend(run, {
10582
+ instId: v.instId,
10583
+ algoId: v.algoId,
10584
+ newSz: v.newSz,
10585
+ newTpTriggerPx: v.newTpTriggerPx,
10586
+ newTpOrdPx: v.newTpOrdPx,
10587
+ newSlTriggerPx: v.newSlTriggerPx,
10588
+ newSlOrdPx: v.newSlOrdPx,
10589
+ json
10590
+ });
10591
+ if (subAction === "cancel")
10592
+ return cmdFuturesAlgoCancel(run, v.instId, v.algoId, json);
10593
+ if (subAction === "orders")
10594
+ return cmdFuturesAlgoOrders(run, {
10595
+ instId: v.instId,
10596
+ status: v.history ? "history" : "pending",
10597
+ ordType: v.ordType,
10598
+ json
10599
+ });
10600
+ }
10518
10601
  function handleFuturesCommand(run, action, rest, v, json) {
10519
10602
  if (action === "orders") {
10520
10603
  let status = "open";
@@ -10550,6 +10633,37 @@ function handleFuturesCommand(run, action, rest, v, json) {
10550
10633
  return cmdFuturesCancel(run, rest[0] ?? v.instId, v.ordId, json);
10551
10634
  if (action === "get")
10552
10635
  return cmdFuturesGet(run, { instId: rest[0] ?? v.instId, ordId: v.ordId, json });
10636
+ if (action === "amend")
10637
+ return cmdFuturesAmend(run, {
10638
+ instId: v.instId,
10639
+ ordId: v.ordId,
10640
+ clOrdId: v.clOrdId,
10641
+ newSz: v.newSz,
10642
+ newPx: v.newPx,
10643
+ json
10644
+ });
10645
+ if (action === "close")
10646
+ return cmdFuturesClose(run, {
10647
+ instId: v.instId,
10648
+ mgnMode: v.mgnMode,
10649
+ posSide: v.posSide,
10650
+ autoCxl: v.autoCxl,
10651
+ json
10652
+ });
10653
+ if (action === "get-leverage")
10654
+ return cmdFuturesGetLeverage(run, { instId: v.instId, mgnMode: v.mgnMode, json });
10655
+ if (action === "leverage")
10656
+ return cmdFuturesSetLeverage(run, {
10657
+ instId: v.instId,
10658
+ lever: v.lever,
10659
+ mgnMode: v.mgnMode,
10660
+ posSide: v.posSide,
10661
+ json
10662
+ });
10663
+ if (action === "batch")
10664
+ return cmdFuturesBatch(run, { action: v.action, orders: v.orders, json });
10665
+ if (action === "algo")
10666
+ return handleFuturesAlgoCommand(run, rest[0], v, json);
10553
10667
  }
10554
10668
  function handleBotGridCommand(run, v, rest, json) {
10555
10669
  const subAction = rest[0];