ccxt 4.5.3 → 4.5.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.
Files changed (44) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +67 -5
  5. package/dist/cjs/src/base/functions/encode.js +8 -0
  6. package/dist/cjs/src/base/functions/rsa.js +14 -1
  7. package/dist/cjs/src/base/functions.js +1 -0
  8. package/dist/cjs/src/binance.js +7 -4
  9. package/dist/cjs/src/bitvavo.js +8 -0
  10. package/dist/cjs/src/bybit.js +20 -6
  11. package/dist/cjs/src/coinbase.js +28 -10
  12. package/dist/cjs/src/coincatch.js +32 -19
  13. package/dist/cjs/src/delta.js +1 -0
  14. package/dist/cjs/src/kucoinfutures.js +3 -2
  15. package/dist/cjs/src/okx.js +2 -1
  16. package/dist/cjs/src/pro/bitget.js +111 -14
  17. package/dist/cjs/src/pro/bybit.js +64 -8
  18. package/dist/cjs/src/pro/coinex.js +10 -11
  19. package/js/ccxt.d.ts +1 -1
  20. package/js/ccxt.js +1 -1
  21. package/js/src/abstract/myokx.d.ts +1 -0
  22. package/js/src/abstract/okx.d.ts +1 -0
  23. package/js/src/abstract/okxus.d.ts +1 -0
  24. package/js/src/base/Exchange.d.ts +4 -0
  25. package/js/src/base/Exchange.js +67 -5
  26. package/js/src/base/functions/encode.d.ts +2 -1
  27. package/js/src/base/functions/encode.js +8 -1
  28. package/js/src/base/functions/rsa.js +16 -3
  29. package/js/src/binance.js +7 -4
  30. package/js/src/bitvavo.js +8 -0
  31. package/js/src/bybit.js +20 -6
  32. package/js/src/coinbase.d.ts +1 -1
  33. package/js/src/coinbase.js +28 -10
  34. package/js/src/coincatch.d.ts +2 -0
  35. package/js/src/coincatch.js +32 -19
  36. package/js/src/delta.js +1 -0
  37. package/js/src/kucoinfutures.js +3 -2
  38. package/js/src/okx.js +2 -1
  39. package/js/src/pro/bitget.d.ts +3 -1
  40. package/js/src/pro/bitget.js +111 -14
  41. package/js/src/pro/bybit.d.ts +4 -0
  42. package/js/src/pro/bybit.js +64 -8
  43. package/js/src/pro/coinex.js +11 -12
  44. package/package.json +3 -3
