ccxt 4.5.40 → 4.5.42

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 (106) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +18 -18
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/lighter.js +11 -0
  5. package/dist/cjs/src/ascendex.js +73 -1
  6. package/dist/cjs/src/base/Exchange.js +149 -17
  7. package/dist/cjs/src/base/functions/generic.js +1 -0
  8. package/dist/cjs/src/base/functions/io.js +160 -0
  9. package/dist/cjs/src/base/functions.js +6 -0
  10. package/dist/cjs/src/base/ws/Client.js +1 -0
  11. package/dist/cjs/src/base/ws/WsClient.js +1 -0
  12. package/dist/cjs/src/binance.js +1 -0
  13. package/dist/cjs/src/bingx.js +13 -3
  14. package/dist/cjs/src/bitmex.js +20 -0
  15. package/dist/cjs/src/blofin.js +2 -2
  16. package/dist/cjs/src/bybit.js +1 -1
  17. package/dist/cjs/src/coinspot.js +7 -2
  18. package/dist/cjs/src/delta.js +1 -1
  19. package/dist/cjs/src/gate.js +11 -4
  20. package/dist/cjs/src/gemini.js +76 -1
  21. package/dist/cjs/src/htx.js +2 -2
  22. package/dist/cjs/src/hyperliquid.js +20 -7
  23. package/dist/cjs/src/independentreserve.js +7 -7
  24. package/dist/cjs/src/kraken.js +1 -1
  25. package/dist/cjs/src/krakenfutures.js +96 -5
  26. package/dist/cjs/src/kucoin.js +3 -3
  27. package/dist/cjs/src/kucoinfutures.js +1 -1
  28. package/dist/cjs/src/lighter.js +2931 -0
  29. package/dist/cjs/src/mexc.js +0 -1
  30. package/dist/cjs/src/phemex.js +1 -1
  31. package/dist/cjs/src/pro/binance.js +2 -2
  32. package/dist/cjs/src/pro/bingx.js +215 -2
  33. package/dist/cjs/src/pro/bitget.js +1 -0
  34. package/dist/cjs/src/pro/defx.js +1 -1
  35. package/dist/cjs/src/pro/kucoinfutures.js +1 -1
  36. package/dist/cjs/src/pro/lighter.js +787 -0
  37. package/dist/cjs/src/pro/mexc.js +1 -1
  38. package/dist/cjs/src/pro/paradex.js +1 -1
  39. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +1 -0
  40. package/dist/cjs/src/static_dependencies/ethers/address/address.js +1 -0
  41. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +1 -0
  42. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +1 -0
  43. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +1 -0
  44. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +1 -0
  45. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +1 -0
  46. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +1 -0
  47. package/dist/cjs/src/static_dependencies/ethers/fragments.js +1 -0
  48. package/dist/cjs/src/static_dependencies/ethers/index.js +1 -0
  49. package/dist/cjs/src/static_dependencies/ethers/interface.js +1 -0
  50. package/dist/cjs/src/static_dependencies/ethers/typed.js +1 -0
  51. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +1 -0
  52. package/dist/cjs/src/whitebit.js +118 -16
  53. package/dist/cjs/src/woo.js +1 -1
  54. package/js/ccxt.d.ts +8 -2
  55. package/js/ccxt.js +6 -2
  56. package/js/src/abstract/gemini.d.ts +27 -0
  57. package/js/src/abstract/lighter.d.ts +53 -0
  58. package/js/src/abstract/lighter.js +11 -0
  59. package/js/src/ascendex.d.ts +12 -1
  60. package/js/src/ascendex.js +73 -1
  61. package/js/src/base/Exchange.d.ts +18 -6
  62. package/js/src/base/Exchange.js +154 -21
  63. package/js/src/base/functions/generic.js +1 -0
  64. package/js/src/base/functions/io.d.ts +32 -0
  65. package/js/src/base/functions/io.js +137 -0
  66. package/js/src/base/functions.d.ts +1 -0
  67. package/js/src/base/functions.js +1 -0
  68. package/js/src/binance.d.ts +1 -0
  69. package/js/src/binance.js +1 -0
  70. package/js/src/bingx.js +13 -3
  71. package/js/src/bitmex.js +20 -0
  72. package/js/src/blofin.js +2 -2
  73. package/js/src/bybit.js +1 -1
  74. package/js/src/coinspot.js +7 -2
  75. package/js/src/delta.js +1 -1
  76. package/js/src/gate.d.ts +1 -0
  77. package/js/src/gate.js +11 -4
  78. package/js/src/gemini.d.ts +11 -0
  79. package/js/src/gemini.js +76 -1
  80. package/js/src/htx.js +2 -2
  81. package/js/src/hyperliquid.js +20 -7
  82. package/js/src/independentreserve.js +7 -7
  83. package/js/src/kraken.js +1 -1
  84. package/js/src/krakenfutures.d.ts +1 -1
  85. package/js/src/krakenfutures.js +96 -5
  86. package/js/src/kucoin.d.ts +3 -3
  87. package/js/src/kucoin.js +3 -3
  88. package/js/src/kucoinfutures.js +1 -1
  89. package/js/src/lighter.d.ts +424 -0
  90. package/js/src/lighter.js +2930 -0
  91. package/js/src/mexc.js +0 -1
  92. package/js/src/phemex.js +1 -1
  93. package/js/src/pro/binance.js +2 -2
  94. package/js/src/pro/bingx.d.ts +17 -1
  95. package/js/src/pro/bingx.js +216 -3
  96. package/js/src/pro/bitget.js +1 -0
  97. package/js/src/pro/defx.js +1 -1
  98. package/js/src/pro/kucoinfutures.js +1 -1
  99. package/js/src/pro/lighter.d.ts +161 -0
  100. package/js/src/pro/lighter.js +786 -0
  101. package/js/src/pro/mexc.js +1 -1
  102. package/js/src/pro/paradex.js +1 -1
  103. package/js/src/whitebit.d.ts +2 -1
  104. package/js/src/whitebit.js +118 -16
  105. package/js/src/woo.js +1 -1
  106. package/package.json +1 -1
