ccxt 4.2.86 → 4.2.88

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 (103) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +4 -5
  3. package/dist/ccxt.browser.js +748 -169
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/ccxt.js +6 -1
  6. package/dist/cjs/src/ascendex.js +11 -1
  7. package/dist/cjs/src/base/Exchange.js +26 -2
  8. package/dist/cjs/src/binance.js +24 -7
  9. package/dist/cjs/src/bingx.js +37 -1
  10. package/dist/cjs/src/bitfinex.js +3 -0
  11. package/dist/cjs/src/bitfinex2.js +16 -1
  12. package/dist/cjs/src/bitflyer.js +19 -0
  13. package/dist/cjs/src/bitget.js +32 -17
  14. package/dist/cjs/src/bitopro.js +3 -0
  15. package/dist/cjs/src/bitrue.js +13 -7
  16. package/dist/cjs/src/bitvavo.js +3 -0
  17. package/dist/cjs/src/btcmarkets.js +1 -1
  18. package/dist/cjs/src/btcturk.js +2 -1
  19. package/dist/cjs/src/coinex.js +182 -54
  20. package/dist/cjs/src/cryptocom.js +1 -1
  21. package/dist/cjs/src/currencycom.js +1 -1
  22. package/dist/cjs/src/delta.js +3 -1
  23. package/dist/cjs/src/digifinex.js +4 -2
  24. package/dist/cjs/src/exmo.js +11 -12
  25. package/dist/cjs/src/gate.js +13 -10
  26. package/dist/cjs/src/hitbtc.js +26 -2
  27. package/dist/cjs/src/htx.js +2 -2
  28. package/dist/cjs/src/huobijp.js +1 -1
  29. package/dist/cjs/src/hyperliquid.js +249 -12
  30. package/dist/cjs/src/idex.js +1 -1
  31. package/dist/cjs/src/krakenfutures.js +4 -7
  32. package/dist/cjs/src/kucoin.js +7 -4
  33. package/dist/cjs/src/lbank.js +3 -0
  34. package/dist/cjs/src/mexc.js +1 -1
  35. package/dist/cjs/src/oceanex.js +1 -1
  36. package/dist/cjs/src/okx.js +24 -10
  37. package/dist/cjs/src/phemex.js +3 -1
  38. package/dist/cjs/src/pro/kucoin.js +11 -6
  39. package/dist/cjs/src/wazirx.js +1 -1
  40. package/dist/cjs/src/zonda.js +3 -0
  41. package/examples/js/benchmark.js +104 -0
  42. package/examples/js/cli.js +0 -2
  43. package/examples/ts/benchmark.ts +134 -0
  44. package/examples/ts/cli.ts +0 -2
  45. package/js/ccxt.d.ts +3 -3
  46. package/js/ccxt.js +3 -3
  47. package/js/src/ascendex.d.ts +5 -12
  48. package/js/src/ascendex.js +11 -1
  49. package/js/src/base/Exchange.d.ts +5 -4
  50. package/js/src/base/Exchange.js +26 -2
  51. package/js/src/base/types.d.ts +12 -1
  52. package/js/src/binance.d.ts +5 -12
  53. package/js/src/binance.js +24 -7
  54. package/js/src/bingx.d.ts +5 -2
  55. package/js/src/bingx.js +37 -1
  56. package/js/src/bitfinex.js +3 -0
  57. package/js/src/bitfinex2.d.ts +3 -17
  58. package/js/src/bitfinex2.js +16 -1
  59. package/js/src/bitflyer.d.ts +1 -0
  60. package/js/src/bitflyer.js +20 -1
  61. package/js/src/bitget.d.ts +5 -12
  62. package/js/src/bitget.js +32 -17
  63. package/js/src/bitopro.js +3 -0
  64. package/js/src/bitrue.d.ts +3 -17
  65. package/js/src/bitrue.js +13 -7
  66. package/js/src/bitvavo.js +3 -0
  67. package/js/src/btcmarkets.js +1 -1
  68. package/js/src/btcturk.js +2 -1
  69. package/js/src/coinex.d.ts +4 -11
  70. package/js/src/coinex.js +182 -54
  71. package/js/src/cryptocom.js +1 -1
  72. package/js/src/currencycom.js +1 -1
  73. package/js/src/delta.d.ts +5 -37
  74. package/js/src/delta.js +3 -1
  75. package/js/src/digifinex.d.ts +5 -13
  76. package/js/src/digifinex.js +4 -2
  77. package/js/src/exmo.d.ts +5 -37
  78. package/js/src/exmo.js +11 -12
  79. package/js/src/gate.d.ts +5 -33
  80. package/js/src/gate.js +13 -10
  81. package/js/src/hitbtc.d.ts +5 -12
  82. package/js/src/hitbtc.js +26 -2
  83. package/js/src/htx.js +2 -2
  84. package/js/src/huobijp.js +1 -1
  85. package/js/src/hyperliquid.d.ts +7 -4
  86. package/js/src/hyperliquid.js +249 -12
  87. package/js/src/idex.js +1 -1
  88. package/js/src/krakenfutures.js +4 -7
  89. package/js/src/kucoin.js +7 -4
  90. package/js/src/kucoinfutures.d.ts +2 -2
  91. package/js/src/lbank.js +3 -0
  92. package/js/src/mexc.d.ts +3 -3
  93. package/js/src/mexc.js +1 -1
  94. package/js/src/oceanex.js +1 -1
  95. package/js/src/okx.d.ts +5 -33
  96. package/js/src/okx.js +24 -10
  97. package/js/src/phemex.d.ts +3 -11
  98. package/js/src/phemex.js +3 -1
  99. package/js/src/pro/kucoin.js +11 -6
  100. package/js/src/wazirx.js +1 -1
  101. package/js/src/zonda.js +3 -0
  102. package/package.json +3 -2
  103. package/skip-tests.json +3 -3