@@ -1125,6 +1125,32 @@ class bitget extends bitget$1["default"] {
1125
1125
  // "uTime": "1714471204194"
1126
1126
  // }
1127
1127
  //
1128
+ // uta private
1129
+ //
1130
+ // {
1131
+ // "symbol": "BTCUSDT",
1132
+ // "orderType": "market",
1133
+ // "updatedTime": "1736378720623",
1134
+ // "side": "buy",
1135
+ // "orderId": "1288888888888888888",
1136
+ // "execPnl": "0",
1137
+ // "feeDetail": [
1138
+ // {
1139
+ // "feeCoin": "USDT",
1140
+ // "fee": "0.569958"
1141
+ // }
1142
+ // ],
1143
+ // "execTime": "1736378720623",
1144
+ // "tradeScope": "taker",
1145
+ // "tradeSide": "open",
1146
+ // "execId": "1288888888888888888",
1147
+ // "execLinkId": "1288888888888888888",
1148
+ // "execPrice": "94993",
1149
+ // "holdSide": "long",
1150
+ // "execValue": "949.93",
1151
+ // "category": "USDT-FUTURES",
1152
+ // "execQty": "0.01",
1153
+ // "clientOid": "1288888888888888889"
1128
1154
  // uta
1129
1155
  //
1130
1156
  // {
@@ -1138,11 +1164,18 @@ class bitget extends bitget$1["default"] {
1138
1164
  //
1139
1165
  const instId = this.safeString2(trade, 'symbol', 'instId');
1140
1166
  const posMode = this.safeString(trade, 'posMode');
1141
- const defaultType = (posMode !== undefined) ? 'contract' : 'spot';
1167
+ const category = this.safeString(trade, 'category');
1168
+ let defaultType = undefined;
1169
+ if (category !== undefined) {
1170
+ defaultType = (category !== 'SPOT') ? 'contract' : 'spot';
1171
+ }
1172
+ else {
1173
+ defaultType = (posMode !== undefined) ? 'contract' : 'spot';
1174
+ }
1142
1175
  if (market === undefined) {
1143
1176
  market = this.safeMarket(instId, undefined, undefined, defaultType);
1144
1177
  }
1145
- const timestamp = this.safeIntegerN(trade, ['uTime', 'cTime', 'ts', 'T']);
1178
+ const timestamp = this.safeIntegerN(trade, ['uTime', 'cTime', 'ts', 'T', 'execTime']);
1146
1179
  const feeDetail = this.safeList(trade, 'feeDetail', []);
1147
1180
  const first = this.safeDict(feeDetail, 0);
1148
1181
  let fee = undefined;
@@ -1150,13 +1183,13 @@ class bitget extends bitget$1["default"] {
1150
1183
  const feeCurrencyId = this.safeString(first, 'feeCoin');
1151
1184
  const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1152
1185
  fee = {
1153
- 'cost': Precise["default"].stringAbs(this.safeString(first, 'totalFee')),
1186
+ 'cost': Precise["default"].stringAbs(this.safeString2(first, 'totalFee', 'fee')),
1154
1187
  'currency': feeCurrencyCode,
1155
1188
  };
1156
1189
  }
1157
1190
  return this.safeTrade({
1158
1191
  'info': trade,
1159
- 'id': this.safeString2(trade, 'tradeId', 'i'),
1192
+ 'id': this.safeStringN(trade, ['tradeId', 'i', 'execId']),
1160
1193
  'order': this.safeString2(trade, 'orderId', 'L'),
1161
1194
  'timestamp': timestamp,
1162
1195
  'datetime': this.iso8601(timestamp),
@@ -1164,9 +1197,9 @@ class bitget extends bitget$1["default"] {
1164
1197
  'type': this.safeString(trade, 'orderType'),
1165
1198
  'side': this.safeString2(trade, 'side', 'S'),
1166
1199
  'takerOrMaker': this.safeString(trade, 'tradeScope'),
1167
- 'price': this.safeStringN(trade, ['priceAvg', 'price', 'P']),
1168
- 'amount': this.safeStringN(trade, ['size', 'baseVolume', 'v']),
1169
- 'cost': this.safeString2(trade, 'amount', 'quoteVolume'),
1200
+ 'price': this.safeStringN(trade, ['priceAvg', 'price', 'execPrice', 'P']),
1201
+ 'amount': this.safeStringN(trade, ['size', 'baseVolume', 'execQty', 'v']),
1202
+ 'cost': this.safeStringN(trade, ['amount', 'quoteVolume', 'execValue']),
1170
1203
  'fee': fee,
1171
1204
  }, market);
1172
1205
  }
@@ -1762,11 +1795,13 @@ class bitget extends bitget$1["default"] {
1762
1795
  * @method
1763
1796
  * @name bitget#watchMyTrades
1764
1797
  * @description watches trades made by the user
1765
- * @see https://www.bitget.com/api-doc/contract/websocket/private/Order-Channel
1798
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Fill-Channel
1799
+ * @see https://www.bitget.com/api-doc/uta/websocket/private/Fill-Channel
1766
1800
  * @param {str} symbol unified market symbol
1767
1801
  * @param {int} [since] the earliest time in ms to fetch trades for
1768
1802
  * @param {int} [limit] the maximum number of trades structures to retrieve
1769
1803
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1804
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
1770
1805
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1771
1806
  */
1772
1807
  async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -1781,18 +1816,29 @@ class bitget extends bitget$1["default"] {
1781
1816
  let type = undefined;
1782
1817
  [type, params] = this.handleMarketTypeAndParams('watchMyTrades', market, params);
1783
1818
  let instType = undefined;
1819
+ let uta = undefined;
1820
+ [uta, params] = this.handleOptionAndParams(params, 'watchMyTrades', 'uta', false);
1784
1821
  if (market === undefined && type === 'spot') {
1785
- instType = 'spot';
1822
+ instType = 'SPOT';
1786
1823
  }
1787
1824
  else {
1788
- [instType, params] = this.getInstType(market, false, params);
1825
+ [instType, params] = this.getInstType(market, uta, params);
1826
+ }
1827
+ if (uta) {
1828
+ instType = 'UTA';
1789
1829
  }
1790
1830
  const subscriptionHash = 'fill:' + instType;
1791
1831
  const args = {
1792
1832
  'instType': instType,
1793
- 'channel': 'fill',
1794
- 'instId': 'default',
1795
1833
  };
1834
+ const topicOrChannel = uta ? 'topic' : 'channel';
1835
+ args[topicOrChannel] = 'fill';
1836
+ if (!uta) {
1837
+ args['instId'] = 'default';
1838
+ }
1839
+ else {
1840
+ params['uta'] = true;
1841
+ }
1796
1842
  const trades = await this.watchPrivate(messageHash, subscriptionHash, args, params);
1797
1843
  if (this.newUpdates) {
1798
1844
  limit = trades.getLimit(symbol, limit);
@@ -1871,6 +1917,44 @@ class bitget extends bitget$1["default"] {
1871
1917
  // "ts": 1714471276629
1872
1918
  // }
1873
1919
  //
1920
+ // uta
1921
+ //
1922
+ // {
1923
+ // "data": [
1924
+ // {
1925
+ // "symbol": "BTCUSDT",
1926
+ // "orderType": "market",
1927
+ // "updatedTime": "1736378720623",
1928
+ // "side": "buy",
1929
+ // "orderId": "1288888888888888888",
1930
+ // "execPnl": "0",
1931
+ // "feeDetail": [
1932
+ // {
1933
+ // "feeCoin": "USDT",
1934
+ // "fee": "0.569958"
1935
+ // }
1936
+ // ],
1937
+ // "execTime": "1736378720623",
1938
+ // "tradeScope": "taker",
1939
+ // "tradeSide": "open",
1940
+ // "execId": "1288888888888888888",
1941
+ // "execLinkId": "1288888888888888888",
1942
+ // "execPrice": "94993",
1943
+ // "holdSide": "long",
1944
+ // "execValue": "949.93",
1945
+ // "category": "USDT-FUTURES",
1946
+ // "execQty": "0.01",
1947
+ // "clientOid": "1288888888888888889"
1948
+ // }
1949
+ // ],
1950
+ // "arg": {
1951
+ // "instType": "UTA",
1952
+ // "topic": "fill"
1953
+ // },
1954
+ // "action": "snapshot",
1955
+ // "ts": 1733904123981
1956
+ // }
1957
+ //
1874
1958
  if (this.myTrades === undefined) {
1875
1959
  const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
1876
1960
  this.myTrades = new Cache.ArrayCache(limit);
@@ -2133,12 +2217,25 @@ class bitget extends bitget$1["default"] {
2133
2217
  return await future;
2134
2218
  }
2135
2219
  async watchPrivate(messageHash, subscriptionHash, args, params = {}) {
2136
- let url = this.urls['api']['ws']['private'];
2220
+ let uta = undefined;
2221
+ let url = undefined;
2222
+ [uta, params] = this.handleOptionAndParams(params, 'watchPrivate', 'uta', false);
2223
+ if (uta) {
2224
+ url = this.urls['api']['ws']['utaPrivate'];
2225
+ }
2226
+ else {
2227
+ url = this.urls['api']['ws']['private'];
2228
+ }
2137
2229
  const sandboxMode = this.safeBool2(this.options, 'sandboxMode', 'sandbox', false);
2138
2230
  if (sandboxMode) {
2139
2231
  const instType = this.safeString(args, 'instType');
2140
2232
  if ((instType !== 'SCOIN-FUTURES') && (instType !== 'SUSDT-FUTURES') && (instType !== 'SUSDC-FUTURES')) {
2141
- url = this.urls['api']['demo']['private'];
2233
+ if (uta) {
2234
+ url = this.urls['api']['demo']['utaPrivate'];
2235
+ }
2236
+ else {
2237
+ url = this.urls['api']['demo']['private'];
2238
+ }
2142
2239
  }
2143
2240
  }
2144
2241
  await this.authenticate({ 'url': url });
@@ -1243,11 +1243,13 @@ class bybit extends bybit$1["default"] {
1243
1243
  * @name bybit#watchMyTrades
1244
1244
  * @description watches information on multiple trades made by the user
1245
1245
  * @see https://bybit-exchange.github.io/docs/v5/websocket/private/execution
1246
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/fast-execution
1246
1247
  * @param {string} symbol unified market symbol of the market orders were made in
1247
1248
  * @param {int} [since] the earliest time in ms to fetch orders for
1248
1249
  * @param {int} [limit] the maximum number of order structures to retrieve
1249
1250
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1250
1251
  * @param {boolean} [params.unifiedMargin] use unified margin account
1252
+ * @param {boolean} [params.executionFast] use fast execution
1251
1253
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1252
1254
  */
1253
1255
  async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -1265,7 +1267,12 @@ class bybit extends bybit$1["default"] {
1265
1267
  'unified': 'execution',
1266
1268
  'usdc': 'user.openapi.perp.trade',
1267
1269
  };
1268
- const topic = this.safeValue(topicByMarket, this.getPrivateType(url));
1270
+ let topic = this.safeValue(topicByMarket, this.getPrivateType(url));
1271
+ let executionFast = false;
1272
+ [executionFast, params] = this.handleOptionAndParams(params, 'watchMyTrades', 'executionFast', false);
1273
+ if (executionFast) {
1274
+ topic = 'execution.fast';
1275
+ }
1269
1276
  const trades = await this.watchTopics(url, [messageHash], [topic], params);
1270
1277
  if (this.newUpdates) {
1271
1278
  limit = trades.getLimit(symbol, limit);
@@ -1277,9 +1284,11 @@ class bybit extends bybit$1["default"] {
1277
1284
  * @name bybit#unWatchMyTrades
1278
1285
  * @description unWatches information on multiple trades made by the user
1279
1286
  * @see https://bybit-exchange.github.io/docs/v5/websocket/private/execution
1287
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/fast-execution
1280
1288
  * @param {string} symbol unified market symbol of the market orders were made in
1281
1289
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1282
1290
  * @param {boolean} [params.unifiedMargin] use unified margin account
1291
+ * @param {boolean} [params.executionFast] use fast execution
1283
1292
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1284
1293
  */
1285
1294
  async unWatchMyTrades(symbol = undefined, params = {}) {
@@ -1297,7 +1306,12 @@ class bybit extends bybit$1["default"] {
1297
1306
  'unified': 'execution',
1298
1307
  'usdc': 'user.openapi.perp.trade',
1299
1308
  };
1300
- const topic = this.safeValue(topicByMarket, this.getPrivateType(url));
1309
+ let topic = this.safeValue(topicByMarket, this.getPrivateType(url));
1310
+ let executionFast = false;
1311
+ [executionFast, params] = this.handleOptionAndParams(params, 'watchMyTrades', 'executionFast', false);
1312
+ if (executionFast) {
1313
+ topic = 'execution.fast';
1314
+ }
1301
1315
  return await this.unWatchTopics(url, 'myTrades', [], [messageHash], [subHash], [topic], params);
1302
1316
  }
1303
1317
  handleMyTrades(client, message) {
@@ -1363,8 +1377,31 @@ class bybit extends bybit$1["default"] {
1363
1377
  // ]
1364
1378
  // }
1365
1379
  //
1380
+ // execution.fast
1381
+ //
1382
+ // {
1383
+ // "topic": "execution.fast",
1384
+ // "creationTime": 1757405601981,
1385
+ // "data": [
1386
+ // {
1387
+ // "category": "linear",
1388
+ // "symbol": "BTCUSDT",
1389
+ // "execId": "ffcac6ac-7571-536d-a28a-847dd7d08a0f",
1390
+ // "execPrice": "112529.6",
1391
+ // "execQty": "0.001",
1392
+ // "orderId": "6e25ab73-7a55-4ae7-adc2-8ea95f167c85",
1393
+ // "isMaker": false,
1394
+ // "orderLinkId": "test-00001",
1395
+ // "side": "Buy",
1396
+ // "execTime": "1757405601977",
1397
+ // "seq": 9515624038
1398
+ // }
1399
+ // ]
1400
+ // }
1401
+ //
1366
1402
  const topic = this.safeString(message, 'topic');
1367
1403
  const spot = topic === 'ticketInfo';
1404
+ const executionFast = topic === 'execution.fast';
1368
1405
  let data = this.safeValue(message, 'data', []);
1369
1406
  if (!Array.isArray(data)) {
1370
1407
  data = this.safeValue(data, 'result', []);
@@ -1379,12 +1416,15 @@ class bybit extends bybit$1["default"] {
1379
1416
  for (let i = 0; i < data.length; i++) {
1380
1417
  const rawTrade = data[i];
1381
1418
  let parsed = undefined;
1382
- if (spot) {
1419
+ if (spot && !executionFast) {
1383
1420
  parsed = this.parseWsTrade(rawTrade);
1384
1421
  }
1385
1422
  else {
1386
1423
  // filter unified trades
1387
- const execType = this.safeString(rawTrade, 'execType', '');
1424
+ let execType = this.safeString(rawTrade, 'execType', '');
1425
+ if (executionFast) {
1426
+ execType = 'Trade';
1427
+ }
1388
1428
  if (!this.inArray(execType, filterExecTypes)) {
1389
1429
  continue;
1390
1430
  }
@@ -2340,12 +2380,13 @@ class bybit extends bybit$1["default"] {
2340
2380
  }
2341
2381
  }
2342
2382
  handleMessage(client, message) {
2383
+ const topic = this.safeString2(message, 'topic', 'op', '');
2343
2384
  if (this.handleErrorMessage(client, message)) {
2344
2385
  return;
2345
2386
  }
2346
2387
  // contract pong
2347
2388
  const ret_msg = this.safeString(message, 'ret_msg');
2348
- if (ret_msg === 'pong') {
2389
+ if ((ret_msg === 'pong') || (topic === 'pong')) {
2349
2390
  this.handlePong(client, message);
2350
2391
  return;
2351
2392
  }
@@ -2357,11 +2398,10 @@ class bybit extends bybit$1["default"] {
2357
2398
  }
2358
2399
  // pong
2359
2400
  const event = this.safeString(message, 'event');
2360
- if (event === 'sub') {
2401
+ if (event === 'sub' || (topic === 'subscribe')) {
2361
2402
  this.handleSubscriptionStatus(client, message);
2362
2403
  return;
2363
2404
  }
2364
- const topic = this.safeString2(message, 'topic', 'op', '');
2365
2405
  const methods = {
2366
2406
  'orderbook': this.handleOrderBook,
2367
2407
  'kline': this.handleOHLCV,
@@ -2374,6 +2414,7 @@ class bybit extends bybit$1["default"] {
2374
2414
  'wallet': this.handleBalance,
2375
2415
  'outboundAccountInfo': this.handleBalance,
2376
2416
  'execution': this.handleMyTrades,
2417
+ 'execution.fast': this.handleMyTrades,
2377
2418
  'ticketInfo': this.handleMyTrades,
2378
2419
  'user.openapi.perp.trade': this.handleMyTrades,
2379
2420
  'position': this.handlePositions,
@@ -2423,6 +2464,14 @@ class bybit extends bybit$1["default"] {
2423
2464
  //
2424
2465
  // { pong: 1653296711335 }
2425
2466
  //
2467
+ //
2468
+ // {
2469
+ // "req_id": "2",
2470
+ // "op": "pong",
2471
+ // "args": [ "1757405570352" ],
2472
+ // "conn_id": "d266o6hqo29sqmnq4vk0-1yus1"
2473
+ // }
2474
+ //
2426
2475
  client.lastPong = this.safeInteger(message, 'pong');
2427
2476
  return message;
2428
2477
  }
@@ -2442,6 +2491,13 @@ class bybit extends bybit$1["default"] {
2442
2491
  // "connId":"cojifin88smerbj9t560-404"
2443
2492
  // }
2444
2493
  //
2494
+ // {
2495
+ // "success": true,
2496
+ // "ret_msg": "",
2497
+ // "op": "auth",
2498
+ // "conn_id": "d266o6hqo29sqmnq4vk0-1yus1"
2499
+ // }
2500
+ //
2445
2501
  const success = this.safeValue(message, 'success');
2446
2502
  const code = this.safeInteger(message, 'retCode');
2447
2503
  const messageHash = 'authenticated';
@@ -2507,7 +2563,7 @@ class bybit extends bybit$1["default"] {
2507
2563
  for (let j = 0; j < messageHashes.length; j++) {
2508
2564
  const unsubHash = messageHashes[j];
2509
2565
  const subHash = subMessageHashes[j];
2510
- const usePrefix = (subHash === 'orders') || (subHash === 'myTrades');
2566
+ const usePrefix = (subHash === 'orders') || (subHash === 'myTrades') || (subHash === 'positions');
2511
2567
  this.cleanUnsubscription(client, subHash, unsubHash, usePrefix);
2512
2568
  }
2513
2569
  this.cleanCache(subscription);
@@ -755,7 +755,6 @@ class coinex extends coinex$1["default"] {
755
755
  let type = undefined;
756
756
  let callerMethodName = undefined;
757
757
  [callerMethodName, params] = this.handleParamString(params, 'callerMethodName', 'watchOrderBookForSymbols');
758
- [type, params] = this.handleMarketTypeAndParams(callerMethodName, undefined, params);
759
758
  const options = this.safeDict(this.options, 'watchOrderBook', {});
760
759
  const limits = this.safeList(options, 'limits', []);
761
760
  if (limit === undefined) {
@@ -772,17 +771,16 @@ class coinex extends coinex$1["default"] {
772
771
  }
773
772
  params = this.omit(params, 'aggregation');
774
773
  const symbolsDefined = (symbols !== undefined);
775
- if (symbolsDefined) {
776
- for (let i = 0; i < symbols.length; i++) {
777
- const symbol = symbols[i];
778
- market = this.market(symbol);
779
- messageHashes.push('orderbook:' + market['symbol']);
780
- watchOrderBookSubscriptions[symbol] = [market['id'], limit, aggregation, true];
781
- }
774
+ if (!symbolsDefined) {
775
+ throw new errors.ArgumentsRequired(this.id + ' watchOrderBookForSymbols() requires a symbol argument');
782
776
  }
783
- else {
784
- messageHashes.push('orderbook');
777
+ for (let i = 0; i < symbols.length; i++) {
778
+ const symbol = symbols[i];
779
+ market = this.market(symbol);
780
+ messageHashes.push('orderbook:' + market['symbol']);
781
+ watchOrderBookSubscriptions[symbol] = [market['id'], limit, aggregation, true];
785
782
  }
783
+ [type, params] = this.handleMarketTypeAndParams(callerMethodName, market, params);
786
784
  const marketList = Object.values(watchOrderBookSubscriptions);
787
785
  const subscribe = {
788
786
  'method': 'depth.subscribe',
@@ -849,7 +847,8 @@ class coinex extends coinex$1["default"] {
849
847
  // "id": null
850
848
  // }
851
849
  //
852
- const defaultType = this.safeString(this.options, 'defaultType');
850
+ const isSpot = client.url.indexOf('spot') > -1;
851
+ const defaultType = isSpot ? 'spot' : 'swap';
853
852
  const data = this.safeDict(message, 'data', {});
854
853
  const depth = this.safeDict(data, 'depth', {});
855
854
  const marketId = this.safeString(data, 'market');
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import type { Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarketMarginModes, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers, LongShortRatio, OrderBooks, OpenInterests, ConstructorArgs } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, RestrictedLocation, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
7
- declare const version = "4.5.2";
7
+ declare const version = "4.5.3";
8
8
  import alpaca from './src/alpaca.js';
9
9
  import apex from './src/apex.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, RestrictedLocation, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.5.2';
41
+ const version = '4.5.3';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import alpaca from './src/alpaca.js';
@@ -20,6 +20,7 @@ interface okx {
20
20
  publicGetMarketOpenOracle(params?: {}): Promise<implicitReturnType>;
21
21
  publicGetMarketExchangeRate(params?: {}): Promise<implicitReturnType>;
22
22
  publicGetMarketIndexComponents(params?: {}): Promise<implicitReturnType>;
23
+ publicGetPublicMarketDataHistory(params?: {}): Promise<implicitReturnType>;
23
24
  publicGetPublicEconomicCalendar(params?: {}): Promise<implicitReturnType>;
24
25
  publicGetMarketBlockTickers(params?: {}): Promise<implicitReturnType>;
25
26
  publicGetMarketBlockTicker(params?: {}): Promise<implicitReturnType>;
@@ -20,6 +20,7 @@ interface Exchange {
20
20
  publicGetMarketOpenOracle(params?: {}): Promise<implicitReturnType>;
21
21
  publicGetMarketExchangeRate(params?: {}): Promise<implicitReturnType>;
22
22
  publicGetMarketIndexComponents(params?: {}): Promise<implicitReturnType>;
23
+ publicGetPublicMarketDataHistory(params?: {}): Promise<implicitReturnType>;
23
24
  publicGetPublicEconomicCalendar(params?: {}): Promise<implicitReturnType>;
24
25
  publicGetMarketBlockTickers(params?: {}): Promise<implicitReturnType>;
25
26
  publicGetMarketBlockTicker(params?: {}): Promise<implicitReturnType>;
@@ -20,6 +20,7 @@ interface okx {
20
20
  publicGetMarketOpenOracle(params?: {}): Promise<implicitReturnType>;
21
21
  publicGetMarketExchangeRate(params?: {}): Promise<implicitReturnType>;
22
22
  publicGetMarketIndexComponents(params?: {}): Promise<implicitReturnType>;
23
+ publicGetPublicMarketDataHistory(params?: {}): Promise<implicitReturnType>;
23
24
  publicGetPublicEconomicCalendar(params?: {}): Promise<implicitReturnType>;
24
25
  publicGetMarketBlockTickers(params?: {}): Promise<implicitReturnType>;
25
26
  publicGetMarketBlockTicker(params?: {}): Promise<implicitReturnType>;
@@ -568,6 +568,7 @@ export default class Exchange {
568
568
  safeCurrencyStructure(currency: object): CurrencyInterface;
569
569
  safeMarketStructure(market?: Dict): MarketInterface;
570
570
  setMarkets(markets: any, currencies?: any): Dictionary<any>;
571
+ setMarketsFromExchange(sourceExchange: any): this;
571
572
  getDescribeForExtendedWsExchange(currentRestInstance: any, parentRestInstance: any, wsBaseDescribe: Dictionary<any>): any;
572
573
  safeBalance(balance: Dict): Balances;
573
574
  safeOrder(order: Dict, market?: Market): Order;
@@ -630,7 +631,9 @@ export default class Exchange {
630
631
  safePosition(position: Dict): Position;
631
632
  parsePositions(positions: any[], symbols?: string[], params?: {}): Position[];
632
633
  parseAccounts(accounts: any[], params?: {}): Account[];
634
+ parseTradesHelper(isWs: boolean, trades: any[], market?: Market, since?: Int, limit?: Int, params?: {}): Trade[];
633
635
  parseTrades(trades: any[], market?: Market, since?: Int, limit?: Int, params?: {}): Trade[];
636
+ parseWsTrades(trades: any[], market?: Market, since?: Int, limit?: Int, params?: {}): Trade[];
634
637
  parseTransactions(transactions: any[], currency?: Currency, since?: Int, limit?: Int, params?: {}): Transaction[];
635
638
  parseTransfers(transfers: any[], currency?: Currency, since?: Int, limit?: Int, params?: {}): TransferEntry[];
636
639
  parseLedger(data: any, currency?: Currency, since?: Int, limit?: Int, params?: {}): LedgerEntry[];
@@ -856,6 +859,7 @@ export default class Exchange {
856
859
  parseFundingRates(response: any, symbols?: Strings): FundingRates;
857
860
  parseLongShortRatio(info: Dict, market?: Market): LongShortRatio;
858
861
  parseLongShortRatioHistory(response: any, market?: any, since?: Int, limit?: Int): LongShortRatio[];
862
+ handleTriggerPricesAndParams(symbol: any, params: any, omitParams?: boolean): any[];
859
863
  handleTriggerDirectionAndParams(params: any, exchangeSpecificKey?: Str, allowEmpty?: Bool): any[];
860
864
  handleTriggerAndParams(params: any): any[];
861
865
  isTriggerOrder(params: any): any[];
@@ -2432,9 +2432,9 @@ export default class Exchange {
2432
2432
  parseToNumeric(number) {
2433
2433
  const stringVersion = this.numberToString(number); // this will convert 1.0 and 1 to "1" and 1.1 to "1.1"
2434
2434
  // keep this in mind:
2435
- // in JS: 1 == 1.0 is true; 1 === 1.0 is true
2435
+ // in JS: 1 === 1.0 is true
2436
2436
  // in Python: 1 == 1.0 is true
2437
- // in PHP 1 == 1.0 is true, but 1 === 1.0 is false.
2437
+ // in PHP: 1 == 1.0 is true, but 1 === 1.0 is false.
2438
2438
  if (stringVersion.indexOf('.') >= 0) {
2439
2439
  return parseFloat(stringVersion);
2440
2440
  }
@@ -2949,6 +2949,26 @@ export default class Exchange {
2949
2949
  this.codes = Object.keys(currenciesSortedByCode);
2950
2950
  return this.markets;
2951
2951
  }
2952
+ setMarketsFromExchange(sourceExchange) {
2953
+ // Validate that both exchanges are of the same type
2954
+ if (this.id !== sourceExchange.id) {
2955
+ throw new ArgumentsRequired(this.id + ' shareMarkets() can only share markets with exchanges of the same type (got ' + sourceExchange['id'] + ')');
2956
+ }
2957
+ // Validate that source exchange has loaded markets
2958
+ if (!sourceExchange.markets) {
2959
+ throw new ExchangeError('setMarketsFromExchange() source exchange must have loaded markets first. Can call by using loadMarkets function');
2960
+ }
2961
+ // Set all market-related data
2962
+ this.markets = sourceExchange.markets;
2963
+ this.markets_by_id = sourceExchange.markets_by_id;
2964
+ this.symbols = sourceExchange.symbols;
2965
+ this.ids = sourceExchange.ids;
2966
+ this.currencies = sourceExchange.currencies;
2967
+ this.baseCurrencies = sourceExchange.baseCurrencies;
2968
+ this.quoteCurrencies = sourceExchange.quoteCurrencies;
2969
+ this.codes = sourceExchange.codes;
2970
+ return this;
2971
+ }
2952
2972
  getDescribeForExtendedWsExchange(currentRestInstance, parentRestInstance, wsBaseDescribe) {
2953
2973
  const extendedRestDescribe = this.deepExtend(parentRestInstance.describe(), currentRestInstance.describe());
2954
2974
  const superWithRestDescribe = this.deepExtend(extendedRestDescribe, wsBaseDescribe);
@@ -4227,17 +4247,30 @@ export default class Exchange {
4227
4247
  }
4228
4248
  return result;
4229
4249
  }
4230
- parseTrades(trades, market = undefined, since = undefined, limit = undefined, params = {}) {
4250
+ parseTradesHelper(isWs, trades, market = undefined, since = undefined, limit = undefined, params = {}) {
4231
4251
  trades = this.toArray(trades);
4232
4252
  let result = [];
4233
4253
  for (let i = 0; i < trades.length; i++) {
4234
- const trade = this.extend(this.parseTrade(trades[i], market), params);
4254
+ let parsed = undefined;
4255
+ if (isWs) {
4256
+ parsed = this.parseWsTrade(trades[i], market);
4257
+ }
4258
+ else {
4259
+ parsed = this.parseTrade(trades[i], market);
4260
+ }
4261
+ const trade = this.extend(parsed, params);
4235
4262
  result.push(trade);
4236
4263
  }
4237
4264
  result = this.sortBy2(result, 'timestamp', 'id');
4238
4265
  const symbol = (market !== undefined) ? market['symbol'] : undefined;
4239
4266
  return this.filterBySymbolSinceLimit(result, symbol, since, limit);
4240
4267
  }
4268
+ parseTrades(trades, market = undefined, since = undefined, limit = undefined, params = {}) {
4269
+ return this.parseTradesHelper(false, trades, market, since, limit, params);
4270
+ }
4271
+ parseWsTrades(trades, market = undefined, since = undefined, limit = undefined, params = {}) {
4272
+ return this.parseTradesHelper(true, trades, market, since, limit, params);
4273
+ }
4241
4274
  parseTransactions(transactions, currency = undefined, since = undefined, limit = undefined, params = {}) {
4242
4275
  transactions = this.toArray(transactions);
4243
4276
  let result = [];
@@ -6193,6 +6226,35 @@ export default class Exchange {
6193
6226
  const symbol = (market === undefined) ? undefined : market['symbol'];
6194
6227
  return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
6195
6228
  }
6229
+ handleTriggerPricesAndParams(symbol, params, omitParams = true) {
6230
+ //
6231
+ const triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
6232
+ let triggerPriceStr = undefined;
6233
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
6234
+ let stopLossPriceStr = undefined;
6235
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
6236
+ let takeProfitPriceStr = undefined;
6237
+ //
6238
+ if (triggerPrice !== undefined) {
6239
+ if (omitParams) {
6240
+ params = this.omit(params, ['triggerPrice', 'stopPrice']);
6241
+ }
6242
+ triggerPriceStr = this.priceToPrecision(symbol, parseFloat(triggerPrice));
6243
+ }
6244
+ if (stopLossPrice !== undefined) {
6245
+ if (omitParams) {
6246
+ params = this.omit(params, 'stopLossPrice');
6247
+ }
6248
+ stopLossPriceStr = this.priceToPrecision(symbol, parseFloat(stopLossPrice));
6249
+ }
6250
+ if (takeProfitPrice !== undefined) {
6251
+ if (omitParams) {
6252
+ params = this.omit(params, 'takeProfitPrice');
6253
+ }
6254
+ takeProfitPriceStr = this.priceToPrecision(symbol, parseFloat(takeProfitPrice));
6255
+ }
6256
+ return [triggerPriceStr, stopLossPriceStr, takeProfitPriceStr, params];
6257
+ }
6196
6258
  handleTriggerDirectionAndParams(params, exchangeSpecificKey = undefined, allowEmpty = false) {
6197
6259
  /**
6198
6260
  * @ignore
@@ -7389,7 +7451,7 @@ export default class Exchange {
7389
7451
  const clients = Object.values(this.clients);
7390
7452
  for (let i = 0; i < clients.length; i++) {
7391
7453
  const client = clients[i];
7392
- const futures = this.safeDict(client, 'futures');
7454
+ const futures = client.futures;
7393
7455
  if ((futures !== undefined) && ('fetchPositionsSnapshot' in futures)) {
7394
7456
  delete futures['fetchPositionsSnapshot'];
7395
7457
  }
@@ -1,4 +1,5 @@
1
1
  import { concatBytes } from '../../static_dependencies/noble-curves/abstract/utils.js';
2
2
  declare const json: (data: any, params?: any) => string, isJsonEncodedObject: (object: any) => boolean, binaryToString: (data: Uint8Array) => string, stringToBinary: (str: string) => Uint8Array, stringToBase64: (string: string) => string, base64ToString: (string: string) => string, base64ToBinary: (str: string) => Uint8Array, binaryToBase64: (data: Uint8Array) => string, base16ToBinary: (str: string) => Uint8Array, binaryToBase16: (data: Uint8Array) => string, base58ToBinary: (str: string) => Uint8Array, binaryToBase58: (data: Uint8Array) => string, binaryConcat: typeof concatBytes, binaryConcatArray: (arr: any[]) => Uint8Array, urlencode: (object: object, sort?: boolean) => string, urlencodeNested: (object: object) => string, urlencodeWithArrayRepeat: (object: object) => string, rawencode: (object: object, sort?: boolean) => string, encode: (str: string) => Uint8Array, decode: (data: Uint8Array) => string, urlencodeBase64: (payload: string | Uint8Array) => string, numberToLE: (n: number, padding: number) => Uint8Array, numberToBE: (n: number, padding: number) => Uint8Array;
3
3
  declare function packb(req: any): Uint8Array;
4
- export { json, isJsonEncodedObject, binaryToString, stringToBinary, stringToBase64, base64ToBinary, base64ToString, binaryToBase64, base16ToBinary, binaryToBase16, binaryConcat, binaryConcatArray, urlencode, urlencodeWithArrayRepeat, rawencode, encode, decode, urlencodeBase64, numberToLE, numberToBE, base58ToBinary, binaryToBase58, urlencodeNested, packb };
4
+ declare function base64ToBase64Url(base64: string, stripPadding?: boolean): string;
5
+ export { json, isJsonEncodedObject, binaryToString, stringToBinary, stringToBase64, base64ToBinary, base64ToString, binaryToBase64, base16ToBinary, binaryToBase16, binaryConcat, binaryConcatArray, base64ToBase64Url, urlencode, urlencodeWithArrayRepeat, rawencode, encode, decode, urlencodeBase64, numberToLE, numberToBE, base58ToBinary, binaryToBase58, urlencodeNested, packb };
@@ -26,7 +26,14 @@ const json = (data, params = undefined) => JSON.stringify(data), isJsonEncodedOb
26
26
  function packb(req) {
27
27
  return serialize(req);
28
28
  }
29
- export { json, isJsonEncodedObject, binaryToString, stringToBinary, stringToBase64, base64ToBinary, base64ToString, binaryToBase64, base16ToBinary, binaryToBase16, binaryConcat, binaryConcatArray, urlencode, urlencodeWithArrayRepeat, rawencode, encode, decode
29
+ function base64ToBase64Url(base64, stripPadding = true) {
30
+ let base64url = base64.replace(/\+/g, "-").replace(/\//g, "_");
31
+ if (stripPadding) {
32
+ base64url = base64url.replace(/=+$/, "");
33
+ }
34
+ return base64url;
35
+ }
36
+ export { json, isJsonEncodedObject, binaryToString, stringToBinary, stringToBase64, base64ToBinary, base64ToString, binaryToBase64, base16ToBinary, binaryToBase16, binaryConcat, binaryConcatArray, base64ToBase64Url, urlencode, urlencodeWithArrayRepeat, rawencode, encode, decode
30
37
  // Url-safe-base64 without equals signs, with + replaced by - and slashes replaced by underscores
31
38
  , urlencodeBase64, numberToLE, numberToBE, base58ToBinary, binaryToBase58, urlencodeNested, packb };
32
39
  /* ------------------------------------------------------------------------ */