@@ -4714,7 +4714,6 @@ class mexc extends mexc$1["default"] {
4714
4714
  const address = this.safeString(depositAddress, 'address');
4715
4715
  const currencyId = this.safeString(depositAddress, 'coin');
4716
4716
  const networkId = this.safeString(depositAddress, 'netWork');
4717
- this.checkAddress(address);
4718
4717
  return {
4719
4718
  'info': depositAddress,
4720
4719
  'currency': this.safeCurrencyCode(currencyId, currency),
@@ -89,8 +89,8 @@ class phemex extends phemex$1["default"] {
89
89
  'fetchOrderBook': true,
90
90
  'fetchOrders': true,
91
91
  'fetchPositionADLRank': true,
92
- 'fetchPositionsADLRank': true,
93
92
  'fetchPositions': true,
93
+ 'fetchPositionsADLRank': true,
94
94
  'fetchPositionsRisk': false,
95
95
  'fetchPremiumIndexOHLCV': false,
96
96
  'fetchTicker': true,
@@ -156,7 +156,7 @@ class binance extends binance$1["default"] {
156
156
  'name': 'ticker', // ticker or miniTicker or ticker_<window_size>
157
157
  },
158
158
  'watchTickers': {
159
- 'name': 'ticker', // ticker or miniTicker or ticker_<window_size>
159
+ 'name': 'miniTicker', // miniTicker or ticker_<window_size>
160
160
  },
161
161
  'watchOHLCV': {
162
162
  'name': 'kline', // or indexPriceKline or markPriceKline (coin-m futures)
@@ -1867,7 +1867,7 @@ class binance extends binance$1["default"] {
1867
1867
  */
1868
1868
  async watchTickers(symbols = undefined, params = {}) {
1869
1869
  let channelName = undefined;
1870
- [channelName, params] = this.handleOptionAndParams(params, 'watchTickers', 'name', 'ticker');
1870
+ [channelName, params] = this.handleOptionAndParams(params, 'watchTickers', 'name', 'miniTicker');
1871
1871
  if (channelName === 'bookTicker') {
1872
1872
  throw new errors.BadRequest(this.id + ' deprecation notice - to subscribe for bids-asks, use watch_bids_asks() method instead');
1873
1873
  }
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var bingx$1 = require('../bingx.js');
6
6
  var errors = require('../base/errors.js');
7
+ var Precise = require('../base/Precise.js');
7
8
  var Cache = require('../base/ws/Cache.js');
8
9
 
9
10
  // ----------------------------------------------------------------------------
@@ -24,12 +25,18 @@ class bingx extends bingx$1["default"] {
24
25
  'watchTicker': true,
25
26
  'watchTickers': false,
26
27
  'watchBalance': true,
28
+ 'watchPositions': true,
27
29
  'unWatchOHLCV': true,
28
30
  'unWatchOrderBook': true,
29
31
  'unWatchTicker': true,
30
32
  'unWatchTrades': true,
31
33
  },
32
34
  'urls': {
35
+ 'test': {
36
+ 'ws': {
37
+ 'linear': 'wss://vst-open-api-ws.bingx.com/swap-market',
38
+ },
39
+ },
33
40
  'api': {
34
41
  'ws': {
35
42
  'spot': 'wss://open-api-ws.bingx.com/market',
@@ -73,7 +80,11 @@ class bingx extends bingx$1["default"] {
73
80
  },
74
81
  'watchBalance': {
75
82
  'fetchBalanceSnapshot': true,
76
- 'awaitBalanceSnapshot': false, // whether to wait for the balance snapshot before providing updates
83
+ 'awaitBalanceSnapshot': true, // whether to wait for the balance snapshot before providing updates
84
+ },
85
+ 'watchPositions': {
86
+ 'fetchPositionsSnapshot': true,
87
+ 'awaitPositionsSnapshot': false,
77
88
  },
78
89
  'watchOrderBook': {
79
90
  'depth': 100, // 5, 10, 20, 50, 100
@@ -1140,6 +1151,203 @@ class bingx extends bingx$1["default"] {
1140
1151
  client.resolve(this.balance[type], type + ':balance');
1141
1152
  }
1142
1153
  }
1154
+ /**
1155
+ * @method
1156
+ * @name bingx#watchPositions
1157
+ * @description watch all open positions
1158
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
1159
+ * @param {string[]|undefined} [symbols] list of unified market symbols
1160
+ * @param {int} [since] the earliest time in ms to fetch positions for
1161
+ * @param {int} [limit] the maximum number of position structures to retrieve
1162
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1163
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
1164
+ */
1165
+ async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1166
+ await this.loadMarkets();
1167
+ await this.authenticate();
1168
+ let market = undefined;
1169
+ let messageHash = '';
1170
+ symbols = this.marketSymbols(symbols);
1171
+ if (!this.isEmpty(symbols)) {
1172
+ market = this.getMarketFromSymbols(symbols);
1173
+ messageHash = '::' + symbols.join(',');
1174
+ }
1175
+ let type = undefined;
1176
+ let subType = undefined;
1177
+ [type, params] = this.handleMarketTypeAndParams('watchPositions', market, params);
1178
+ [subType, params] = this.handleSubTypeAndParams('watchPositions', market, params, 'linear');
1179
+ if (type === 'spot') {
1180
+ throw new errors.NotSupported(this.id + ' watchPositions is not supported for spot markets');
1181
+ }
1182
+ if (subType === 'inverse') {
1183
+ throw new errors.NotSupported(this.id + ' watchPositions is not supported for inverse swap markets yet');
1184
+ }
1185
+ const subscriptionHash = 'swap:private';
1186
+ messageHash = 'swap:positions' + messageHash;
1187
+ const baseUrl = this.safeString(this.urls['api']['ws'], subType);
1188
+ const url = baseUrl + '?listenKey=' + this.options['listenKey'];
1189
+ const client = this.client(url);
1190
+ this.setPositionsCache(client, type, symbols);
1191
+ let fetchPositionsSnapshot = undefined;
1192
+ let awaitPositionsSnapshot = undefined;
1193
+ [fetchPositionsSnapshot, params] = this.handleOptionAndParams(params, 'watchPositions', 'fetchPositionsSnapshot', true);
1194
+ [awaitPositionsSnapshot, params] = this.handleOptionAndParams(params, 'watchPositions', 'awaitPositionsSnapshot', false);
1195
+ const uuid = this.uuid();
1196
+ const subscription = {
1197
+ 'unsubscribe': false,
1198
+ 'id': uuid,
1199
+ };
1200
+ if (fetchPositionsSnapshot && awaitPositionsSnapshot && this.positions === undefined) {
1201
+ const snapshot = await client.future(type + ':fetchPositionsSnapshot');
1202
+ return this.filterBySymbolsSinceLimit(snapshot, symbols, since, limit, true);
1203
+ }
1204
+ const newPositions = await this.watch(url, messageHash, undefined, subscriptionHash, subscription);
1205
+ if (this.newUpdates) {
1206
+ return newPositions;
1207
+ }
1208
+ return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
1209
+ }
1210
+ setPositionsCache(client, type, symbols = undefined) {
1211
+ if (this.positions !== undefined) {
1212
+ return;
1213
+ }
1214
+ const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
1215
+ if (fetchPositionsSnapshot) {
1216
+ const messageHash = type + ':fetchPositionsSnapshot';
1217
+ if (!(messageHash in client.futures)) {
1218
+ client.future(messageHash);
1219
+ this.spawn(this.loadPositionsSnapshot, client, messageHash, type);
1220
+ }
1221
+ }
1222
+ else {
1223
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1224
+ }
1225
+ }
1226
+ async loadPositionsSnapshot(client, messageHash, type) {
1227
+ const positions = await this.fetchPositions(undefined, { 'type': type, 'subType': 'linear' });
1228
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1229
+ const cache = this.positions;
1230
+ for (let i = 0; i < positions.length; i++) {
1231
+ const position = positions[i];
1232
+ const contracts = this.safeNumber(position, 'contracts', 0);
1233
+ if (contracts > 0) {
1234
+ cache.append(position);
1235
+ }
1236
+ }
1237
+ // don't remove the future from the .futures cache
1238
+ if (messageHash in client.futures) {
1239
+ const future = client.futures[messageHash];
1240
+ future.resolve(cache);
1241
+ client.resolve(cache, 'swap:positions');
1242
+ }
1243
+ }
1244
+ parseWsPosition(position, market = undefined) {
1245
+ //
1246
+ // {
1247
+ // "s": "LINK-USDT", // Symbol
1248
+ // "pa": "5.000", // Position Amount
1249
+ // "ep": "11.2345", // Entry Price
1250
+ // "up": "0.5000", // Unrealized PnL
1251
+ // "mt": "isolated", // Margin Type
1252
+ // "iw": "50.00000000", // Isolated Wallet
1253
+ // "ps": "LONG" // Position Side
1254
+ // }
1255
+ //
1256
+ const marketId = this.safeString(position, 's');
1257
+ const contracts = this.safeString(position, 'pa');
1258
+ const contractsAbs = Precise["default"].stringAbs(contracts);
1259
+ let positionSide = this.safeStringLower(position, 'ps');
1260
+ let hedged = true;
1261
+ if (positionSide === 'both') {
1262
+ hedged = false;
1263
+ if (!Precise["default"].stringEq(contracts, '0')) {
1264
+ if (Precise["default"].stringLt(contracts, '0')) {
1265
+ positionSide = 'short';
1266
+ }
1267
+ else {
1268
+ positionSide = 'long';
1269
+ }
1270
+ }
1271
+ }
1272
+ const marginMode = this.safeString(position, 'mt');
1273
+ const collateral = (marginMode === 'isolated') ? this.safeNumber(position, 'iw') : undefined;
1274
+ return this.safePosition({
1275
+ 'info': position,
1276
+ 'id': undefined,
1277
+ 'symbol': this.safeSymbol(marketId, undefined, undefined, 'swap'),
1278
+ 'notional': undefined,
1279
+ 'marginMode': marginMode,
1280
+ 'liquidationPrice': undefined,
1281
+ 'entryPrice': this.safeNumber(position, 'ep'),
1282
+ 'unrealizedPnl': this.safeNumber(position, 'up'),
1283
+ 'percentage': undefined,
1284
+ 'contracts': this.parseNumber(contractsAbs),
1285
+ 'contractSize': undefined,
1286
+ 'markPrice': undefined,
1287
+ 'side': positionSide,
1288
+ 'hedged': hedged,
1289
+ 'timestamp': undefined,
1290
+ 'datetime': undefined,
1291
+ 'maintenanceMargin': undefined,
1292
+ 'maintenanceMarginPercentage': undefined,
1293
+ 'collateral': collateral,
1294
+ 'initialMargin': undefined,
1295
+ 'initialMarginPercentage': undefined,
1296
+ 'leverage': undefined,
1297
+ 'marginRatio': undefined,
1298
+ });
1299
+ }
1300
+ handlePositions(client, message) {
1301
+ //
1302
+ // {
1303
+ // "e": "ACCOUNT_UPDATE",
1304
+ // "E": 1696244249320,
1305
+ // "a": {
1306
+ // "m": "ORDER",
1307
+ // "B": [...],
1308
+ // "P": [
1309
+ // {
1310
+ // "s": "LINK-USDT",
1311
+ // "pa": "5.000",
1312
+ // "ep": "11.2345",
1313
+ // "up": "0.5000",
1314
+ // "mt": "isolated",
1315
+ // "iw": "50.00000000",
1316
+ // "ps": "LONG"
1317
+ // }
1318
+ // ]
1319
+ // }
1320
+ // }
1321
+ //
1322
+ if (this.positions === undefined) {
1323
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1324
+ }
1325
+ const cache = this.positions;
1326
+ const data = this.safeDict(message, 'a', {});
1327
+ const rawPositions = this.safeList(data, 'P', []);
1328
+ const newPositions = [];
1329
+ for (let i = 0; i < rawPositions.length; i++) {
1330
+ const rawPosition = rawPositions[i];
1331
+ const position = this.parseWsPosition(rawPosition);
1332
+ const timestamp = this.safeInteger(message, 'E');
1333
+ position['timestamp'] = timestamp;
1334
+ position['datetime'] = this.iso8601(timestamp);
1335
+ newPositions.push(position);
1336
+ cache.append(position);
1337
+ }
1338
+ const messageHashes = this.findMessageHashes(client, 'swap:positions::');
1339
+ for (let i = 0; i < messageHashes.length; i++) {
1340
+ const messageHash = messageHashes[i];
1341
+ const parts = messageHash.split('::');
1342
+ const symbolsString = parts[1];
1343
+ const filteredSymbols = symbolsString.split(',');
1344
+ const positions = this.filterByArray(newPositions, 'symbol', filteredSymbols, false);
1345
+ if (!this.isEmpty(positions)) {
1346
+ client.resolve(positions, messageHash);
1347
+ }
1348
+ }
1349
+ client.resolve(newPositions, 'swap:positions');
1350
+ }
1143
1351
  handleErrorMessage(client, message) {
1144
1352
  //
1145
1353
  // { code: 100400, msg: '', timestamp: 1696245808833 }
@@ -1175,7 +1383,11 @@ class bingx extends bingx$1["default"] {
1175
1383
  const types = ['spot', 'linear', 'inverse'];
1176
1384
  for (let i = 0; i < types.length; i++) {
1177
1385
  const type = types[i];
1178
- const url = this.urls['api']['ws'][type] + '?listenKey=' + listenKey;
1386
+ const baseUrl = this.safeString(this.urls['api']['ws'], type);
1387
+ if (baseUrl === undefined) {
1388
+ continue;
1389
+ }
1390
+ const url = baseUrl + '?listenKey=' + listenKey;
1179
1391
  const client = this.client(url);
1180
1392
  const messageHashes = Object.keys(client.futures);
1181
1393
  for (let j = 0; j < messageHashes.length; j++) {
@@ -1505,6 +1717,7 @@ class bingx extends bingx$1["default"] {
1505
1717
  const e = this.safeString(message, 'e');
1506
1718
  if (e === 'ACCOUNT_UPDATE') {
1507
1719
  this.handleBalance(client, message);
1720
+ this.handlePositions(client, message);
1508
1721
  }
1509
1722
  if (e === 'ORDER_TRADE_UPDATE') {
1510
1723
  this.handleOrder(client, message);
@@ -2010,6 +2010,7 @@ class bitget extends bitget$1["default"] {
2010
2010
  }
2011
2011
  parseWsOrderStatus(status) {
2012
2012
  const statuses = {
2013
+ 'new': 'open',
2013
2014
  'live': 'open',
2014
2015
  'partially_filled': 'open',
2015
2016
  'filled': 'closed',
@@ -673,7 +673,7 @@ class defx extends defx$1["default"] {
673
673
  //
674
674
  // {
675
675
  // "event": "WALLET_BALANCE_UPDATE",
676
- // "timestamp": 1711015961397,
676
+ // "timestamp": 1711015961396,
677
677
  // "data": {
678
678
  // "asset": "USDC", "balance": "27.64712963"
679
679
  // }
@@ -718,9 +718,9 @@ class kucoinfutures extends kucoinfutures$1["default"] {
718
718
  const parsed = [
719
719
  this.safeInteger(ohlcv, 0),
720
720
  this.safeNumber(ohlcv, 1),
721
- this.safeNumber(ohlcv, 2),
722
721
  this.safeNumber(ohlcv, 3),
723
722
  this.safeNumber(ohlcv, 4),
723
+ this.safeNumber(ohlcv, 2),
724
724
  this.safeNumber(ohlcv, 6), // Note value 5 is incorrect and will be fixed in subsequent versions of kucoin
725
725
  ];
726
726
  this.ohlcvs[symbol] = this.safeDict(this.ohlcvs, symbol, {});