ccxt 4.2.16 → 4.2.18

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 (53) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.js +546 -276
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/js/ccxt.js +3 -1
  6. package/dist/cjs/js/src/base/Exchange.js +5 -2
  7. package/dist/cjs/js/src/binance.js +7 -0
  8. package/dist/cjs/js/src/bingx.js +26 -0
  9. package/dist/cjs/js/src/bybit.js +21 -47
  10. package/dist/cjs/js/src/coincheck.js +1 -0
  11. package/dist/cjs/js/src/coinlist.js +10 -2
  12. package/dist/cjs/js/src/coinsph.js +2 -2
  13. package/dist/cjs/js/src/deribit.js +5 -1
  14. package/dist/cjs/js/src/kraken.js +1 -1
  15. package/dist/cjs/js/src/pro/binance.js +3 -3
  16. package/dist/cjs/js/src/pro/bitget.js +1 -1
  17. package/dist/cjs/js/src/pro/coincheck.js +208 -0
  18. package/dist/cjs/js/src/pro/hitbtc.js +5 -4
  19. package/dist/cjs/js/src/pro/kucoin.js +46 -36
  20. package/dist/cjs/js/src/pro/kucoinfutures.js +45 -37
  21. package/dist/cjs/js/src/pro/poloniex.js +2 -2
  22. package/dist/cjs/js/src/pro/poloniexfutures.js +43 -35
  23. package/dist/cjs/js/src/whitebit.js +1 -0
  24. package/js/ccxt.d.ts +4 -1
  25. package/js/ccxt.js +3 -1
  26. package/js/src/abstract/binance.d.ts +1 -0
  27. package/js/src/abstract/binancecoinm.d.ts +1 -0
  28. package/js/src/abstract/binanceus.d.ts +1 -0
  29. package/js/src/abstract/binanceusdm.d.ts +1 -0
  30. package/js/src/abstract/coinlist.d.ts +8 -0
  31. package/js/src/base/Exchange.d.ts +2 -3
  32. package/js/src/base/Exchange.js +5 -2
  33. package/js/src/binance.js +7 -0
  34. package/js/src/bingx.d.ts +1 -0
  35. package/js/src/bingx.js +26 -0
  36. package/js/src/bybit.js +21 -47
  37. package/js/src/coincheck.js +1 -0
  38. package/js/src/coinlist.js +10 -2
  39. package/js/src/coinsph.js +2 -2
  40. package/js/src/deribit.js +5 -1
  41. package/js/src/kraken.js +1 -1
  42. package/js/src/pro/binance.js +3 -3
  43. package/js/src/pro/bitget.js +1 -1
  44. package/js/src/pro/coincheck.d.ts +12 -0
  45. package/js/src/pro/coincheck.js +209 -0
  46. package/js/src/pro/hitbtc.js +5 -4
  47. package/js/src/pro/kucoin.js +46 -36
  48. package/js/src/pro/kucoinfutures.js +45 -37
  49. package/js/src/pro/poloniex.js +2 -2
  50. package/js/src/pro/poloniexfutures.js +43 -35
  51. package/js/src/whitebit.js +1 -0
  52. package/package.json +1 -1
  53. package/skip-tests.json +12 -1
package/dist/cjs/ccxt.js CHANGED
@@ -169,7 +169,7 @@ var woo$1 = require('./src/pro/woo.js');
169
169
 
170
170
  //-----------------------------------------------------------------------------
171
171
  // this is updated by vss.js when building
172
- const version = '4.2.16';
172
+ const version = '4.2.18';
173
173
  Exchange["default"].ccxtVersion = version;
