ccxt 4.2.85 → 4.2.87

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 (99) hide show
  1. package/README.md +5 -5
  2. package/dist/ccxt.browser.js +1132 -432
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/ascendex.js +11 -1
  6. package/dist/cjs/src/binance.js +14 -1
  7. package/dist/cjs/src/bingx.js +71 -20
  8. package/dist/cjs/src/bitbank.js +19 -23
  9. package/dist/cjs/src/bitfinex.js +3 -0
  10. package/dist/cjs/src/bitfinex2.js +16 -1
  11. package/dist/cjs/src/bitflyer.js +19 -0
  12. package/dist/cjs/src/bitget.js +15 -1
  13. package/dist/cjs/src/bitopro.js +3 -0
  14. package/dist/cjs/src/bitrue.js +13 -7
  15. package/dist/cjs/src/bitvavo.js +3 -0
  16. package/dist/cjs/src/btcmarkets.js +1 -1
  17. package/dist/cjs/src/btcturk.js +2 -1
  18. package/dist/cjs/src/coinex.js +576 -302
  19. package/dist/cjs/src/currencycom.js +1 -1
  20. package/dist/cjs/src/delta.js +3 -1
  21. package/dist/cjs/src/digifinex.js +4 -2
  22. package/dist/cjs/src/exmo.js +11 -12
  23. package/dist/cjs/src/gate.js +5 -2
  24. package/dist/cjs/src/hitbtc.js +26 -2
  25. package/dist/cjs/src/htx.js +2 -2
  26. package/dist/cjs/src/huobijp.js +1 -1
  27. package/dist/cjs/src/hyperliquid.js +249 -12
  28. package/dist/cjs/src/idex.js +11 -12
  29. package/dist/cjs/src/krakenfutures.js +2 -6
  30. package/dist/cjs/src/lbank.js +3 -0
  31. package/dist/cjs/src/oceanex.js +1 -1
  32. package/dist/cjs/src/okcoin.js +3 -1
  33. package/dist/cjs/src/okx.js +24 -10
  34. package/dist/cjs/src/phemex.js +3 -1
  35. package/dist/cjs/src/pro/bitget.js +1 -0
  36. package/dist/cjs/src/pro/kucoin.js +11 -6
  37. package/dist/cjs/src/wazirx.js +1 -1
  38. package/dist/cjs/src/zonda.js +3 -0
  39. package/examples/js/benchmark.js +104 -0
  40. package/examples/ts/benchmark.ts +134 -0
  41. package/js/ccxt.d.ts +1 -1
  42. package/js/ccxt.js +1 -1
  43. package/js/src/abstract/coinex.d.ts +232 -123
  44. package/js/src/ascendex.d.ts +5 -12
  45. package/js/src/ascendex.js +11 -1
  46. package/js/src/base/Exchange.d.ts +13 -13
  47. package/js/src/base/types.d.ts +11 -0
  48. package/js/src/binance.d.ts +4 -11
  49. package/js/src/binance.js +14 -1
  50. package/js/src/bingx.d.ts +5 -2
  51. package/js/src/bingx.js +71 -20
  52. package/js/src/bitbank.js +19 -23
  53. package/js/src/bitfinex.js +3 -0
  54. package/js/src/bitfinex2.d.ts +3 -17
  55. package/js/src/bitfinex2.js +16 -1
  56. package/js/src/bitflyer.d.ts +1 -0
  57. package/js/src/bitflyer.js +20 -1
  58. package/js/src/bitget.d.ts +5 -12
  59. package/js/src/bitget.js +15 -1
  60. package/js/src/bitopro.js +3 -0
  61. package/js/src/bitrue.d.ts +3 -17
  62. package/js/src/bitrue.js +13 -7
  63. package/js/src/bitvavo.js +3 -0
  64. package/js/src/btcmarkets.js +1 -1
  65. package/js/src/btcturk.js +2 -1
  66. package/js/src/coinex.d.ts +5 -12
  67. package/js/src/coinex.js +576 -302
  68. package/js/src/currencycom.js +1 -1
  69. package/js/src/delta.d.ts +5 -37
  70. package/js/src/delta.js +3 -1
  71. package/js/src/digifinex.d.ts +5 -13
  72. package/js/src/digifinex.js +4 -2
  73. package/js/src/exmo.d.ts +5 -37
  74. package/js/src/exmo.js +11 -12
  75. package/js/src/gate.d.ts +5 -33
  76. package/js/src/gate.js +5 -2
  77. package/js/src/hitbtc.d.ts +5 -12
  78. package/js/src/hitbtc.js +26 -2
  79. package/js/src/htx.js +2 -2
  80. package/js/src/huobijp.js +1 -1
  81. package/js/src/hyperliquid.d.ts +7 -4
  82. package/js/src/hyperliquid.js +249 -12
  83. package/js/src/idex.js +11 -12
  84. package/js/src/krakenfutures.js +2 -6
  85. package/js/src/kucoinfutures.d.ts +2 -2
  86. package/js/src/lbank.js +3 -0
  87. package/js/src/mexc.d.ts +3 -3
  88. package/js/src/oceanex.js +1 -1
  89. package/js/src/okcoin.js +3 -1
  90. package/js/src/okx.d.ts +5 -33
  91. package/js/src/okx.js +24 -10
  92. package/js/src/phemex.d.ts +3 -11
  93. package/js/src/phemex.js +3 -1
  94. package/js/src/pro/bitget.js +1 -0
  95. package/js/src/pro/kucoin.js +11 -6
  96. package/js/src/wazirx.js +1 -1
  97. package/js/src/zonda.js +3 -0
  98. package/package.json +3 -2
  99. package/skip-tests.json +7 -3
