ccxt 4.4.2 → 4.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +2 -2
  5. package/dist/cjs/src/base/functions/misc.js +11 -0
  6. package/dist/cjs/src/base/functions.js +1 -0
  7. package/dist/cjs/src/base/ws/WsClient.js +2 -1
  8. package/dist/cjs/src/binance.js +49 -22
  9. package/dist/cjs/src/bingx.js +1 -0
  10. package/dist/cjs/src/bitfinex2.js +7 -6
  11. package/dist/cjs/src/bitget.js +10 -6
  12. package/dist/cjs/src/bitmart.js +3 -1
  13. package/dist/cjs/src/bitmex.js +11 -10
  14. package/dist/cjs/src/bitso.js +5 -4
  15. package/dist/cjs/src/bitstamp.js +33 -45
  16. package/dist/cjs/src/blofin.js +21 -23
  17. package/dist/cjs/src/bybit.js +22 -20
  18. package/dist/cjs/src/coinbase.js +28 -7
  19. package/dist/cjs/src/coinbaseexchange.js +11 -11
  20. package/dist/cjs/src/coinlist.js +6 -5
  21. package/dist/cjs/src/coinmetro.js +3 -3
  22. package/dist/cjs/src/cryptocom.js +9 -6
  23. package/dist/cjs/src/currencycom.js +6 -6
  24. package/dist/cjs/src/delta.js +5 -5
  25. package/dist/cjs/src/digifinex.js +8 -6
  26. package/dist/cjs/src/gate.js +6 -5
  27. package/dist/cjs/src/hashkey.js +9 -7
  28. package/dist/cjs/src/htx.js +13 -16
  29. package/dist/cjs/src/hyperliquid.js +67 -114
  30. package/dist/cjs/src/kraken.js +8 -6
  31. package/dist/cjs/src/kucoin.js +9 -8
  32. package/dist/cjs/src/luno.js +10 -9
  33. package/dist/cjs/src/mexc.js +54 -2
  34. package/dist/cjs/src/ndax.js +6 -5
  35. package/dist/cjs/src/okcoin.js +18 -27
  36. package/dist/cjs/src/okx.js +18 -26
  37. package/dist/cjs/src/p2b.js +2 -2
  38. package/dist/cjs/src/pro/bybit.js +56 -0
  39. package/dist/cjs/src/pro/cryptocom.js +191 -21
  40. package/dist/cjs/src/pro/mexc.js +165 -3
  41. package/dist/cjs/src/pro/okx.js +6 -3
  42. package/dist/cjs/src/pro/oxfun.js +75 -0
  43. package/dist/cjs/src/pro/phemex.js +45 -1
  44. package/dist/cjs/src/pro/woofipro.js +67 -0
  45. package/dist/cjs/src/woo.js +7 -6
  46. package/dist/cjs/src/woofipro.js +8 -6
  47. package/dist/cjs/src/xt.js +10 -4
  48. package/dist/cjs/src/zonda.js +6 -5
  49. package/js/ccxt.d.ts +1 -1
  50. package/js/ccxt.js +1 -1
  51. package/js/src/abstract/bitmart.d.ts +1 -0
  52. package/js/src/base/Exchange.d.ts +2 -2
  53. package/js/src/base/Exchange.js +2 -2
  54. package/js/src/base/functions/misc.d.ts +2 -1
  55. package/js/src/base/functions/misc.js +11 -1
  56. package/js/src/base/types.d.ts +1 -1
  57. package/js/src/base/ws/WsClient.js +2 -2
  58. package/js/src/binance.d.ts +4 -20
  59. package/js/src/binance.js +49 -22
  60. package/js/src/bingx.js +1 -0
  61. package/js/src/bitfinex2.d.ts +3 -19
  62. package/js/src/bitfinex2.js +7 -6
  63. package/js/src/bitget.d.ts +3 -19
  64. package/js/src/bitget.js +10 -6
  65. package/js/src/bitmart.js +3 -1
  66. package/js/src/bitmex.d.ts +3 -22
  67. package/js/src/bitmex.js +11 -10
  68. package/js/src/bitso.d.ts +3 -19
  69. package/js/src/bitso.js +5 -4
  70. package/js/src/bitstamp.d.ts +3 -35
  71. package/js/src/bitstamp.js +33 -45
  72. package/js/src/blofin.d.ts +3 -15
  73. package/js/src/blofin.js +21 -23
  74. package/js/src/bybit.d.ts +3 -19
  75. package/js/src/bybit.js +23 -21
  76. package/js/src/coinbase.d.ts +3 -19
  77. package/js/src/coinbase.js +28 -7
  78. package/js/src/coinbaseexchange.d.ts +3 -19
  79. package/js/src/coinbaseexchange.js +11 -11
  80. package/js/src/coinlist.d.ts +3 -19
  81. package/js/src/coinlist.js +6 -5
  82. package/js/src/coinmetro.d.ts +3 -19
  83. package/js/src/coinmetro.js +3 -3
  84. package/js/src/cryptocom.d.ts +3 -22
  85. package/js/src/cryptocom.js +9 -6
  86. package/js/src/currencycom.d.ts +3 -3
  87. package/js/src/currencycom.js +6 -6
  88. package/js/src/delta.d.ts +3 -19
  89. package/js/src/delta.js +5 -5
  90. package/js/src/digifinex.d.ts +3 -19
  91. package/js/src/digifinex.js +8 -6
  92. package/js/src/gate.d.ts +3 -19
  93. package/js/src/gate.js +6 -5
  94. package/js/src/hashkey.d.ts +3 -20
  95. package/js/src/hashkey.js +9 -7
  96. package/js/src/htx.d.ts +3 -19
  97. package/js/src/htx.js +13 -16
  98. package/js/src/hyperliquid.d.ts +3 -19
  99. package/js/src/hyperliquid.js +68 -115
  100. package/js/src/kraken.d.ts +5 -24
  101. package/js/src/kraken.js +8 -6
  102. package/js/src/kucoin.d.ts +3 -19
  103. package/js/src/kucoin.js +9 -8
  104. package/js/src/luno.d.ts +4 -20
  105. package/js/src/luno.js +10 -9
  106. package/js/src/mexc.js +54 -2
  107. package/js/src/ndax.d.ts +3 -19
  108. package/js/src/ndax.js +6 -5
  109. package/js/src/okcoin.d.ts +3 -19
  110. package/js/src/okcoin.js +18 -27
  111. package/js/src/okx.d.ts +3 -19
  112. package/js/src/okx.js +18 -26
  113. package/js/src/p2b.js +2 -2
  114. package/js/src/pro/bybit.d.ts +2 -0
  115. package/js/src/pro/bybit.js +56 -0
  116. package/js/src/pro/cryptocom.d.ts +7 -1
  117. package/js/src/pro/cryptocom.js +191 -21
  118. package/js/src/pro/mexc.d.ts +6 -1
  119. package/js/src/pro/mexc.js +166 -4
  120. package/js/src/pro/okx.js +6 -3
  121. package/js/src/pro/oxfun.d.ts +3 -0
  122. package/js/src/pro/oxfun.js +75 -0
  123. package/js/src/pro/phemex.d.ts +2 -1
  124. package/js/src/pro/phemex.js +45 -1
  125. package/js/src/pro/woofipro.d.ts +3 -0
  126. package/js/src/pro/woofipro.js +67 -0
  127. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +1 -1
  128. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.d.ts +1 -1
  129. package/js/src/woo.d.ts +3 -19
  130. package/js/src/woo.js +7 -6
  131. package/js/src/woofipro.d.ts +3 -19
  132. package/js/src/woofipro.js +8 -6
  133. package/js/src/xt.d.ts +3 -22
  134. package/js/src/xt.js +10 -4
  135. package/js/src/zonda.d.ts +3 -19
  136. package/js/src/zonda.js +6 -5
  137. package/package.json +1 -1