174
174
  const exchanges = {
175
175
  'ace': ace,
@@ -134,6 +134,7 @@ var bybit$1 = require('./src/pro/bybit.js');
134
134
  var cex$1 = require('./src/pro/cex.js');
135
135
  var coinbase$1 = require('./src/pro/coinbase.js');
136
136
  var coinbasepro$1 = require('./src/pro/coinbasepro.js');
137
+ var coincheck$1 = require('./src/pro/coincheck.js');
137
138
  var coinex$1 = require('./src/pro/coinex.js');
138
139
  var coinone$1 = require('./src/pro/coinone.js');
139
140
  var cryptocom$1 = require('./src/pro/cryptocom.js');
@@ -170,7 +171,7 @@ var woo$1 = require('./src/pro/woo.js');
170
171
 
171
172
  //-----------------------------------------------------------------------------
172
173
  // this is updated by vss.js when building
173
- const version = '4.2.15';
174
+ const version = '4.2.17';
174
175
  Exchange["default"].ccxtVersion = version;
175
176
  const exchanges = {
176
177
  'ace': ace,
@@ -297,6 +298,7 @@ const pro = {
297
298
  'cex': cex$1,
298
299
  'coinbase': coinbase$1,
299
300
  'coinbasepro': coinbasepro$1,
301
+ 'coincheck': coincheck$1,
300
302
  'coinex': coinex$1,
301
303
  'coinone': coinone$1,
302
304
  'cryptocom': cryptocom$1,
@@ -441,7 +441,7 @@ class Exchange {
441
441
  'fetchPositionsForSymbol': undefined,
442
442
  'fetchPositionsRisk': undefined,
443
443
  'fetchPremiumIndexOHLCV': undefined,
444
- 'fetchStatus': 'emulated',
444
+ 'fetchStatus': undefined,
445
445
  'fetchTicker': true,
446
446
  'fetchTickers': undefined,
447
447
  'fetchTime': undefined,
@@ -1023,7 +1023,10 @@ class Exchange {
1023
1023
  }
1024
1024
  spawn(method, ...args) {
1025
1025
  const future = Future.Future();
1026
- method.apply(this, args).then(future.resolve).catch(future.reject);
1026
+ // using setTimeout 0 to force the execution to run after the future is returned
1027
+ setTimeout(() => {
1028
+ method.apply(this, args).then(future.resolve).catch(future.reject);
1029
+ }, 0);
1027
1030
  return future;
1028
1031
  }
1029
1032
  delay(timeout, method, ...args) {
@@ -222,6 +222,7 @@ class binance extends binance$1 {
222
222
  'margin/allPairs': 0.1,
223
223
  'margin/priceIndex': 1,
224
224
  // these endpoints require this.apiKey + this.secret
225
+ 'spot/delist-schedule': 10,
225
226
  'asset/assetDividend': 1,
226
227
  'asset/dribblet': 0.1,
227
228
  'asset/transfer': 0.1,
@@ -5579,6 +5580,7 @@ class binance extends binance$1 {
5579
5580
  * @param {int} [since] the earliest time in ms to fetch my dust trades for
5580
5581
  * @param {int} [limit] the maximum number of dust trades to retrieve
5581
5582
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5583
+ * @param {string} [params.type] 'spot' or 'margin', default spot
5582
5584
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
5583
5585
  */
5584
5586
  //
@@ -5593,6 +5595,11 @@ class binance extends binance$1 {
5593
5595
  request['startTime'] = since;
5594
5596
  request['endTime'] = this.sum(since, 7776000000);
5595
5597
  }
5598
+ const accountType = this.safeStringUpper(params, 'type');
5599
+ params = this.omit(params, 'type');
5600
+ if (accountType !== undefined) {
5601
+ request['accountType'] = accountType;
5602
+ }
5596
5603
  const response = await this.sapiGetAssetDribblet(this.extend(request, params));
5597
5604
  // {
5598
5605
  // "total": "4",
@@ -50,6 +50,7 @@ class bingx extends bingx$1 {
50
50
  'fetchDepositWithdrawFee': 'emulated',
51
51
  'fetchDepositWithdrawFees': true,
52
52
  'fetchFundingRate': true,
53
+ 'fetchFundingRates': true,
53
54
  'fetchFundingRateHistory': true,
54
55
  'fetchLeverage': true,
55
56
  'fetchLiquidations': false,
@@ -1110,6 +1111,31 @@ class bingx extends bingx$1 {
1110
1111
  const data = this.safeValue(response, 'data', {});
1111
1112
  return this.parseFundingRate(data, market);
1112
1113
  }
1114
+ async fetchFundingRates(symbols = undefined, params = {}) {
1115
+ /**
1116
+ * @method
1117
+ * @name bingx#fetchFundingRate
1118
+ * @description fetch the current funding rate
1119
+ * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Current%20Funding%20Rate
1120
+ * @param {string[]} [symbols] list of unified market symbols
1121
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1122
+ * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
1123
+ */
1124
+ await this.loadMarkets();
1125
+ symbols = this.marketSymbols(symbols, 'swap', true);
1126
+ const response = await this.swapV2PublicGetQuotePremiumIndex(this.extend(params));
1127
+ const data = this.safeValue(response, 'data', []);
1128
+ const filteredResponse = [];
1129
+ for (let i = 0; i < data.length; i++) {
1130
+ const item = data[i];
1131
+ const marketId = this.safeString(item, 'symbol');
1132
+ const market = this.safeMarket(marketId, undefined, undefined, 'swap');
1133
+ if ((symbols === undefined) || this.inArray(market['symbol'], symbols)) {
1134
+ filteredResponse.push(this.parseFundingRate(item, market));
1135
+ }
1136
+ }
1137
+ return filteredResponse;
1138
+ }
1113
1139
  parseFundingRate(contract, market = undefined) {
1114
1140
  //
1115
1141
  // {
@@ -3963,7 +3963,7 @@ class bybit extends bybit$1 {
3963
3963
  response = await this.privatePostOptionUsdcOpenapiPrivateV1ReplaceOrder(this.extend(request, params));
3964
3964
  }
3965
3965
  else {
3966
- const isStop = this.safeValue(params, 'stop', false);
3966
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
3967
3967
  const triggerPrice = this.safeValue2(params, 'stopPrice', 'triggerPrice');
3968
3968
  const stopLossPrice = this.safeValue(params, 'stopLossPrice');
3969
3969
  const isStopLossOrder = stopLossPrice !== undefined;
@@ -4142,8 +4142,8 @@ class bybit extends bybit$1 {
4142
4142
  // 'orderLinkId': 'string', // one of order_id, stop_order_id or order_link_id is required
4143
4143
  // 'orderId': id,
4144
4144
  };
4145
- const isStop = this.safeValue(params, 'stop', false);
4146
- params = this.omit(params, ['stop']);
4145
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
4146
+ params = this.omit(params, ['stop', 'trigger']);
4147
4147
  if (id !== undefined) { // The user can also use argument params["order_link_id"]
4148
4148
  request['orderId'] = id;
4149
4149
  }
@@ -4204,9 +4204,9 @@ class bybit extends bybit$1 {
4204
4204
  };
4205
4205
  if (market['spot']) {
4206
4206
  // only works for spot market
4207
- const isStop = this.safeValue(params, 'stop', false);
4208
- params = this.omit(params, ['stop']);
4209
- request['orderFilter'] = isStop ? 'tpslOrder' : 'Order';
4207
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
4208
+ params = this.omit(params, ['stop', 'trigger']);
4209
+ request['orderFilter'] = isStop ? 'StopOrder' : 'Order';
4210
4210
  }
4211
4211
  if (id !== undefined) { // The user can also use argument params["orderLinkId"]
4212
4212
  request['orderId'] = id;
@@ -4253,14 +4253,14 @@ class bybit extends bybit$1 {
4253
4253
  response = await this.privatePostOptionUsdcOpenapiPrivateV1CancelAll(this.extend(request, params));
4254
4254
  }
4255
4255
  else {
4256
- const isStop = this.safeValue(params, 'stop', false);
4256
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
4257
4257
  if (isStop) {
4258
4258
  request['orderFilter'] = 'StopOrder';
4259
4259
  }
4260
4260
  else {
4261
4261
  request['orderFilter'] = 'Order';
4262
4262
  }
4263
- params = this.omit(params, ['stop']);
4263
+ params = this.omit(params, ['stop', 'trigger']);
4264
4264
  response = await this.privatePostPerpetualUsdcOpenapiPrivateV1CancelAll(this.extend(request, params));
4265
4265
  }
4266
4266
  //
@@ -4327,10 +4327,10 @@ class bybit extends bybit$1 {
4327
4327
  request['settleCoin'] = this.safeString(params, 'settleCoin', defaultSettle);
4328
4328
  }
4329
4329
  }
4330
- const isStop = this.safeValue(params, 'stop', false);
4331
- params = this.omit(params, ['stop']);
4330
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
4331
+ params = this.omit(params, ['stop', 'trigger']);
4332
4332
  if (isStop) {
4333
- request['orderFilter'] = 'tpslOrder';
4333
+ request['orderFilter'] = 'StopOrder';
4334
4334
  }
4335
4335
  const response = await this.privatePostV5OrderCancelAll(this.extend(request, params));
4336
4336
  //
@@ -4395,8 +4395,8 @@ class bybit extends bybit$1 {
4395
4395
  else {
4396
4396
  request['category'] = 'OPTION';
4397
4397
  }
4398
- const isStop = this.safeValue(params, 'stop', false);
4399
- params = this.omit(params, ['stop']);
4398
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
4399
+ params = this.omit(params, ['stop', 'trigger']);
4400
4400
  if (isStop) {
4401
4401
  request['orderFilter'] = 'StopOrder';
4402
4402
  }
@@ -4498,12 +4498,7 @@ class bybit extends bybit$1 {
4498
4498
  const isStop = this.safeValueN(params, ['trigger', 'stop'], false);
4499
4499
  params = this.omit(params, ['trigger', 'stop']);
4500
4500
  if (isStop) {
4501
- if (type === 'spot') {
4502
- request['orderFilter'] = 'tpslOrder';
4503
- }
4504
- else {
4505
- request['orderFilter'] = 'StopOrder';
4506
- }
4501
+ request['orderFilter'] = 'StopOrder';
4507
4502
  }
4508
4503
  if (limit !== undefined) {
4509
4504
  request['limit'] = limit;
@@ -4662,7 +4657,7 @@ class bybit extends bybit$1 {
4662
4657
  * @param {int} [since] the earliest time in ms to fetch open orders for
4663
4658
  * @param {int} [limit] the maximum number of open orders structures to retrieve
4664
4659
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4665
- * @param {boolean} [params.stop] true if stop order
4660
+ * @param {boolean} [params.stop] set to true for fetching open stop orders
4666
4661
  * @param {string} [params.type] market type, ['swap', 'option', 'spot']
4667
4662
  * @param {string} [params.subType] market subType, ['linear', 'inverse']
4668
4663
  * @param {string} [params.baseCoin] Base coin. Supports linear, inverse & option
@@ -4696,15 +4691,10 @@ class bybit extends bybit$1 {
4696
4691
  return await this.fetchUsdcOpenOrders(symbol, since, limit, params);
4697
4692
  }
4698
4693
  request['category'] = type;
4699
- const isStop = this.safeValue(params, 'stop', false);
4700
- params = this.omit(params, ['stop']);
4694
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
4695
+ params = this.omit(params, ['stop', 'trigger']);
4701
4696
  if (isStop) {
4702
- if (type === 'spot') {
4703
- request['orderFilter'] = 'tpslOrder';
4704
- }
4705
- else {
4706
- request['orderFilter'] = 'StopOrder';
4707
- }
4697
+ request['orderFilter'] = 'StopOrder';
4708
4698
  }
4709
4699
  if (limit !== undefined) {
4710
4700
  request['limit'] = limit;
@@ -4836,12 +4826,11 @@ class bybit extends bybit$1 {
4836
4826
  * @method
4837
4827
  * @name bybit#fetchMyTrades
4838
4828
  * @description fetch all trades made by the user
4839
- * @see https://bybit-exchange.github.io/docs/v5/position/execution
4829
+ * @see https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution
4840
4830
  * @param {string} symbol unified market symbol
4841
4831
  * @param {int} [since] the earliest time in ms to fetch trades for
4842
4832
  * @param {int} [limit] the maximum number of trades structures to retrieve
4843
4833
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4844
- * @param {boolean} [params.stop] true if stop order
4845
4834
  * @param {string} [params.type] market type, ['swap', 'option', 'spot']
4846
4835
  * @param {string} [params.subType] market subType, ['linear', 'inverse']
4847
4836
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
@@ -4855,7 +4844,7 @@ class bybit extends bybit$1 {
4855
4844
  }
4856
4845
  const [enableUnifiedMargin, enableUnifiedAccount] = await this.isUnifiedEnabled();
4857
4846
  const isUnifiedAccount = (enableUnifiedMargin || enableUnifiedAccount);
4858
- const request = {};
4847
+ let request = {};
4859
4848
  let market = undefined;
4860
4849
  let isUsdcSettled = false;
4861
4850
  if (symbol !== undefined) {
@@ -4869,28 +4858,13 @@ class bybit extends bybit$1 {
4869
4858
  return await this.fetchMyUsdcTrades(symbol, since, limit, params);
4870
4859
  }
4871
4860
  request['category'] = type;
4872
- const isStop = this.safeValue(params, 'stop', false);
4873
- params = this.omit(params, ['stop', 'type']);
4874
- if (isStop) {
4875
- if (type === 'spot') {
4876
- request['orderFilter'] = 'tpslOrder';
4877
- }
4878
- else {
4879
- request['orderFilter'] = 'StopOrder';
4880
- }
4881
- }
4882
4861
  if (limit !== undefined) {
4883
4862
  request['limit'] = limit;
4884
4863
  }
4885
4864
  if (since !== undefined) {
4886
4865
  request['startTime'] = since;
4887
4866
  }
4888
- const until = this.safeInteger2(params, 'until', 'till'); // unified in milliseconds
4889
- const endTime = this.safeInteger(params, 'endTime', until); // exchange-specific in milliseconds
4890
- params = this.omit(params, ['endTime', 'till', 'until']);
4891
- if (endTime !== undefined) {
4892
- request['endTime'] = endTime;
4893
- }
4867
+ [request, params] = this.handleUntilOption('endTime', request, params);
4894
4868
  const response = await this.privateGetV5ExecutionList(this.extend(request, params));
4895
4869
  //
4896
4870
  // {
@@ -65,6 +65,7 @@ class coincheck extends coincheck$1 {
65
65
  'setLeverage': false,
66
66
  'setMarginMode': false,
67
67
  'setPositionMode': false,
68
+ 'ws': true,
68
69
  },
69
70
  'urls': {
70
71
  'logo': 'https://user-images.githubusercontent.com/51840849/87182088-1d6d6380-c2ec-11ea-9c64-8ab9f9b289f5.jpg',
@@ -148,6 +148,9 @@ class coinlist extends coinlist$1 {
148
148
  'v1/symbols/{symbol}/auctions/{auction_code}': 1,
149
149
  'v1/time': 1,
150
150
  'v1/assets': 1,
151
+ 'v1/leaderboard': 1,
152
+ 'v1/affiliate/{competition_code}': 1,
153
+ 'v1/competition/{competition_id}': 1,
151
154
  },
152
155
  },
153
156
  'private': {
@@ -155,6 +158,7 @@ class coinlist extends coinlist$1 {
155
158
  'v1/fees': 1,
156
159
  'v1/accounts': 1,
157
160
  'v1/accounts/{trader_id}': 1,
161
+ 'v1/accounts/{trader_id}/alias': 1,
158
162
  'v1/accounts/{trader_id}/ledger': 1,
159
163
  'v1/accounts/{trader_id}/wallets': 1,
160
164
  'v1/accounts/{trader_id}/wallet-ledger': 1,
@@ -167,7 +171,9 @@ class coinlist extends coinlist$1 {
167
171
  'v1/balances': 1,
168
172
  'v1/transfers': 1,
169
173
  'v1/user': 1,
170
- 'v1/credits': 1, // not unified
174
+ 'v1/credits': 1,
175
+ 'v1/positions': 1,
176
+ 'v1/accounts/{trader_id}/competitions': 1,
171
177
  },
172
178
  'post': {
173
179
  'v1/keys': 1,
@@ -178,7 +184,9 @@ class coinlist extends coinlist$1 {
178
184
  'v1/transfers/from-wallet': 1,
179
185
  'v1/transfers/internal-transfer': 1,
180
186
  'v1/transfers/withdrawal-request': 1,
181
- 'v1/orders/bulk': 1, // not unified
187
+ 'v1/orders/bulk': 1,
188
+ 'v1/accounts/{trader_id}/competitions': 1,
189
+ 'v1/accounts/{trader_id}/create-competition': 1,
182
190
  },
183
191
  'patch': {
184
192
  'v1/orders/{order_id}': 1,
@@ -996,10 +996,10 @@ class coinsph extends coinsph$1 {
996
996
  'currency': this.safeCurrencyCode(feeCurrencyId),
997
997
  };
998
998
  }
999
- const isBuyer = this.safeString2(trade, 'isBuyer', 'isBuyerMaker', undefined);
999
+ const isBuyer = this.safeValue2(trade, 'isBuyer', 'isBuyerMaker', undefined);
1000
1000
  let side = undefined;
1001
1001
  if (isBuyer !== undefined) {
1002
- side = (isBuyer === 'true') ? 'buy' : 'sell';
1002
+ side = (isBuyer === true) ? 'buy' : 'sell';
1003
1003
  }
1004
1004
  const isMaker = this.safeString2(trade, 'isMaker', undefined);
1005
1005
  let takerOrMaker = undefined;
@@ -1683,6 +1683,10 @@ class deribit extends deribit$1 {
1683
1683
  const request = {
1684
1684
  'order_id': id,
1685
1685
  };
1686
+ let market = undefined;
1687
+ if (symbol !== undefined) {
1688
+ market = this.market(symbol);
1689
+ }
1686
1690
  const response = await this.privateGetGetOrderState(this.extend(request, params));
1687
1691
  //
1688
1692
  // {
@@ -1713,7 +1717,7 @@ class deribit extends deribit$1 {
1713
1717
  // }
1714
1718
  //
1715
1719
  const result = this.safeValue(response, 'result');
1716
- return this.parseOrder(result);
1720
+ return this.parseOrder(result, market);
1717
1721
  }
1718
1722
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1719
1723
  /**
@@ -103,7 +103,7 @@ class kraken extends kraken$1 {
103
103
  'zendesk': 'https://kraken.zendesk.com/api/v2/help_center/en-us/articles', // use the public zendesk api to receive article bodies and bypass new anti-spam protections
104
104
  },
105
105
  'www': 'https://www.kraken.com',
106
- 'doc': 'https://www.kraken.com/features/api',
106
+ 'doc': 'https://docs.kraken.com/rest/',
107
107
  'fees': 'https://www.kraken.com/en-us/features/fee-schedule',
108
108
  },
109
109
  'fees': {
@@ -142,7 +142,7 @@ class binance extends binance$1 {
142
142
  }
143
143
  const subscriptionsByStream = this.safeInteger(this.options['numSubscriptionsByStream'], stream, 0);
144
144
  const newNumSubscriptions = subscriptionsByStream + numSubscriptions;
145
- const subscriptionLimitByStream = this.safeInteger(this.options, 'subscriptionLimitByStream', 200);
145
+ const subscriptionLimitByStream = this.safeInteger(this.options['subscriptionLimitByStream'], type, 200);
146
146
  if (newNumSubscriptions > subscriptionLimitByStream) {
147
147
  throw new errors.BadRequest(this.id + ' reached the limit of subscriptions by stream. Increase the number of streams, or increase the stream limit or subscription limit by stream if the exchange allows.');
148
148
  }
@@ -1081,7 +1081,7 @@ class binance extends binance$1 {
1081
1081
  const isSpot = ((client.url.indexOf('/stream') > -1) || (client.url.indexOf('/testnet.binance') > -1));
1082
1082
  const marketType = (isSpot) ? 'spot' : 'contract';
1083
1083
  let rawTickers = [];
1084
- const newTickers = [];
1084
+ const newTickers = {};
1085
1085
  if (Array.isArray(message)) {
1086
1086
  rawTickers = message;
1087
1087
  }
@@ -1093,7 +1093,7 @@ class binance extends binance$1 {
1093
1093
  const result = this.parseWsTicker(ticker, marketType);
1094
1094
  const symbol = result['symbol'];
1095
1095
  this.tickers[symbol] = result;
1096
- newTickers.push(result);
1096
+ newTickers[symbol] = result;
1097
1097
  }
1098
1098
  const messageHashes = this.findMessageHashes(client, 'tickers::');
1099
1099
  for (let i = 0; i < messageHashes.length; i++) {
@@ -446,7 +446,7 @@ class bitget extends bitget$1 {
446
446
  symbols = this.marketSymbols(symbols);
447
447
  let channel = 'books';
448
448
  let incrementalFeed = true;
449
- if ((limit === 5) || (limit === 15)) {
449
+ if ((limit === 1) || (limit === 5) || (limit === 15)) {
450
450
  channel += limit.toString();
451
451
  incrementalFeed = false;
452
452
  }
@@ -0,0 +1,208 @@
1
+ 'use strict';
2
+
3
+ var coincheck$1 = require('../coincheck.js');
4
+ var errors = require('../base/errors.js');
5
+ var Cache = require('../base/ws/Cache.js');
6
+
7
+ // ---------------------------------------------------------------------------
8
+ // ---------------------------------------------------------------------------
9
+ class coincheck extends coincheck$1 {
10
+ describe() {
11
+ return this.deepExtend(super.describe(), {
12
+ 'has': {
13
+ 'ws': true,
14
+ 'watchOrderBook': true,
15
+ 'watchOrders': false,
16
+ 'watchTrades': true,
17
+ 'watchOHLCV': false,
18
+ 'watchTicker': false,
19
+ 'watchTickers': false,
20
+ },
21
+ 'urls': {
22
+ 'api': {
23
+ 'ws': 'wss://ws-api.coincheck.com/',
24
+ },
25
+ },
26
+ 'options': {
27
+ 'expiresIn': '',
28
+ 'userId': '',
29
+ 'wsSessionToken': '',
30
+ 'watchOrderBook': {
31
+ 'snapshotDelay': 6,
32
+ 'snapshotMaxRetries': 3,
33
+ },
34
+ 'tradesLimit': 1000,
35
+ 'OHLCVLimit': 1000,
36
+ },
37
+ 'exceptions': {
38
+ 'exact': {
39
+ '4009': errors.AuthenticationError,
40
+ },
41
+ },
42
+ });
43
+ }
44
+ async watchOrderBook(symbol, limit = undefined, params = {}) {
45
+ /**
46
+ * @method
47
+ * @name coincheck#watchOrderBook
48
+ * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
49
+ * @see https://coincheck.com/documents/exchange/api#websocket-order-book
50
+ * @param {string} symbol unified symbol of the market to fetch the order book for
51
+ * @param {int} [limit] the maximum amount of order book entries to return
52
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
53
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
54
+ */
55
+ await this.loadMarkets();
56
+ const market = this.market(symbol);
57
+ const messageHash = 'orderbook:' + market['symbol'];
58
+ const url = this.urls['api']['ws'];
59
+ const request = {
60
+ 'type': 'subscribe',
61
+ 'channel': market['id'] + '-orderbook',
62
+ };
63
+ const message = this.extend(request, params);
64
+ const orderbook = await this.watch(url, messageHash, message, messageHash);
65
+ return orderbook.limit();
66
+ }
67
+ handleOrderBook(client, message) {
68
+ //
69
+ // [
70
+ // "btc_jpy",
71
+ // {
72
+ // "bids": [
73
+ // [
74
+ // "6288279.0",
75
+ // "0"
76
+ // ]
77
+ // ],
78
+ // "asks": [
79
+ // [
80
+ // "6290314.0",
81
+ // "0"
82
+ // ]
83
+ // ],
84
+ // "last_update_at": "1705396097"
85
+ // }
86
+ // ]
87
+ //
88
+ const symbol = this.symbol(this.safeString(message, 0));
89
+ const data = this.safeValue(message, 1, {});
90
+ const timestamp = this.safeTimestamp(data, 'last_update_at');
91
+ const snapshot = this.parseOrderBook(data, symbol, timestamp);
92
+ let orderbook = this.safeValue(this.orderbooks, symbol);
93
+ if (orderbook === undefined) {
94
+ orderbook = this.orderBook(snapshot);
95
+ this.orderbooks[symbol] = orderbook;
96
+ }
97
+ else {
98
+ orderbook = this.orderbooks[symbol];
99
+ orderbook.reset(snapshot);
100
+ }
101
+ const messageHash = 'orderbook:' + symbol;
102
+ client.resolve(orderbook, messageHash);
103
+ }
104
+ async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
105
+ /**
106
+ * @method
107
+ * @name coincheck#watchTrades
108
+ * @description watches information on multiple trades made in a market
109
+ * @see https://coincheck.com/documents/exchange/api#websocket-trades
110
+ * @param {string} symbol unified market symbol of the market trades were made in
111
+ * @param {int} [since] the earliest time in ms to fetch trades for
112
+ * @param {int} [limit] the maximum number of trade structures to retrieve
113
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
114
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
115
+ */
116
+ await this.loadMarkets();
117
+ const market = this.market(symbol);
118
+ symbol = market['symbol'];
119
+ const messageHash = 'trade:' + market['symbol'];
120
+ const url = this.urls['api']['ws'];
121
+ const request = {
122
+ 'type': 'subscribe',
123
+ 'channel': market['id'] + '-trades',
124
+ };
125
+ const message = this.extend(request, params);
126
+ const trades = await this.watch(url, messageHash, message, messageHash);
127
+ if (this.newUpdates) {
128
+ limit = trades.getLimit(symbol, limit);
129
+ }
130
+ return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
131
+ }
132
+ handleTrades(client, message) {
133
+ //
134
+ // [
135
+ // [
136
+ // "1663318663", // transaction timestamp (unix time)
137
+ // "2357062", // transaction ID
138
+ // "btc_jpy", // pair
139
+ // "2820896.0", // transaction rate
140
+ // "5.0", // transaction amount
141
+ // "sell", // order side
142
+ // "1193401", // ID of the Taker
143
+ // "2078767" // ID of the Maker
144
+ // ]
145
+ // ]
146
+ //
147
+ const first = this.safeValue(message, 0, []);
148
+ const symbol = this.symbol(this.safeString(first, 2));
149
+ let stored = this.safeValue(this.trades, symbol);
150
+ if (stored === undefined) {
151
+ const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
152
+ stored = new Cache.ArrayCache(limit);
153
+ this.trades[symbol] = stored;
154
+ }
155
+ for (let i = 0; i < message.length; i++) {
156
+ const data = this.safeValue(message, i);
157
+ const trade = this.parseWsTrade(data);
158
+ stored.append(trade);
159
+ }
160
+ const messageHash = 'trade:' + symbol;
161
+ client.resolve(stored, messageHash);
162
+ }
163
+ parseWsTrade(trade, market = undefined) {
164
+ //
165
+ // [
166
+ // "1663318663", // transaction timestamp (unix time)
167
+ // "2357062", // transaction ID
168
+ // "btc_jpy", // pair
169
+ // "2820896.0", // transaction rate
170
+ // "5.0", // transaction amount
171
+ // "sell", // order side
172
+ // "1193401", // ID of the Taker
173
+ // "2078767" // ID of the Maker
174
+ // ]
175
+ //
176
+ const symbol = this.symbol(this.safeString(trade, 2));
177
+ const timestamp = this.safeTimestamp(trade, 0);
178
+ const side = this.safeString(trade, 5);
179
+ const priceString = this.safeString(trade, 3);
180
+ const amountString = this.safeString(trade, 4);
181
+ return this.safeTrade({
182
+ 'id': this.safeString(trade, 1),
183
+ 'info': trade,
184
+ 'timestamp': timestamp,
185
+ 'datetime': this.iso8601(timestamp),
186
+ 'order': undefined,
187
+ 'symbol': symbol,
188
+ 'type': undefined,
189
+ 'side': side,
190
+ 'takerOrMaker': undefined,
191
+ 'price': priceString,
192
+ 'amount': amountString,
193
+ 'cost': undefined,
194
+ 'fee': undefined,
195
+ }, market);
196
+ }
197
+ handleMessage(client, message) {
198
+ const data = this.safeValue(message, 0);
199
+ if (!Array.isArray(data)) {
200
+ this.handleOrderBook(client, message);
201
+ }
202
+ else {
203
+ this.handleTrades(client, message);
204
+ }
205
+ }
206
+ }
207
+
208
+ module.exports = coincheck;