package/js/src/gate.js CHANGED
@@ -1862,7 +1862,7 @@ export default class gate extends Exchange {
1862
1862
  await this.loadMarkets();
1863
1863
  const currency = this.currency(code);
1864
1864
  const request = {
1865
- 'currency': currency['id'],
1865
+ 'currency': currency['id'], // todo: currencies have network-junctions
1866
1866
  };
1867
1867
  const response = await this.privateWalletGetDepositAddress(this.extend(request, params));
1868
1868
  const addresses = this.safeValue(response, 'multichain_addresses');
@@ -1913,7 +1913,7 @@ export default class gate extends Exchange {
1913
1913
  const rawNetwork = this.safeStringUpper(params, 'network');
1914
1914
  params = this.omit(params, 'network');
1915
1915
  const request = {
1916
- 'currency': currency['id'],
1916
+ 'currency': currency['id'], // todo: currencies have network-junctions
1917
1917
  };
1918
1918
  const response = await this.privateWalletGetDepositAddress(this.extend(request, params));
1919
1919
  //
@@ -3529,7 +3529,7 @@ export default class gate extends Exchange {
3529
3529
  let currency = undefined;
3530
3530
  if (code !== undefined) {
3531
3531
  currency = this.currency(code);
3532
- request['currency'] = currency['id'];
3532
+ request['currency'] = currency['id']; // todo: currencies have network-junctions
3533
3533
  }
3534
3534
  if (limit !== undefined) {
3535
3535
  request['limit'] = limit;
@@ -3567,7 +3567,7 @@ export default class gate extends Exchange {
3567
3567
  let currency = undefined;
3568
3568
  if (code !== undefined) {
3569
3569
  currency = this.currency(code);
3570
- request['currency'] = currency['id'];
3570
+ request['currency'] = currency['id']; // todo: currencies have network-junctions
3571
3571
  }
3572
3572
  if (limit !== undefined) {
3573
3573
  request['limit'] = limit;
@@ -3614,7 +3614,7 @@ export default class gate extends Exchange {
3614
3614
  params = this.omit(params, 'network');
3615
3615
  }
3616
3616
  else {
3617
- request['chain'] = currency['id'];
3617
+ request['chain'] = currency['id']; // todo: currencies have network-junctions
3618
3618
  }
3619
3619
  const response = await this.privateWithdrawalsPostWithdrawals(this.extend(request, params));
3620
3620
  //
@@ -5148,7 +5148,7 @@ export default class gate extends Exchange {
5148
5148
  params = this.omit(params, 'symbol');
5149
5149
  }
5150
5150
  if ((toId === 'futures') || (toId === 'delivery') || (fromId === 'futures') || (fromId === 'delivery')) {
5151
- request['settle'] = currency['id'];
5151
+ request['settle'] = currency['id']; // todo: currencies have network-junctions
5152
5152
  }
5153
5153
  const response = await this.privateWalletPostTransfers(this.extend(request, params));
5154
5154
  //
@@ -6118,11 +6118,14 @@ export default class gate extends Exchange {
6118
6118
  const total = this.safeNumber(data, 'margin');
6119
6119
  return {
6120
6120
  'info': data,
6121
- 'amount': undefined,
6122
- 'code': this.safeValue(market, 'quote'),
6123
6121
  'symbol': market['symbol'],
6122
+ 'type': undefined,
6123
+ 'amount': undefined,
6124
6124
  'total': total,
6125
+ 'code': this.safeValue(market, 'quote'),
6125
6126
  'status': 'ok',
6127
+ 'timestamp': undefined,
6128
+ 'datetime': undefined,
6126
6129
  };
6127
6130
  }
6128
6131
  async reduceMargin(symbol, amount, params = {}) {
@@ -6453,7 +6456,7 @@ export default class gate extends Exchange {
6453
6456
  if ((type === 'spot') || (type === 'margin')) {
6454
6457
  if (code !== undefined) {
6455
6458
  currency = this.currency(code);
6456
- request['currency'] = currency['id'];
6459
+ request['currency'] = currency['id']; // todo: currencies have network-junctions
6457
6460
  }
6458
6461
  }
6459
6462
  if ((type === 'swap') || (type === 'future')) {
@@ -7272,7 +7275,7 @@ export default class gate extends Exchange {
7272
7275
  await this.loadMarkets();
7273
7276
  const currency = this.currency(code);
7274
7277
  const request = {
7275
- 'underlying': currency['code'] + '_USDT',
7278
+ 'underlying': currency['code'] + '_USDT', // todo: currency['id'].toUpperCase () & network junctions
7276
7279
  };
7277
7280
  const response = await this.publicOptionsGetContracts(this.extend(request, params));
7278
7281
  //
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/hitbtc.js';
2
- import type { TransferEntry, Int, OrderSide, OrderType, FundingRateHistory, OHLCV, Ticker, Order, OrderBook, Dictionary, Position, Str, Trade, Balances, Transaction, MarginMode, Tickers, Strings, Market, Currency, MarginModes, Leverage, Num } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, OrderType, FundingRateHistory, OHLCV, Ticker, Order, OrderBook, Dictionary, Position, Str, Trade, Balances, Transaction, MarginMode, Tickers, Strings, Market, Currency, MarginModes, Leverage, Num, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class hitbtc
5
5
  * @augments Exchange
@@ -132,17 +132,10 @@ export default class hitbtc extends Exchange {
132
132
  previousFundingTimestamp: any;
133
133
  previousFundingDatetime: any;
134
134
  };
135
- modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<any>;
136
- parseMarginModification(data: any, market?: Market): {
137
- info: any;
138
- type: any;
139
- amount: any;
140
- code: string;
141
- symbol: string;
142
- status: any;
143
- };
144
- reduceMargin(symbol: string, amount: any, params?: {}): Promise<any>;
145
- addMargin(symbol: string, amount: any, params?: {}): Promise<any>;
135
+ modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<MarginModification>;
136
+ parseMarginModification(data: any, market?: Market): MarginModification;
137
+ reduceMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
138
+ addMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
146
139
  fetchLeverage(symbol: string, params?: {}): Promise<Leverage>;
147
140
  parseLeverage(leverage: any, market?: any): Leverage;
148
141
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
package/js/src/hitbtc.js CHANGED
@@ -1737,7 +1737,7 @@ export default class hitbtc extends Exchange {
1737
1737
  }
1738
1738
  [request, params] = this.handleUntilOption('till', request, params);
1739
1739
  if (limit !== undefined) {
1740
- request['limit'] = limit;
1740
+ request['limit'] = Math.min(limit, 1000);
1741
1741
  }
1742
1742
  const price = this.safeString(params, 'price');
1743
1743
  params = this.omit(params, 'price');
@@ -3295,15 +3295,39 @@ export default class hitbtc extends Exchange {
3295
3295
  });
3296
3296
  }
3297
3297
  parseMarginModification(data, market = undefined) {
3298
+ //
3299
+ // addMargin/reduceMargin
3300
+ //
3301
+ // {
3302
+ // "symbol": "BTCUSDT_PERP",
3303
+ // "type": "isolated",
3304
+ // "leverage": "8.00",
3305
+ // "created_at": "2022-03-30T23:34:27.161Z",
3306
+ // "updated_at": "2022-03-30T23:34:27.161Z",
3307
+ // "currencies": [
3308
+ // {
3309
+ // "code": "USDT",
3310
+ // "margin_balance": "7.000000000000",
3311
+ // "reserved_orders": "0",
3312
+ // "reserved_positions": "0"
3313
+ // }
3314
+ // ],
3315
+ // "positions": null
3316
+ // }
3317
+ //
3298
3318
  const currencies = this.safeValue(data, 'currencies', []);
3299
3319
  const currencyInfo = this.safeValue(currencies, 0);
3320
+ const datetime = this.safeString(data, 'updated_at');
3300
3321
  return {
3301
3322
  'info': data,
3323
+ 'symbol': market['symbol'],
3302
3324
  'type': undefined,
3303
3325
  'amount': undefined,
3326
+ 'total': undefined,
3304
3327
  'code': this.safeString(currencyInfo, 'code'),
3305
- 'symbol': market['symbol'],
3306
3328
  'status': undefined,
3329
+ 'timestamp': this.parse8601(datetime),
3330
+ 'datetime': datetime,
3307
3331
  };
3308
3332
  }
3309
3333
  async reduceMargin(symbol, amount, params = {}) {
package/js/src/htx.js CHANGED
@@ -2965,7 +2965,7 @@ export default class htx extends Exchange {
2965
2965
  const untilSeconds = (until !== undefined) ? this.parseToInt(until / 1000) : undefined;
2966
2966
  if (market['contract']) {
2967
2967
  if (limit !== undefined) {
2968
- request['size'] = limit; // when using limit: from & to are ignored
2968
+ request['size'] = Math.min(limit, 2000); // when using limit: from & to are ignored
2969
2969
  // https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data
2970
2970
  }
2971
2971
  else {
@@ -3057,7 +3057,7 @@ export default class htx extends Exchange {
3057
3057
  [useHistorical, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'useHistoricalEndpointForSpot', true);
3058
3058
  if (!useHistorical) {
3059
3059
  if (limit !== undefined) {
3060
- request['size'] = Math.min(2000, limit); // max 2000
3060
+ request['size'] = Math.min(limit, 2000); // max 2000
3061
3061
  }
3062
3062
  response = await this.spotPublicGetMarketHistoryKline(this.extend(request, params));
3063
3063
  }
package/js/src/huobijp.js CHANGED
@@ -955,7 +955,7 @@ export default class huobijp extends Exchange {
955
955
  'period': this.safeString(this.timeframes, timeframe, timeframe),
956
956
  };
957
957
  if (limit !== undefined) {
958
- request['size'] = limit;
958
+ request['size'] = Math.min(limit, 2000);
959
959
  }
960
960
  const response = await this.marketGetHistoryKline(this.extend(request, params));
961
961
  //
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/hyperliquid.js';
2
- import type { Market, TransferEntry, Balances, Int, OrderBook, OHLCV, Str, FundingRateHistory, Order, OrderType, OrderSide, Trade, Strings, Position, OrderRequest, Dict, Num } from './base/types.js';
2
+ import type { Market, TransferEntry, Balances, Int, OrderBook, OHLCV, Str, FundingRateHistory, Order, OrderType, OrderSide, Trade, Strings, Position, OrderRequest, Dict, Num, MarginModification } from './base/types.js';
3
3
  /**
4
4
  * @class hyperliquid
5
5
  * @augments Exchange
@@ -9,6 +9,8 @@ export default class hyperliquid extends Exchange {
9
9
  setSandboxMode(enabled: any): void;
10
10
  fetchCurrencies(params?: {}): Promise<{}>;
11
11
  fetchMarkets(params?: {}): Promise<Market[]>;
12
+ fetchSwapMarkets(params?: {}): Promise<Market[]>;
13
+ fetchSpotMarkets(params?: {}): Promise<Market[]>;
12
14
  parseMarket(market: any): Market;
13
15
  fetchBalance(params?: {}): Promise<Balances>;
14
16
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
@@ -68,9 +70,10 @@ export default class hyperliquid extends Exchange {
68
70
  parsePosition(position: any, market?: Market): Position;
69
71
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
70
72
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
71
- addMargin(symbol: string, amount: any, params?: {}): Promise<any>;
72
- reduceMargin(symbol: string, amount: any, params?: {}): Promise<any>;
73
- modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<any>;
73
+ addMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
74
+ reduceMargin(symbol: string, amount: any, params?: {}): Promise<MarginModification>;
75
+ modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<MarginModification>;
76
+ parseMarginModification(data: any, market?: Market): MarginModification;
74
77
  transfer(code: string, amount: number, fromAccount: string, toAccount: string, params?: {}): Promise<TransferEntry>;
75
78
  withdraw(code: string, amount: any, address: any, tag?: any, params?: {}): Promise<any>;
76
79
  formatVaultAddress(address?: Str): string;
@@ -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
@@ -466,7 +466,7 @@ export default class idex extends Exchange {
466
466
  request['start'] = since;
467
467
  }
468
468
  if (limit !== undefined) {
469
- request['limit'] = limit;
469
+ request['limit'] = Math.min(limit, 1000);
470
470
  }
471
471
  const response = await this.publicGetCandles(this.extend(request, params));
472
472
  if (Array.isArray(response)) {
@@ -355,7 +355,8 @@ export default class krakenfutures extends Exchange {
355
355
  // swap == perpetual
356
356
  let settle = undefined;
357
357
  let settleId = undefined;
358
- const amountPrecision = this.parseNumber(this.parsePrecision(this.safeString(market, 'contractValueTradePrecision', '0')));
358
+ const cvtp = this.safeString(market, 'contractValueTradePrecision');
359
+ const amountPrecision = this.parseNumber(this.integerPrecisionToAmount(cvtp));
359
360
  const pricePrecision = this.safeNumber(market, 'tickSize');
360
361
  const contract = (swap || future || index);
361
362
  const swapOrFutures = (swap || future);
@@ -644,17 +645,13 @@ export default class krakenfutures extends Exchange {
644
645
  if (limit === undefined) {
645
646
  limit = 5000;
646
647
  }
647
- else if (limit > 5000) {
648
- throw new BadRequest(this.id + ' fetchOHLCV() limit cannot exceed 5000');
649
- }
648
+ limit = Math.min(limit, 5000);
650
649
  const toTimestamp = this.sum(request['from'], limit * duration - 1);
651
650
  const currentTimestamp = this.seconds();
652
651
  request['to'] = Math.min(toTimestamp, currentTimestamp);
653
652
  }
654
653
  else if (limit !== undefined) {
655
- if (limit > 5000) {
656
- throw new BadRequest(this.id + ' fetchOHLCV() limit cannot exceed 5000');
657
- }
654
+ limit = Math.min(limit, 5000);
658
655
  const duration = this.parseTimeframe(timeframe);
659
656
  request['to'] = this.seconds();
660
657
  request['from'] = this.parseToInt(request['to'] - (duration * limit));