@@ -29,7 +29,7 @@ export default class hyperliquid extends Exchange {
29
29
  'pro': true,
30
30
  'has': {
31
31
  'CORS': undefined,
32
- 'spot': false,
32
+ 'spot': true,
33
33
  'margin': false,
34
34
  'swap': true,
35
35
  'future': true,
@@ -162,6 +162,10 @@ export default class hyperliquid extends Exchange {
162
162
  'taker': this.parseNumber('0.00035'),
163
163
  'maker': this.parseNumber('0.0001'),
164
164
  },
165
+ 'spot': {
166
+ 'taker': this.parseNumber('0.00035'),
167
+ 'maker': this.parseNumber('0.0001'),
168
+ },
165
169
  },
166
170
  'requiredCredentials': {
167
171
  'apiKey': false,
@@ -187,6 +191,7 @@ export default class hyperliquid extends Exchange {
187
191
  'precisionMode': TICK_SIZE,
188
192
  'commonCurrencies': {},
189
193
  'options': {
194
+ 'defaultType': 'swap',
190
195
  'sandboxMode': false,
191
196
  'defaultSlippage': 0.05,
192
197
  'zeroAddress': '0x0000000000000000000000000000000000000000',
@@ -257,6 +262,24 @@ export default class hyperliquid extends Exchange {
257
262
  * @param {object} [params] extra parameters specific to the exchange API endpoint
258
263
  * @returns {object[]} an array of objects representing market data
259
264
  */
265
+ const rawPromises = [
266
+ this.fetchSwapMarkets(params),
267
+ this.fetchSpotMarkets(params),
268
+ ];
269
+ const promises = await Promise.all(rawPromises);
270
+ const swapMarkets = promises[0];
271
+ const spotMarkets = promises[1];
272
+ return this.arrayConcat(swapMarkets, spotMarkets);
273
+ }
274
+ async fetchSwapMarkets(params = {}) {
275
+ /**
276
+ * @method
277
+ * @name hyperliquid#fetchMarkets
278
+ * @description retrieves data on all swap markets for hyperliquid
279
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-asset-contexts-includes-mark-price-current-funding-open-interest-etc
280
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
281
+ * @returns {object[]} an array of objects representing market data
282
+ */
260
283
  const request = {
261
284
  'type': 'metaAndAssetCtxs',
262
285
  };
@@ -302,6 +325,132 @@ export default class hyperliquid extends Exchange {
302
325
  }
303
326
  return this.parseMarkets(result);
304
327
  }
328
+ async fetchSpotMarkets(params = {}) {
329
+ /**
330
+ * @method
331
+ * @name hyperliquid#fetchMarkets
332
+ * @description retrieves data on all spot markets for hyperliquid
333
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-asset-contexts-includes-mark-price-current-funding-open-interest-etc
334
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
335
+ * @returns {object[]} an array of objects representing market data
336
+ */
337
+ const request = {
338
+ 'type': 'spotMetaAndAssetCtxs',
339
+ };
340
+ const response = await this.publicPostInfo(this.extend(request, params));
341
+ //
342
+ // [
343
+ // {
344
+ // 'tokens': [
345
+ // {
346
+ // 'name': 'USDC',
347
+ // 'szDecimals': '8',
348
+ // 'weiDecimals': '8',
349
+ // },
350
+ // {
351
+ // 'name': 'PURR',
352
+ // 'szDecimals': '0',
353
+ // 'weiDecimals': '5',
354
+ // },
355
+ // ],
356
+ // 'universe': [
357
+ // {
358
+ // 'name': 'PURR/USDC',
359
+ // 'tokens': [
360
+ // 1,
361
+ // 0,
362
+ // ],
363
+ // },
364
+ // ],
365
+ // },
366
+ // [
367
+ // {
368
+ // 'dayNtlVlm': '264250385.14640012',
369
+ // 'markPx': '0.018314',
370
+ // 'midPx': '0.0182235',
371
+ // 'prevDayPx': '0.017427',
372
+ // },
373
+ // ],
374
+ // ];
375
+ //
376
+ const first = this.safeDict(response, 0, {});
377
+ const meta = this.safeList(first, 'universe', []);
378
+ const tokens = this.safeList(first, 'tokens', []);
379
+ const markets = [];
380
+ for (let i = 0; i < meta.length; i++) {
381
+ const market = this.safeDict(meta, i, {});
382
+ const marketName = this.safeString(market, 'name');
383
+ const marketParts = marketName.split('/');
384
+ const baseName = this.safeString(marketParts, 0);
385
+ const quoteId = this.safeString(marketParts, 1);
386
+ const base = this.safeCurrencyCode(baseName);
387
+ const quote = this.safeCurrencyCode(quoteId);
388
+ const symbol = base + '/' + quote;
389
+ const fees = this.safeDict(this.fees, 'spot', {});
390
+ const taker = this.safeNumber(fees, 'taker');
391
+ const maker = this.safeNumber(fees, 'maker');
392
+ const tokensPos = this.safeList(market, 'tokens', []);
393
+ const baseTokenPos = this.safeInteger(tokensPos, 0);
394
+ const quoteTokenPos = this.safeInteger(tokensPos, 1);
395
+ const baseTokenInfo = this.safeDict(tokens, baseTokenPos, {});
396
+ const quoteTokenInfo = this.safeDict(tokens, quoteTokenPos, {});
397
+ const baseDecimals = this.safeString(baseTokenInfo, 'szDecimals');
398
+ const quoteDecimals = this.safeInteger(quoteTokenInfo, 'szDecimals');
399
+ const baseId = this.numberToString(i + 10000);
400
+ markets.push(this.safeMarketStructure({
401
+ 'id': baseId,
402
+ 'symbol': symbol,
403
+ 'base': base,
404
+ 'quote': quote,
405
+ 'settle': undefined,
406
+ 'baseId': baseId,
407
+ 'quoteId': quoteId,
408
+ 'settleId': undefined,
409
+ 'type': 'spot',
410
+ 'spot': true,
411
+ 'margin': undefined,
412
+ 'swap': false,
413
+ 'future': false,
414
+ 'option': false,
415
+ 'active': true,
416
+ 'contract': false,
417
+ 'linear': true,
418
+ 'inverse': false,
419
+ 'taker': taker,
420
+ 'maker': maker,
421
+ 'contractSize': undefined,
422
+ 'expiry': undefined,
423
+ 'expiryDatetime': undefined,
424
+ 'strike': undefined,
425
+ 'optionType': undefined,
426
+ 'precision': {
427
+ 'amount': this.parseNumber(this.parsePrecision(baseDecimals)),
428
+ 'price': quoteDecimals, // significant digits
429
+ },
430
+ 'limits': {
431
+ 'leverage': {
432
+ 'min': undefined,
433
+ 'max': undefined,
434
+ },
435
+ 'amount': {
436
+ 'min': undefined,
437
+ 'max': undefined,
438
+ },
439
+ 'price': {
440
+ 'min': undefined,
441
+ 'max': undefined,
442
+ },
443
+ 'cost': {
444
+ 'min': undefined,
445
+ 'max': undefined,
446
+ },
447
+ },
448
+ 'created': undefined,
449
+ 'info': market,
450
+ }));
451
+ }
452
+ return markets;
453
+ }
305
454
  parseMarket(market) {
306
455
  //
307
456
  // {
@@ -400,12 +549,17 @@ export default class hyperliquid extends Exchange {
400
549
  * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-state
401
550
  * @param {object} [params] extra parameters specific to the exchange API endpoint
402
551
  * @param {string} [params.user] user address, will default to this.walletAddress if not provided
552
+ * @param {string} [params.type] wallet type, ['spot', 'swap'], defaults to swap
403
553
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
404
554
  */
405
555
  let userAddress = undefined;
406
556
  [userAddress, params] = this.handlePublicAddress('fetchBalance', params);
557
+ let type = undefined;
558
+ [type, params] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
559
+ const isSpot = (type === 'spot');
560
+ const reqType = (isSpot) ? 'spotClearinghouseState' : 'clearinghouseState';
407
561
  const request = {
408
- 'type': 'clearinghouseState',
562
+ 'type': reqType,
409
563
  'user': userAddress,
410
564
  };
411
565
  const response = await this.publicPostInfo(this.extend(request, params));
@@ -428,7 +582,37 @@ export default class hyperliquid extends Exchange {
428
582
  // "time": "1704261007014",
429
583
  // "withdrawable": "100.0"
430
584
  // }
585
+ // spot
586
+ //
587
+ // {
588
+ // "balances":[
589
+ // {
590
+ // "coin":"USDC",
591
+ // "hold":"0.0",
592
+ // "total":"1481.844"
593
+ // },
594
+ // {
595
+ // "coin":"PURR",
596
+ // "hold":"0.0",
597
+ // "total":"999.65004"
598
+ // }
599
+ // }
431
600
  //
601
+ const balances = this.safeList(response, 'balances');
602
+ if (balances !== undefined) {
603
+ const spotBalances = { 'info': response };
604
+ for (let i = 0; i < balances.length; i++) {
605
+ const balance = balances[i];
606
+ const code = this.safeCurrencyCode(this.safeString(balance, 'coin'));
607
+ const account = this.account();
608
+ const total = this.safeString(balance, 'total');
609
+ const free = this.safeString(balance, 'hold');
610
+ account['total'] = total;
611
+ account['free'] = free;
612
+ spotBalances[code] = account;
613
+ }
614
+ return this.safeBalance(spotBalances);
615
+ }
432
616
  const data = this.safeDict(response, 'marginSummary', {});
433
617
  const result = {
434
618
  'info': response,
@@ -954,6 +1138,7 @@ export default class hyperliquid extends Exchange {
954
1138
  * @param {string} symbol unified symbol of the market the order was made in
955
1139
  * @param {object} [params] extra parameters specific to the exchange API endpoint
956
1140
  * @param {string} [params.clientOrderId] client order id, (optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
1141
+ * @param {string} [params.vaultAddress] the vault address for order
957
1142
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
958
1143
  */
959
1144
  return await this.cancelOrders([id], symbol, params);
@@ -969,6 +1154,7 @@ export default class hyperliquid extends Exchange {
969
1154
  * @param {string} [symbol] unified market symbol
970
1155
  * @param {object} [params] extra parameters specific to the exchange API endpoint
971
1156
  * @param {string|string[]} [params.clientOrderId] client order ids, (optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
1157
+ * @param {string} [params.vaultAddress] the vault address
972
1158
  * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
973
1159
  */
974
1160
  this.checkRequiredCredentials();
@@ -1451,7 +1637,12 @@ export default class hyperliquid extends Exchange {
1451
1637
  const coin = this.safeString(entry, 'coin');
1452
1638
  let marketId = undefined;
1453
1639
  if (coin !== undefined) {
1454
- marketId = coin + '/USDC:USDC';
1640
+ if (coin.indexOf('/') > -1) {
1641
+ marketId = coin;
1642
+ }
1643
+ else {
1644
+ marketId = coin + '/USDC:USDC';
1645
+ }
1455
1646
  }
1456
1647
  if (this.safeString(entry, 'id') === undefined) {
1457
1648
  market = this.safeMarket(marketId, undefined);
@@ -1935,10 +2126,27 @@ export default class hyperliquid extends Exchange {
1935
2126
  // 'status': 'ok'
1936
2127
  // }
1937
2128
  //
1938
- return response;
1939
- // return this.extend (this.parseMarginModification (response, market), {
1940
- // 'code': code,
1941
- // });
2129
+ return this.extend(this.parseMarginModification(response, market), {
2130
+ 'code': this.safeString(response, 'status'),
2131
+ });
2132
+ }
2133
+ parseMarginModification(data, market = undefined) {
2134
+ //
2135
+ // {
2136
+ // 'type': 'default'
2137
+ // }
2138
+ //
2139
+ return {
2140
+ 'info': data,
2141
+ 'symbol': this.safeSymbol(undefined, market),
2142
+ 'type': undefined,
2143
+ 'amount': undefined,
2144
+ 'total': undefined,
2145
+ 'code': this.safeString(market, 'settle'),
2146
+ 'status': undefined,
2147
+ 'timestamp': undefined,
2148
+ 'datetime': undefined,
2149
+ };
1942
2150
  }
1943
2151
  async transfer(code, amount, fromAccount, toAccount, params = {}) {
1944
2152
  /**
@@ -1948,13 +2156,44 @@ export default class hyperliquid extends Exchange {
1948
2156
  * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer
1949
2157
  * @param {string} code unified currency code
1950
2158
  * @param {float} amount amount to transfer
1951
- * @param {string} fromAccount account to transfer from
1952
- * @param {string} toAccount account to transfer to
2159
+ * @param {string} fromAccount account to transfer from *spot, swap*
2160
+ * @param {string} toAccount account to transfer to *swap, spot or address*
1953
2161
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2162
+ * @param {string} [params.vaultAddress] the vault address for order
1954
2163
  * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
1955
2164
  */
1956
2165
  this.checkRequiredCredentials();
1957
2166
  await this.loadMarkets();
2167
+ const isSandboxMode = this.safeBool(this.options, 'sandboxMode');
2168
+ const nonce = this.milliseconds();
2169
+ if (this.inArray(fromAccount, ['spot', 'swap', 'perp'])) {
2170
+ // handle swap <> spot account transfer
2171
+ if (!this.inArray(toAccount, ['spot', 'swap', 'perp'])) {
2172
+ throw new NotSupported(this.id + 'transfer() only support spot <> swap transfer');
2173
+ }
2174
+ const vaultAddress = this.formatVaultAddress(this.safeString(params, 'vaultAddress'));
2175
+ params = this.omit(params, 'vaultAddress');
2176
+ const toPerp = (toAccount === 'perp') || (toAccount === 'swap');
2177
+ const action = {
2178
+ 'type': 'spotUser',
2179
+ 'classTransfer': {
2180
+ 'usdc': amount,
2181
+ 'toPerp': toPerp,
2182
+ },
2183
+ };
2184
+ const signature = this.signL1Action(action, nonce, vaultAddress);
2185
+ const innerRequest = {
2186
+ 'action': this.extend(action, params),
2187
+ 'nonce': nonce,
2188
+ 'signature': signature,
2189
+ };
2190
+ if (vaultAddress !== undefined) {
2191
+ innerRequest['vaultAddress'] = vaultAddress;
2192
+ }
2193
+ const transferResponse = await this.privatePostExchange(innerRequest);
2194
+ return transferResponse;
2195
+ }
2196
+ // handle sub-account/different account transfer
1958
2197
  this.checkAddress(toAccount);
1959
2198
  if (code !== undefined) {
1960
2199
  code = code.toUpperCase();
@@ -1962,11 +2201,9 @@ export default class hyperliquid extends Exchange {
1962
2201
  throw new NotSupported(this.id + 'withdraw() only support USDC');
1963
2202
  }
1964
2203
  }
1965
- const isSandboxMode = this.safeBool(this.options, 'sandboxMode');
1966
- const nonce = this.milliseconds();
1967
2204
  const payload = {
1968
2205
  'destination': toAccount,
1969
- 'amount': amount.toString(),
2206
+ 'amount': this.numberToString(amount),
1970
2207
  'time': nonce,
1971
2208
  };
1972
2209
  const sig = this.buildTransferSig(payload);
package/js/src/idex.js CHANGED
@@ -165,13 +165,15 @@ export default class idex extends Exchange {
165
165
  'network': 'MATIC',
166
166
  },
167
167
  'exceptions': {
168
- 'INVALID_ORDER_QUANTITY': InvalidOrder,
169
- 'INSUFFICIENT_FUNDS': InsufficientFunds,
170
- 'SERVICE_UNAVAILABLE': ExchangeNotAvailable,
171
- 'EXCEEDED_RATE_LIMIT': DDoSProtection,
172
- 'INVALID_PARAMETER': BadRequest,
173
- 'WALLET_NOT_ASSOCIATED': InvalidAddress,
174
- 'INVALID_WALLET_SIGNATURE': AuthenticationError,
168
+ 'exact': {
169
+ 'INVALID_ORDER_QUANTITY': InvalidOrder,
170
+ 'INSUFFICIENT_FUNDS': InsufficientFunds,
171
+ 'SERVICE_UNAVAILABLE': ExchangeNotAvailable,
172
+ 'EXCEEDED_RATE_LIMIT': DDoSProtection,
173
+ 'INVALID_PARAMETER': BadRequest,
174
+ 'WALLET_NOT_ASSOCIATED': InvalidAddress,
175
+ 'INVALID_WALLET_SIGNATURE': AuthenticationError,
176
+ },
175
177
  },
176
178
  'requiredCredentials': {
177
179
  'walletAddress': true,
@@ -464,7 +466,7 @@ export default class idex extends Exchange {
464
466
  request['start'] = since;
465
467
  }
466
468
  if (limit !== undefined) {
467
- request['limit'] = limit;
469
+ request['limit'] = Math.min(limit, 1000);
468
470
  }
469
471
  const response = await this.publicGetCandles(this.extend(request, params));
470
472
  if (Array.isArray(response)) {
@@ -1497,11 +1499,8 @@ export default class idex extends Exchange {
1497
1499
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1498
1500
  const errorCode = this.safeString(response, 'code');
1499
1501
  const message = this.safeString(response, 'message');
1500
- if (errorCode in this.exceptions) {
1501
- const Exception = this.exceptions[errorCode];
1502
- throw new Exception(this.id + ' ' + message);
1503
- }
1504
1502
  if (errorCode !== undefined) {
1503
+ this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, message);
1505
1504
  throw new ExchangeError(this.id + ' ' + message);
1506
1505
  }
1507
1506
  return undefined;
@@ -644,17 +644,13 @@ export default class krakenfutures extends Exchange {
644
644
  if (limit === undefined) {
645
645
  limit = 5000;
646
646
  }
647
- else if (limit > 5000) {
648
- throw new BadRequest(this.id + ' fetchOHLCV() limit cannot exceed 5000');
649
- }
647
+ limit = Math.min(limit, 5000);
650
648
  const toTimestamp = this.sum(request['from'], limit * duration - 1);
651
649
  const currentTimestamp = this.seconds();
652
650
  request['to'] = Math.min(toTimestamp, currentTimestamp);
653
651
  }
654
652
  else if (limit !== undefined) {
655
- if (limit > 5000) {
656
- throw new BadRequest(this.id + ' fetchOHLCV() limit cannot exceed 5000');
657
- }
653
+ limit = Math.min(limit, 5000);
658
654
  const duration = this.parseTimeframe(timeframe);
659
655
  request['to'] = this.seconds();
660
656
  request['from'] = this.parseToInt(request['to'] - (duration * limit));
@@ -1,5 +1,5 @@
1
1
  import kucoin from './abstract/kucoinfutures.js';
2
- import type { TransferEntry, Int, OrderSide, OrderType, OHLCV, Order, Trade, OrderRequest, FundingHistory, Balances, Str, Ticker, Tickers, OrderBook, Transaction, Strings, Market, Currency, Num } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, OrderType, OHLCV, Order, Trade, OrderRequest, FundingHistory, Balances, Str, Ticker, Tickers, OrderBook, Transaction, Strings, Market, Currency, Num, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class kucoinfutures
5
5
  * @augments Exchange
@@ -37,7 +37,7 @@ export default class kucoinfutures extends kucoin {
37
37
  createContractOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): any;
38
38
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<any>;
39
39
  cancelAllOrders(symbol?: Str, params?: {}): Promise<any>;
40
- addMargin(symbol: string, amount: any, params?: {}): Promise<any>;
40
+ addMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
41
41
  parseMarginModification(info: any, market?: Market): {
42
42
  info: any;
43
43
  direction: any;
package/js/src/lbank.js CHANGED
@@ -1003,6 +1003,9 @@ export default class lbank extends Exchange {
1003
1003
  if (limit === undefined) {
1004
1004
  limit = 100;
1005
1005
  }
1006
+ else {
1007
+ limit = Math.min(limit, 2000);
1008
+ }
1006
1009
  if (since === undefined) {
1007
1010
  const duration = this.parseTimeframe(timeframe);
1008
1011
  since = this.milliseconds() - duration * 1000 * limit;
package/js/src/mexc.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/mexc.js';
2
- import type { TransferEntry, IndexType, Int, OrderSide, Balances, OrderType, OHLCV, FundingRateHistory, Position, OrderBook, OrderRequest, FundingHistory, Order, Str, Trade, Transaction, Ticker, Tickers, Strings, Market, Currency, Leverage, Num, Account } from './base/types.js';
2
+ import type { TransferEntry, IndexType, Int, OrderSide, Balances, OrderType, OHLCV, FundingRateHistory, Position, OrderBook, OrderRequest, FundingHistory, Order, Str, Trade, Transaction, Ticker, Tickers, Strings, Market, Currency, Leverage, Num, Account, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class mexc
5
5
  * @augments Exchange
@@ -59,8 +59,8 @@ export default class mexc extends Exchange {
59
59
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
60
60
  fetchOrderTrades(id: string, symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
61
61
  modifyMarginHelper(symbol: string, amount: any, addOrReduce: any, params?: {}): Promise<any>;
62
- reduceMargin(symbol: string, amount: any, params?: {}): Promise<any>;
63
- addMargin(symbol: string, amount: any, params?: {}): Promise<any>;
62
+ reduceMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
63
+ addMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
64
64
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
65
65
  fetchFundingHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
66
66
  parseFundingRate(contract: any, market?: Market): {
package/js/src/oceanex.js CHANGED
@@ -797,7 +797,7 @@ export default class oceanex extends Exchange {
797
797
  request['timestamp'] = since;
798
798
  }
799
799
  if (limit !== undefined) {
800
- request['limit'] = limit;
800
+ request['limit'] = Math.min(limit, 10000);
801
801
  }
802
802
  const response = await this.publicPostK(this.extend(request, params));
803
803
  const ohlcvs = this.safeList(response, 'data', []);
package/js/src/okcoin.js CHANGED
@@ -1136,8 +1136,10 @@ export default class okcoin extends Exchange {
1136
1136
  const request = {
1137
1137
  'instId': market['id'],
1138
1138
  'bar': bar,
1139
- 'limit': limit,
1140
1139
  };
1140
+ if (limit !== undefined) {
1141
+ request['limit'] = limit; // default 100, max 100
1142
+ }
1141
1143
  let method = undefined;
1142
1144
  [method, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'method', 'publicGetMarketCandles');
1143
1145
  let response = undefined;
package/js/src/okx.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/okx.js';
2
- import type { TransferEntry, Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Str, Transaction, Ticker, OrderBook, Balances, Tickers, Market, Greeks, Strings, MarketInterface, Currency, Leverage, Num, Account, OptionChain, Option } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Str, Transaction, Ticker, OrderBook, Balances, Tickers, Market, Greeks, Strings, MarketInterface, Currency, Leverage, Num, Account, OptionChain, Option, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class okx
5
5
  * @augments Exchange
@@ -202,38 +202,10 @@ export default class okx extends Exchange {
202
202
  parseBorrowRateHistory(response: any, code: any, since: any, limit: any): any;
203
203
  fetchBorrowRateHistories(codes?: any, since?: Int, limit?: Int, params?: {}): Promise<{}>;
204
204
  fetchBorrowRateHistory(code: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
205
- modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<{
206
- info: any;
207
- type: string;
208
- amount: number;
209
- code: string;
210
- symbol: string;
211
- status: string;
212
- }>;
213
- parseMarginModification(data: any, market?: Market): {
214
- info: any;
215
- type: string;
216
- amount: number;
217
- code: string;
218
- symbol: string;
219
- status: string;
220
- };
221
- reduceMargin(symbol: string, amount: any, params?: {}): Promise<{
222
- info: any;
223
- type: string;
224
- amount: number;
225
- code: string;
226
- symbol: string;
227
- status: string;
228
- }>;
229
- addMargin(symbol: string, amount: any, params?: {}): Promise<{
230
- info: any;
231
- type: string;
232
- amount: number;
233
- code: string;
234
- symbol: string;
235
- status: string;
236
- }>;
205
+ modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<MarginModification>;
206
+ parseMarginModification(data: any, market?: Market): MarginModification;
207
+ reduceMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
208
+ addMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
237
209
  fetchMarketLeverageTiers(symbol: string, params?: {}): Promise<any[]>;
238
210
  parseMarketLeverageTiers(info: any, market?: Market): any[];
239
211
  fetchBorrowInterest(code?: Str, symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
package/js/src/okx.js CHANGED
@@ -6463,26 +6463,40 @@ export default class okx extends Exchange {
6463
6463
  // "msg": ""
6464
6464
  // }
6465
6465
  //
6466
- return this.parseMarginModification(response, market);
6466
+ const data = this.safeList(response, 'data', []);
6467
+ const errorCode = this.safeString(response, 'code');
6468
+ const item = this.safeDict(data, 0, {});
6469
+ return this.extend(this.parseMarginModification(item, market), {
6470
+ 'status': (errorCode === '0') ? 'ok' : 'failed',
6471
+ });
6467
6472
  }
6468
6473
  parseMarginModification(data, market = undefined) {
6469
- const innerData = this.safeValue(data, 'data', []);
6470
- const entry = this.safeValue(innerData, 0, {});
6471
- const errorCode = this.safeString(data, 'code');
6472
- const status = (errorCode === '0') ? 'ok' : 'failed';
6473
- const amountRaw = this.safeNumber(entry, 'amt');
6474
- const typeRaw = this.safeString(entry, 'type');
6474
+ //
6475
+ // addMargin/reduceMargin
6476
+ //
6477
+ // {
6478
+ // "amt": "0.01",
6479
+ // "instId": "ETH-USD-SWAP",
6480
+ // "posSide": "net",
6481
+ // "type": "reduce"
6482
+ // }
6483
+ //
6484
+ const amountRaw = this.safeNumber(data, 'amt');
6485
+ const typeRaw = this.safeString(data, 'type');
6475
6486
  const type = (typeRaw === 'reduce') ? 'reduce' : 'add';
6476
- const marketId = this.safeString(entry, 'instId');
6487
+ const marketId = this.safeString(data, 'instId');
6477
6488
  const responseMarket = this.safeMarket(marketId, market);
6478
6489
  const code = responseMarket['inverse'] ? responseMarket['base'] : responseMarket['quote'];
6479
6490
  return {
6480
6491
  'info': data,
6492
+ 'symbol': responseMarket['symbol'],
6481
6493
  'type': type,
6482
6494
  'amount': amountRaw,
6495
+ 'total': undefined,
6483
6496
  'code': code,
6484
- 'symbol': responseMarket['symbol'],
6485
- 'status': status,
6497
+ 'status': undefined,
6498
+ 'timestamp': undefined,
6499
+ 'datetime': undefined,
6486
6500
  };
6487
6501
  }
6488
6502
  async reduceMargin(symbol, amount, params = {}) {
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/phemex.js';
2
- import type { TransferEntry, Balances, Currency, FundingHistory, FundingRateHistory, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
2
+ import type { TransferEntry, Balances, Currency, FundingHistory, FundingRateHistory, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class phemex
5
5
  * @augments Exchange
@@ -99,17 +99,9 @@ export default class phemex extends Exchange {
99
99
  previousFundingTimestamp: any;
100
100
  previousFundingDatetime: any;
101
101
  };
102
- setMargin(symbol: string, amount: number, params?: {}): Promise<any>;
102
+ setMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
103
103
  parseMarginStatus(status: any): string;
104
- parseMarginModification(data: any, market?: Market): {
105
- info: any;
106
- type: string;
107
- amount: any;
108
- total: any;
109
- code: string;
110
- symbol: string;
111
- status: string;
112
- };
104
+ parseMarginModification(data: any, market?: Market): MarginModification;
113
105
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
114
106
  setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<any>;
115
107
  fetchLeverageTiers(symbols?: Strings, params?: {}): Promise<{}>;
package/js/src/phemex.js CHANGED
@@ -4063,12 +4063,14 @@ export default class phemex extends Exchange {
4063
4063
  const codeCurrency = inverse ? 'base' : 'quote';
4064
4064
  return {
4065
4065
  'info': data,
4066
+ 'symbol': this.safeSymbol(undefined, market),
4066
4067
  'type': 'set',
4067
4068
  'amount': undefined,
4068
4069
  'total': undefined,
4069
4070
  'code': market[codeCurrency],
4070
- 'symbol': this.safeSymbol(undefined, market),
4071
4071
  'status': this.parseMarginStatus(this.safeString(data, 'code')),
4072
+ 'timestamp': undefined,
4073
+ 'datetime': undefined,
4072
4074
  };
4073
4075
  }
4074
4076
  async setMarginMode(marginMode, symbol = undefined, params = {}) {
@@ -86,6 +86,7 @@ export default class bitget extends bitgetRest {
86
86
  '30015': AuthenticationError,
87
87
  '30016': BadRequest, // { event: 'error', code: 30016, msg: 'Param error' }
88
88
  },
89
+ 'broad': {},
89
90
  },
90
91
  },
91
92
  });