package/js/src/mexc.js CHANGED
@@ -1017,8 +1017,9 @@ export default class mexc extends Exchange {
1017
1017
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1018
1018
  * @returns {object[]} an array of objects representing market data
1019
1019
  */
1020
- const spotMarket = await this.fetchSpotMarkets(params);
1021
- const swapMarket = await this.fetchSwapMarkets(params);
1020
+ const spotMarketPromise = this.fetchSpotMarkets(params);
1021
+ const swapMarketPromise = this.fetchSwapMarkets(params);
1022
+ const [spotMarket, swapMarket] = await Promise.all([spotMarketPromise, swapMarketPromise]);
1022
1023
  return this.arrayConcat(spotMarket, swapMarket);
1023
1024
  }
1024
1025
  async fetchSpotMarkets(params = {}) {
@@ -1157,7 +1158,10 @@ export default class mexc extends Exchange {
1157
1158
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1158
1159
  * @returns {object[]} an array of objects representing market data
1159
1160
  */
1161
+ const currentRl = this.rateLimit;
1162
+ this.setProperty(this, 'rateLimit', 10); // see comment: https://github.com/ccxt/ccxt/pull/23698
1160
1163
  const response = await this.contractPublicGetDetail(params);
1164
+ this.setProperty(this, 'rateLimit', currentRl);
1161
1165
  //
1162
1166
  // {
1163
1167
  // "success":true,
@@ -3065,6 +3069,9 @@ export default class mexc extends Exchange {
3065
3069
  * @method
3066
3070
  * @name mexc#cancelAllOrders
3067
3071
  * @description cancel all open orders
3072
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#cancel-all-open-orders-on-a-symbol
3073
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-all-orders-under-a-contract-under-maintenance
3074
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-all-trigger-orders-under-maintenance
3068
3075
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
3069
3076
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3070
3077
  * @param {string} [params.marginMode] only 'isolated' is supported for spot-margin trading
@@ -3468,6 +3475,8 @@ export default class mexc extends Exchange {
3468
3475
  * @method
3469
3476
  * @name mexc#fetchAccounts
3470
3477
  * @description fetch all the accounts associated with a profile
3478
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-information
3479
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-informations-of-user-39-s-asset
3471
3480
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3472
3481
  * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
3473
3482
  */
@@ -3495,6 +3504,8 @@ export default class mexc extends Exchange {
3495
3504
  * @method
3496
3505
  * @name mexc#fetchTradingFees
3497
3506
  * @description fetch the trading fees for multiple markets
3507
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-information
3508
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-informations-of-user-39-s-asset
3498
3509
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3499
3510
  * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
3500
3511
  */
@@ -3780,6 +3791,8 @@ export default class mexc extends Exchange {
3780
3791
  * @method
3781
3792
  * @name mexc#fetchMyTrades
3782
3793
  * @description fetch all trades made by the user
3794
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-trade-list
3795
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-transaction-details-of-the-user-s-order
3783
3796
  * @param {string} symbol unified market symbol
3784
3797
  * @param {int} [since] the earliest time in ms to fetch trades for
3785
3798
  * @param {int} [limit] the maximum number of trades structures to retrieve
@@ -3870,6 +3883,8 @@ export default class mexc extends Exchange {
3870
3883
  * @method
3871
3884
  * @name mexc#fetchOrderTrades
3872
3885
  * @description fetch all the trades made from a single order
3886
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-trade-list
3887
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#query-the-order-based-on-the-order-number
3873
3888
  * @param {string} id order id
3874
3889
  * @param {string} symbol unified market symbol
3875
3890
  * @param {int} [since] the earliest time in ms to fetch trades for
@@ -3968,6 +3983,7 @@ export default class mexc extends Exchange {
3968
3983
  * @method
3969
3984
  * @name mexc#reduceMargin
3970
3985
  * @description remove margin from a position
3986
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#increase-or-decrease-margin
3971
3987
  * @param {string} symbol unified market symbol
3972
3988
  * @param {float} amount the amount of margin to remove
3973
3989
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -3980,6 +3996,7 @@ export default class mexc extends Exchange {
3980
3996
  * @method
3981
3997
  * @name mexc#addMargin
3982
3998
  * @description add margin
3999
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#increase-or-decrease-margin
3983
4000
  * @param {string} symbol unified market symbol
3984
4001
  * @param {float} amount amount of margin to add
3985
4002
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -3992,6 +4009,7 @@ export default class mexc extends Exchange {
3992
4009
  * @method
3993
4010
  * @name mexc#setLeverage
3994
4011
  * @description set the level of leverage for a market
4012
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#switch-leverage
3995
4013
  * @param {float} leverage the rate of leverage
3996
4014
  * @param {string} symbol unified market symbol
3997
4015
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -4025,6 +4043,7 @@ export default class mexc extends Exchange {
4025
4043
  * @method
4026
4044
  * @name mexc#fetchFundingHistory
4027
4045
  * @description fetch the history of funding payments paid and received on this account
4046
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-details-of-user-s-funding-rate
4028
4047
  * @param {string} symbol unified market symbol
4029
4048
  * @param {int} [since] the earliest time in ms to fetch funding history for
4030
4049
  * @param {int} [limit] the maximum number of funding history structures to retrieve
@@ -4140,6 +4159,7 @@ export default class mexc extends Exchange {
4140
4159
  * @method
4141
4160
  * @name mexc#fetchFundingRate
4142
4161
  * @description fetch the current funding rate
4162
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-funding-rate
4143
4163
  * @param {string} symbol unified market symbol
4144
4164
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4145
4165
  * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
@@ -4173,6 +4193,7 @@ export default class mexc extends Exchange {
4173
4193
  * @method
4174
4194
  * @name mexc#fetchFundingRateHistory
4175
4195
  * @description fetches historical funding rate prices
4196
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-funding-rate-history
4176
4197
  * @param {string} symbol unified symbol of the market to fetch the funding rate history for
4177
4198
  * @param {int} [since] not used by mexc, but filtered internally by ccxt
4178
4199
  * @param {int} [limit] mexc limit is page_size default 20, maximum is 100
@@ -4906,6 +4927,16 @@ export default class mexc extends Exchange {
4906
4927
  });
4907
4928
  }
4908
4929
  async fetchTransfer(id, code = undefined, params = {}) {
4930
+ /**
4931
+ * @method
4932
+ * @name mexc#fetchTransfer
4933
+ * @description fetches a transfer
4934
+ * @see https://mexcdevelop.github.io/apidocs/spot_v2_en/#internal-assets-transfer-order-inquiry
4935
+ * @param {string} id transfer id
4936
+ * @param {string} [code] not used by mexc fetchTransfer
4937
+ * @param {object} params extra parameters specific to the exchange api endpoint
4938
+ * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
4939
+ */
4909
4940
  const [marketType, query] = this.handleMarketTypeAndParams('fetchTransfer', undefined, params);
4910
4941
  await this.loadMarkets();
4911
4942
  if (marketType === 'spot') {
@@ -4939,6 +4970,8 @@ export default class mexc extends Exchange {
4939
4970
  * @method
4940
4971
  * @name mexc#fetchTransfers
4941
4972
  * @description fetch a history of internal transfers made on an account
4973
+ * @see https://mexcdevelop.github.io/apidocs/spot_v2_en/#get-internal-assets-transfer-records
4974
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-39-s-asset-transfer-records
4942
4975
  * @param {string} code unified currency code of the currency transferred
4943
4976
  * @param {int} [since] the earliest time in ms to fetch transfers for
4944
4977
  * @param {int} [limit] the maximum number of transfers structures to retrieve
@@ -5196,6 +5229,16 @@ export default class mexc extends Exchange {
5196
5229
  return this.parseTransaction(response, currency);
5197
5230
  }
5198
5231
  async setPositionMode(hedged, symbol = undefined, params = {}) {
5232
+ /**
5233
+ * @method
5234
+ * @name mexc#setPositionMode
5235
+ * @description set hedged to true or false for a market
5236
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#change-position-mode
5237
+ * @param {bool} hedged set to true to use dualSidePosition
5238
+ * @param {string} symbol not used by mexc setPositionMode ()
5239
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5240
+ * @returns {object} response from the exchange
5241
+ */
5199
5242
  const request = {
5200
5243
  'positionMode': hedged ? 1 : 2, // 1 Hedge, 2 One-way, before changing position mode make sure that there are no active orders, planned orders, or open positions, the risk limit level will be reset to 1
5201
5244
  };
@@ -5209,6 +5252,15 @@ export default class mexc extends Exchange {
5209
5252
  return response;
5210
5253
  }
5211
5254
  async fetchPositionMode(symbol = undefined, params = {}) {
5255
+ /**
5256
+ * @method
5257
+ * @name mexc#fetchPositionMode
5258
+ * @description fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
5259
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-position-mode
5260
+ * @param {string} symbol not used by mexc fetchPositionMode
5261
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5262
+ * @returns {object} an object detailing whether the market is in hedged or one-way mode
5263
+ */
5212
5264
  const response = await this.contractPrivateGetPositionPositionMode(params);
5213
5265
  //
5214
5266
  // {
package/js/src/ndax.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/ndax.js';
2
- import type { IndexType, Balances, Currency, Int, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Ticker, Trade, Transaction, Num, Account, Currencies, Dict, int } from './base/types.js';
2
+ import type { IndexType, Balances, Currency, Int, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Ticker, Trade, Transaction, Num, Account, Currencies, Dict, int, LedgerEntry } from './base/types.js';
3
3
  /**
4
4
  * @class ndax
5
5
  * @augments Exchange
@@ -22,24 +22,8 @@ export default class ndax extends Exchange {
22
22
  parseBalance(response: any): Balances;
23
23
  fetchBalance(params?: {}): Promise<Balances>;
24
24
  parseLedgerEntryType(type: any): string;
25
- parseLedgerEntry(item: Dict, currency?: Currency): {
26
- info: Dict;
27
- id: string;
28
- direction: any;
29
- account: string;
30
- referenceId: string;
31
- referenceAccount: string;
32
- type: string;
33
- currency: string;
34
- amount: number;
35
- before: number;
36
- after: number;
37
- status: string;
38
- timestamp: number;
39
- datetime: string;
40
- fee: any;
41
- };
42
- fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
25
+ parseLedgerEntry(item: Dict, currency?: Currency): LedgerEntry;
26
+ fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<LedgerEntry[]>;
43
27
  parseOrderStatus(status: Str): string;
44
28
  parseOrder(order: Dict, market?: Market): Order;
45
29
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): Promise<Order>;
package/js/src/ndax.js CHANGED
@@ -1141,6 +1141,7 @@ export default class ndax extends Exchange {
1141
1141
  // }
1142
1142
  //
1143
1143
  const currencyId = this.safeString(item, 'ProductId');
1144
+ currency = this.safeCurrency(currencyId, currency);
1144
1145
  const credit = this.safeString(item, 'CR');
1145
1146
  const debit = this.safeString(item, 'DR');
1146
1147
  let amount = undefined;
@@ -1162,7 +1163,7 @@ export default class ndax extends Exchange {
1162
1163
  before = Precise.stringMax('0', Precise.stringSub(after, amount));
1163
1164
  }
1164
1165
  const timestamp = this.safeInteger(item, 'TimeStamp');
1165
- return {
1166
+ return this.safeLedgerEntry({
1166
1167
  'info': item,
1167
1168
  'id': this.safeString(item, 'TransactionId'),
1168
1169
  'direction': direction,
@@ -1178,17 +1179,17 @@ export default class ndax extends Exchange {
1178
1179
  'timestamp': timestamp,
1179
1180
  'datetime': this.iso8601(timestamp),
1180
1181
  'fee': undefined,
1181
- };
1182
+ }, currency);
1182
1183
  }
1183
1184
  async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
1184
1185
  /**
1185
1186
  * @method
1186
1187
  * @name ndax#fetchLedger
1187
- * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
1188
+ * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
1188
1189
  * @see https://apidoc.ndax.io/#getaccounttransactions
1189
- * @param {string} code unified currency code, default is undefined
1190
+ * @param {string} [code] unified currency code, default is undefined
1190
1191
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1191
- * @param {int} [limit] max number of ledger entrys to return, default is undefined
1192
+ * @param {int} [limit] max number of ledger entries to return, default is undefined
1192
1193
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1193
1194
  * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
1194
1195
  */
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/okcoin.js';
2
- import type { TransferEntry, Balances, Currency, Int, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, Num, Currencies, Dict, int } from './base/types.js';
2
+ import type { TransferEntry, Balances, Currency, Int, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, Num, Currencies, Dict, int, LedgerEntry } from './base/types.js';
3
3
  /**
4
4
  * @class okcoin
5
5
  * @augments Exchange
@@ -52,25 +52,9 @@ export default class okcoin extends Exchange {
52
52
  parseTransaction(transaction: Dict, currency?: Currency): Transaction;
53
53
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
54
54
  fetchOrderTrades(id: string, symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
55
- fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
55
+ fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<LedgerEntry[]>;
56
56
  parseLedgerEntryType(type: any): string;
57
- parseLedgerEntry(item: Dict, currency?: Currency): {
58
- id: string;
59
- info: Dict;
60
- timestamp: number;
61
- datetime: string;
62
- account: any;
63
- referenceId: string;
64
- referenceAccount: any;
65
- type: string;
66
- currency: string;
67
- symbol: string;
68
- amount: number;
69
- before: any;
70
- after: number;
71
- status: string;
72
- fee: any;
73
- };
57
+ parseLedgerEntry(item: Dict, currency?: Currency): LedgerEntry;
74
58
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
75
59
  url: string;
76
60
  method: string;
package/js/src/okcoin.js CHANGED
@@ -2861,13 +2861,13 @@ export default class okcoin extends Exchange {
2861
2861
  /**
2862
2862
  * @method
2863
2863
  * @name okcoin#fetchLedger
2864
+ * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
2864
2865
  * @see https://www.okcoin.com/docs-v5/en/#rest-api-funding-asset-bills-details
2865
2866
  * @see https://www.okcoin.com/docs-v5/en/#rest-api-account-get-bills-details-last-7-days
2866
2867
  * @see https://www.okcoin.com/docs-v5/en/#rest-api-account-get-bills-details-last-3-months
2867
- * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
2868
- * @param {string} code unified currency code, default is undefined
2868
+ * @param {string} [code] unified currency code, default is undefined
2869
2869
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
2870
- * @param {int} [limit] max number of ledger entrys to return, default is undefined
2870
+ * @param {int} [limit] max number of ledger entries to return, default is undefined
2871
2871
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2872
2872
  * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
2873
2873
  */
@@ -3009,46 +3009,37 @@ export default class okcoin extends Exchange {
3009
3009
  // "ts": "1597026383085"
3010
3010
  // }
3011
3011
  //
3012
- const id = this.safeString(item, 'billId');
3013
- const account = undefined;
3014
- const referenceId = this.safeString(item, 'ordId');
3015
- const referenceAccount = undefined;
3016
- const type = this.parseLedgerEntryType(this.safeString(item, 'type'));
3017
- const code = this.safeCurrencyCode(this.safeString(item, 'ccy'), currency);
3018
- const amountString = this.safeString(item, 'balChg');
3019
- const amount = this.parseNumber(amountString);
3012
+ const currencyId = this.safeString(item, 'ccy');
3013
+ const code = this.safeCurrencyCode(currencyId, currency);
3014
+ currency = this.safeCurrency(currencyId, currency);
3020
3015
  const timestamp = this.safeInteger(item, 'ts');
3021
3016
  const feeCostString = this.safeString(item, 'fee');
3022
3017
  let fee = undefined;
3023
3018
  if (feeCostString !== undefined) {
3024
3019
  fee = {
3025
- 'cost': this.parseNumber(Precise.stringNeg(feeCostString)),
3020
+ 'cost': this.parseToNumeric(Precise.stringNeg(feeCostString)),
3026
3021
  'currency': code,
3027
3022
  };
3028
3023
  }
3029
- const before = undefined;
3030
- const afterString = this.safeString(item, 'bal');
3031
- const after = this.parseNumber(afterString);
3032
- const status = 'ok';
3033
3024
  const marketId = this.safeString(item, 'instId');
3034
3025
  const symbol = this.safeSymbol(marketId, undefined, '-');
3035
- return {
3036
- 'id': id,
3026
+ return this.safeLedgerEntry({
3037
3027
  'info': item,
3028
+ 'id': this.safeString(item, 'billId'),
3038
3029
  'timestamp': timestamp,
3039
3030
  'datetime': this.iso8601(timestamp),
3040
- 'account': account,
3041
- 'referenceId': referenceId,
3042
- 'referenceAccount': referenceAccount,
3043
- 'type': type,
3031
+ 'account': undefined,
3032
+ 'referenceId': this.safeString(item, 'ordId'),
3033
+ 'referenceAccount': undefined,
3034
+ 'type': this.parseLedgerEntryType(this.safeString(item, 'type')),
3044
3035
  'currency': code,
3045
3036
  'symbol': symbol,
3046
- 'amount': amount,
3047
- 'before': before,
3048
- 'after': after,
3049
- 'status': status,
3037
+ 'amount': this.safeNumber(item, 'balChg'),
3038
+ 'before': undefined,
3039
+ 'after': this.safeNumber(item, 'bal'),
3040
+ 'status': 'ok',
3050
3041
  'fee': fee,
3051
- };
3042
+ }, currency);
3052
3043
  }
3053
3044
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3054
3045
  const isArray = Array.isArray(params);
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, MarginModification, TradingFeeInterface, Currencies, Conversion, CancellationRequest, Dict, Position, CrossBorrowRate, CrossBorrowRates, LeverageTier, int } 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, TradingFeeInterface, Currencies, Conversion, CancellationRequest, Dict, Position, CrossBorrowRate, CrossBorrowRates, LeverageTier, int, LedgerEntry } from './base/types.js';
3
3
  /**
4
4
  * @class okx
5
5
  * @augments Exchange
@@ -52,25 +52,9 @@ export default class okx extends Exchange {
52
52
  fetchClosedOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
53
53
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
54
54
  fetchOrderTrades(id: string, symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
55
- fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
55
+ fetchLedger(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<LedgerEntry[]>;
56
56
  parseLedgerEntryType(type: any): string;
57
- parseLedgerEntry(item: Dict, currency?: Currency): {
58
- id: string;
59
- info: Dict;
60
- timestamp: number;
61
- datetime: string;
62
- account: any;
63
- referenceId: string;
64
- referenceAccount: any;
65
- type: string;
66
- currency: string;
67
- symbol: string;
68
- amount: number;
69
- before: any;
70
- after: number;
71
- status: string;
72
- fee: any;
73
- };
57
+ parseLedgerEntry(item: Dict, currency?: Currency): LedgerEntry;
74
58
  parseDepositAddress(depositAddress: any, currency?: Currency): {
75
59
  currency: string;
76
60
  address: string;
package/js/src/okx.js CHANGED
@@ -793,6 +793,7 @@ export default class okx extends Exchange {
793
793
  // SPOT/MARGIN error codes 54000-54999
794
794
  '54000': ExchangeError,
795
795
  '54001': ExchangeError,
796
+ '54011': InvalidOrder,
796
797
  // Trading bot Error Code from 55100 to 55999
797
798
  '55100': InvalidOrder,
798
799
  '55101': InvalidOrder,
@@ -4474,13 +4475,13 @@ export default class okx extends Exchange {
4474
4475
  * @see https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-7-days
4475
4476
  * @see https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-3-months
4476
4477
  * @see https://www.okx.com/docs-v5/en/#rest-api-funding-asset-bills-details
4477
- * @param {string} code unified currency code, default is undefined
4478
+ * @param {string} [code] unified currency code, default is undefined
4478
4479
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
4479
- * @param {int} [limit] max number of ledger entrys to return, default is undefined
4480
+ * @param {int} [limit] max number of ledger entries to return, default is undefined
4480
4481
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4481
4482
  * @param {string} [params.marginMode] 'cross' or 'isolated'
4482
4483
  * @param {int} [params.until] the latest time in ms to fetch entries for
4483
- * @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)
4484
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
4484
4485
  * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
4485
4486
  */
4486
4487
  await this.loadMarkets();
@@ -4643,14 +4644,9 @@ export default class okx extends Exchange {
4643
4644
  // "ts": "1597026383085"
4644
4645
  // }
4645
4646
  //
4646
- const id = this.safeString(item, 'billId');
4647
- const account = undefined;
4648
- const referenceId = this.safeString(item, 'ordId');
4649
- const referenceAccount = undefined;
4650
- const type = this.parseLedgerEntryType(this.safeString(item, 'type'));
4651
- const code = this.safeCurrencyCode(this.safeString(item, 'ccy'), currency);
4652
- const amountString = this.safeString(item, 'balChg');
4653
- const amount = this.parseNumber(amountString);
4647
+ const currencyId = this.safeString(item, 'ccy');
4648
+ const code = this.safeCurrencyCode(currencyId, currency);
4649
+ currency = this.safeCurrency(currencyId, currency);
4654
4650
  const timestamp = this.safeInteger(item, 'ts');
4655
4651
  const feeCostString = this.safeString(item, 'fee');
4656
4652
  let fee = undefined;
@@ -4660,29 +4656,25 @@ export default class okx extends Exchange {
4660
4656
  'currency': code,
4661
4657
  };
4662
4658
  }
4663
- const before = undefined;
4664
- const afterString = this.safeString(item, 'bal');
4665
- const after = this.parseNumber(afterString);
4666
- const status = 'ok';
4667
4659
  const marketId = this.safeString(item, 'instId');
4668
4660
  const symbol = this.safeSymbol(marketId, undefined, '-');
4669
- return {
4670
- 'id': id,
4661
+ return this.safeLedgerEntry({
4671
4662
  'info': item,
4663
+ 'id': this.safeString(item, 'billId'),
4672
4664
  'timestamp': timestamp,
4673
4665
  'datetime': this.iso8601(timestamp),
4674
- 'account': account,
4675
- 'referenceId': referenceId,
4676
- 'referenceAccount': referenceAccount,
4677
- 'type': type,
4666
+ 'account': undefined,
4667
+ 'referenceId': this.safeString(item, 'ordId'),
4668
+ 'referenceAccount': undefined,
4669
+ 'type': this.parseLedgerEntryType(this.safeString(item, 'type')),
4678
4670
  'currency': code,
4679
4671
  'symbol': symbol,
4680
- 'amount': amount,
4681
- 'before': before,
4682
- 'after': after,
4683
- 'status': status,
4672
+ 'amount': this.safeNumber(item, 'balChg'),
4673
+ 'before': undefined,
4674
+ 'after': this.safeNumber(item, 'bal'),
4675
+ 'status': 'ok',
4684
4676
  'fee': fee,
4685
- };
4677
+ }, currency);
4686
4678
  }
4687
4679
  parseDepositAddress(depositAddress, currency = undefined) {
4688
4680
  //
package/js/src/p2b.js CHANGED
@@ -477,7 +477,7 @@ export default class p2b extends Exchange {
477
477
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
478
478
  /**
479
479
  * @method
480
- * @name p2bfutures#fetchOrderBook
480
+ * @name p2b#fetchOrderBook
481
481
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
482
482
  * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#depth-result
483
483
  * @param {string} symbol unified symbol of the market to fetch the order book for
@@ -646,7 +646,7 @@ export default class p2b extends Exchange {
646
646
  async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
647
647
  /**
648
648
  * @method
649
- * @name poloniexfutures#fetchOHLCV
649
+ * @name p2b#fetchOHLCV
650
650
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
651
651
  * @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#kline
652
652
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
@@ -14,6 +14,8 @@ export default class bybit extends bybitRest {
14
14
  unWatchTickers(symbols?: Strings, params?: {}): Promise<any>;
15
15
  unWatchTicker(symbols: string, params?: {}): Promise<any>;
16
16
  handleTicker(client: Client, message: any): void;
17
+ watchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
18
+ parseWsBidAsk(orderbook: any, market?: any): Ticker;
17
19
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
18
20
  watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<import("../base/types.js").Dictionary<import("../base/types.js").Dictionary<OHLCV[]>>>;
19
21
  unWatchOHLCVForSymbols(symbolsAndTimeframes: string[][], params?: {}): Promise<any>;
@@ -25,6 +25,7 @@ export default class bybit extends bybitRest {
25
25
  'fetchTradesWs': false,
26
26
  'fetchBalanceWs': false,
27
27
  'watchBalance': true,
28
+ 'watchBidsAsks': true,
28
29
  'watchLiquidations': true,
29
30
  'watchLiquidationsForSymbols': false,
30
31
  'watchMyLiquidations': false,
@@ -581,6 +582,52 @@ export default class bybit extends bybitRest {
581
582
  const messageHash = 'ticker:' + symbol;
582
583
  client.resolve(this.tickers[symbol], messageHash);
583
584
  }
585
+ async watchBidsAsks(symbols = undefined, params = {}) {
586
+ /**
587
+ * @method
588
+ * @name bybit#watchBidsAsks
589
+ * @description watches best bid & ask for symbols
590
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook
591
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
592
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
593
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
594
+ */
595
+ await this.loadMarkets();
596
+ symbols = this.marketSymbols(symbols, undefined, false);
597
+ const messageHashes = [];
598
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchBidsAsks', params);
599
+ params = this.cleanParams(params);
600
+ const marketIds = this.marketIds(symbols);
601
+ const topics = [];
602
+ for (let i = 0; i < marketIds.length; i++) {
603
+ const marketId = marketIds[i];
604
+ const topic = 'orderbook.1.' + marketId;
605
+ topics.push(topic);
606
+ messageHashes.push('bidask:' + symbols[i]);
607
+ }
608
+ const ticker = await this.watchTopics(url, messageHashes, topics, params);
609
+ if (this.newUpdates) {
610
+ return ticker;
611
+ }
612
+ return this.filterByArray(this.bidsasks, 'symbol', symbols);
613
+ }
614
+ parseWsBidAsk(orderbook, market = undefined) {
615
+ const timestamp = this.safeInteger(orderbook, 'timestamp');
616
+ const bids = this.sortBy(this.aggregate(orderbook['bids']), 0);
617
+ const asks = this.sortBy(this.aggregate(orderbook['asks']), 0);
618
+ const bestBid = this.safeList(bids, 0, []);
619
+ const bestAsk = this.safeList(asks, 0, []);
620
+ return this.safeTicker({
621
+ 'symbol': market['symbol'],
622
+ 'timestamp': timestamp,
623
+ 'datetime': this.iso8601(timestamp),
624
+ 'ask': this.safeNumber(bestAsk, 0),
625
+ 'askVolume': this.safeNumber(bestAsk, 1),
626
+ 'bid': this.safeNumber(bestBid, 0),
627
+ 'bidVolume': this.safeNumber(bestBid, 1),
628
+ 'info': orderbook,
629
+ }, market);
630
+ }
584
631
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
585
632
  /**
586
633
  * @method
@@ -905,6 +952,8 @@ export default class bybit extends bybitRest {
905
952
  // }
906
953
  // }
907
954
  //
955
+ const topic = this.safeString(message, 'topic');
956
+ const limit = topic.split('.')[1];
908
957
  const isSpot = client.url.indexOf('spot') >= 0;
909
958
  const type = this.safeString(message, 'type');
910
959
  const isSnapshot = (type === 'snapshot');
@@ -933,6 +982,13 @@ export default class bybit extends bybitRest {
933
982
  const messageHash = 'orderbook' + ':' + symbol;
934
983
  this.orderbooks[symbol] = orderbook;
935
984
  client.resolve(orderbook, messageHash);
985
+ if (limit === '1') {
986
+ const bidask = this.parseWsBidAsk(this.orderbooks[symbol], market);
987
+ const newBidsAsks = {};
988
+ newBidsAsks[symbol] = bidask;
989
+ this.bidsasks[symbol] = bidask;
990
+ client.resolve(newBidsAsks, 'bidask:' + symbol);
991
+ }
936
992
  }
937
993
  handleDelta(bookside, delta) {
938
994
  const bidAsk = this.parseBidAsk(delta, 0, 1);
@@ -1,5 +1,5 @@
1
1
  import cryptocomRest from '../cryptocom.js';
2
- import type { Int, OrderSide, OrderType, Str, Strings, OrderBook, Order, Trade, Ticker, OHLCV, Position, Balances, Num } from '../base/types.js';
2
+ import type { Int, OrderSide, OrderType, Str, Strings, OrderBook, Order, Trade, Ticker, OHLCV, Position, Balances, Num, Dict, Tickers, Market } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class cryptocom extends cryptocomRest {
5
5
  describe(): any;
@@ -19,7 +19,13 @@ export default class cryptocom extends cryptocomRest {
19
19
  watchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
20
20
  watchTicker(symbol: string, params?: {}): Promise<Ticker>;
21
21
  unWatchTicker(symbol: string, params?: {}): Promise<any>;
22
+ watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
23
+ unWatchTickers(symbols?: Strings, params?: {}): Promise<any>;
22
24
  handleTicker(client: Client, message: any): void;
25
+ parseWsTicker(ticker: Dict, market?: Market): Ticker;
26
+ watchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
27
+ handleBidAsk(client: Client, message: any): void;
28
+ parseWsBidAsk(ticker: any, market?: any): Ticker;
23
29
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
24
30
  unWatchOHLCV(symbol: string, timeframe?: string, params?: {}): Promise<any>;
25
31
  handleOHLCV(client: Client, message: any): void;