ccxt 4.2.88 → 4.2.90

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 (164) hide show
  1. package/README.md +3 -3
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +1062 -241
  4. package/dist/ccxt.browser.min.js +6 -4
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/ascendex.js +3 -0
  7. package/dist/cjs/src/base/Exchange.js +53 -7
  8. package/dist/cjs/src/base/functions/crypto.js +37 -0
  9. package/dist/cjs/src/base/functions/rsa.js +19 -4
  10. package/dist/cjs/src/binance.js +92 -9
  11. package/dist/cjs/src/bingx.js +101 -1
  12. package/dist/cjs/src/bitfinex2.js +1 -0
  13. package/dist/cjs/src/bitflyer.js +2 -0
  14. package/dist/cjs/src/bitget.js +9 -1
  15. package/dist/cjs/src/bitmart.js +2 -0
  16. package/dist/cjs/src/bitmex.js +1 -0
  17. package/dist/cjs/src/bitrue.js +1 -0
  18. package/dist/cjs/src/bitstamp.js +83 -99
  19. package/dist/cjs/src/blofin.js +2 -0
  20. package/dist/cjs/src/bybit.js +63 -0
  21. package/dist/cjs/src/coinbase.js +48 -24
  22. package/dist/cjs/src/coinbaseinternational.js +1 -0
  23. package/dist/cjs/src/coinex.js +102 -8
  24. package/dist/cjs/src/coinsph.js +2 -0
  25. package/dist/cjs/src/cryptocom.js +1 -0
  26. package/dist/cjs/src/delta.js +1 -0
  27. package/dist/cjs/src/digifinex.js +3 -0
  28. package/dist/cjs/src/exmo.js +1 -0
  29. package/dist/cjs/src/gate.js +4 -0
  30. package/dist/cjs/src/gemini.js +10 -9
  31. package/dist/cjs/src/hitbtc.js +3 -0
  32. package/dist/cjs/src/htx.js +3 -0
  33. package/dist/cjs/src/hyperliquid.js +1 -0
  34. package/dist/cjs/src/kucoin.js +40 -15
  35. package/dist/cjs/src/kucoinfutures.js +34 -3
  36. package/dist/cjs/src/latoken.js +4 -0
  37. package/dist/cjs/src/lbank.js +3 -1
  38. package/dist/cjs/src/luno.js +2 -0
  39. package/dist/cjs/src/mexc.js +55 -6
  40. package/dist/cjs/src/okx.js +159 -8
  41. package/dist/cjs/src/phemex.js +1 -0
  42. package/dist/cjs/src/pro/bitget.js +2 -0
  43. package/dist/cjs/src/static_dependencies/noble-curves/p256.js +48 -0
  44. package/dist/cjs/src/timex.js +2 -0
  45. package/dist/cjs/src/woo.js +1 -0
  46. package/js/ccxt.d.ts +1 -1
  47. package/js/ccxt.js +1 -1
  48. package/js/src/abstract/bingx.d.ts +2 -0
  49. package/js/src/abstract/bybit.d.ts +2 -0
  50. package/js/src/ascendex.d.ts +3 -3
  51. package/js/src/ascendex.js +3 -0
  52. package/js/src/base/Exchange.d.ts +13 -8
  53. package/js/src/base/Exchange.js +53 -7
  54. package/js/src/base/functions/crypto.js +37 -0
  55. package/js/src/base/functions/rsa.d.ts +1 -1
  56. package/js/src/base/functions/rsa.js +21 -5
  57. package/js/src/base/types.d.ts +35 -1
  58. package/js/src/bigone.d.ts +2 -2
  59. package/js/src/binance.d.ts +6 -15
  60. package/js/src/binance.js +92 -9
  61. package/js/src/bingx.d.ts +3 -2
  62. package/js/src/bingx.js +101 -1
  63. package/js/src/bit2c.d.ts +2 -2
  64. package/js/src/bitbank.d.ts +2 -2
  65. package/js/src/bitfinex.d.ts +2 -2
  66. package/js/src/bitfinex2.d.ts +3 -3
  67. package/js/src/bitfinex2.js +1 -0
  68. package/js/src/bitflyer.d.ts +2 -7
  69. package/js/src/bitflyer.js +2 -0
  70. package/js/src/bitget.d.ts +6 -9
  71. package/js/src/bitget.js +9 -1
  72. package/js/src/bitmart.d.ts +4 -14
  73. package/js/src/bitmart.js +2 -0
  74. package/js/src/bitmex.d.ts +2 -2
  75. package/js/src/bitmex.js +1 -0
  76. package/js/src/bitopro.d.ts +3 -3
  77. package/js/src/bitrue.d.ts +2 -2
  78. package/js/src/bitrue.js +1 -0
  79. package/js/src/bitso.d.ts +2 -2
  80. package/js/src/bitstamp.d.ts +7 -19
  81. package/js/src/bitstamp.js +83 -99
  82. package/js/src/bitteam.d.ts +2 -2
  83. package/js/src/bitvavo.d.ts +3 -3
  84. package/js/src/bl3p.d.ts +2 -2
  85. package/js/src/blockchaincom.d.ts +2 -2
  86. package/js/src/blofin.d.ts +2 -7
  87. package/js/src/blofin.js +2 -0
  88. package/js/src/bybit.d.ts +7 -15
  89. package/js/src/bybit.js +63 -0
  90. package/js/src/cex.d.ts +3 -3
  91. package/js/src/coinbase.d.ts +2 -2
  92. package/js/src/coinbase.js +48 -24
  93. package/js/src/coinbaseinternational.d.ts +2 -2
  94. package/js/src/coinbaseinternational.js +1 -0
  95. package/js/src/coinbasepro.d.ts +3 -3
  96. package/js/src/coincheck.d.ts +2 -2
  97. package/js/src/coinex.d.ts +7 -19
  98. package/js/src/coinex.js +102 -8
  99. package/js/src/coinlist.d.ts +3 -3
  100. package/js/src/coinmate.d.ts +2 -9
  101. package/js/src/coinmetro.d.ts +2 -2
  102. package/js/src/coinone.d.ts +2 -2
  103. package/js/src/coinsph.d.ts +4 -14
  104. package/js/src/coinsph.js +2 -0
  105. package/js/src/cryptocom.js +1 -0
  106. package/js/src/currencycom.d.ts +3 -3
  107. package/js/src/delta.d.ts +2 -2
  108. package/js/src/delta.js +1 -0
  109. package/js/src/deribit.d.ts +3 -3
  110. package/js/src/digifinex.d.ts +4 -14
  111. package/js/src/digifinex.js +3 -0
  112. package/js/src/exmo.d.ts +3 -3
  113. package/js/src/exmo.js +1 -0
  114. package/js/src/gate.d.ts +6 -9
  115. package/js/src/gate.js +4 -0
  116. package/js/src/gemini.d.ts +3 -3
  117. package/js/src/gemini.js +10 -9
  118. package/js/src/hitbtc.d.ts +5 -15
  119. package/js/src/hitbtc.js +3 -0
  120. package/js/src/hollaex.d.ts +3 -3
  121. package/js/src/htx.d.ts +4 -14
  122. package/js/src/htx.js +3 -0
  123. package/js/src/huobijp.d.ts +2 -2
  124. package/js/src/hyperliquid.d.ts +2 -2
  125. package/js/src/hyperliquid.js +1 -0
  126. package/js/src/idex.d.ts +3 -3
  127. package/js/src/independentreserve.d.ts +2 -2
  128. package/js/src/kraken.d.ts +3 -10
  129. package/js/src/kucoin.d.ts +3 -10
  130. package/js/src/kucoin.js +40 -15
  131. package/js/src/kucoinfutures.d.ts +2 -9
  132. package/js/src/kucoinfutures.js +34 -3
  133. package/js/src/kuna.d.ts +2 -2
  134. package/js/src/latoken.d.ts +7 -8
  135. package/js/src/latoken.js +4 -0
  136. package/js/src/lbank.d.ts +4 -9
  137. package/js/src/lbank.js +3 -1
  138. package/js/src/luno.d.ts +2 -7
  139. package/js/src/luno.js +2 -0
  140. package/js/src/lykke.d.ts +2 -2
  141. package/js/src/mexc.d.ts +3 -3
  142. package/js/src/mexc.js +55 -6
  143. package/js/src/ndax.d.ts +2 -2
  144. package/js/src/oceanex.d.ts +2 -2
  145. package/js/src/okcoin.d.ts +2 -2
  146. package/js/src/okx.d.ts +5 -14
  147. package/js/src/okx.js +159 -8
  148. package/js/src/onetrading.d.ts +3 -3
  149. package/js/src/phemex.d.ts +2 -2
  150. package/js/src/phemex.js +1 -0
  151. package/js/src/poloniex.d.ts +3 -3
  152. package/js/src/pro/bitget.js +2 -0
  153. package/js/src/pro/bitvavo.d.ts +2 -2
  154. package/js/src/probit.d.ts +2 -2
  155. package/js/src/timex.d.ts +4 -14
  156. package/js/src/timex.js +2 -0
  157. package/js/src/upbit.d.ts +2 -9
  158. package/js/src/wazirx.d.ts +2 -2
  159. package/js/src/whitebit.d.ts +3 -3
  160. package/js/src/woo.d.ts +3 -3
  161. package/js/src/woo.js +1 -0
  162. package/js/src/yobit.d.ts +2 -2
  163. package/package.json +1 -1
  164. package/skip-tests.json +6 -1
package/js/src/bybit.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import Exchange from './abstract/bybit.js';
2
- import type { Int, OrderSide, OrderType, Trade, Order, OHLCV, FundingRateHistory, OpenInterest, OrderRequest, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Greeks, Strings, Market, Currency, MarketInterface, TransferEntry, Liquidation, Leverage, Num, FundingHistory, Option, OptionChain } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, Order, OHLCV, FundingRateHistory, OpenInterest, OrderRequest, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Greeks, Strings, Market, Currency, MarketInterface, TransferEntry, Liquidation, Leverage, Num, FundingHistory, Option, OptionChain, TradingFeeInterface, Currencies, TradingFees } from './base/types.js';
3
3
  /**
4
4
  * @class bybit
5
5
  * @augments Exchange
6
6
  */
7
7
  export default class bybit extends Exchange {
8
8
  describe(): any;
9
+ setSandboxMode(enable: boolean): void;
10
+ enableDemoTrading(enable: boolean): void;
9
11
  nonce(): number;
10
12
  addPaginationCursorToResult(response: any): any;
11
13
  isUnifiedEnabled(params?: {}): Promise<any[]>;
@@ -14,7 +16,7 @@ export default class bybit extends Exchange {
14
16
  safeMarket(marketId?: Str, market?: Market, delimiter?: Str, marketType?: Str): MarketInterface;
15
17
  getBybitType(method: any, market: any, params?: {}): any[];
16
18
  fetchTime(params?: {}): Promise<number>;
17
- fetchCurrencies(params?: {}): Promise<{}>;
19
+ fetchCurrencies(params?: {}): Promise<Currencies>;
18
20
  fetchMarkets(params?: {}): Promise<Market[]>;
19
21
  fetchSpotMarkets(params: any): Promise<any[]>;
20
22
  fetchFutureMarkets(params: any): Promise<any[]>;
@@ -188,19 +190,9 @@ export default class bybit extends Exchange {
188
190
  };
189
191
  fetchDerivativesMarketLeverageTiers(symbol: string, params?: {}): Promise<any[]>;
190
192
  fetchMarketLeverageTiers(symbol: string, params?: {}): Promise<any[]>;
191
- parseTradingFee(fee: any, market?: Market): {
192
- info: any;
193
- symbol: string;
194
- maker: number;
195
- taker: number;
196
- };
197
- fetchTradingFee(symbol: string, params?: {}): Promise<{
198
- info: any;
199
- symbol: string;
200
- maker: number;
201
- taker: number;
202
- }>;
203
- fetchTradingFees(params?: {}): Promise<{}>;
193
+ parseTradingFee(fee: any, market?: Market): TradingFeeInterface;
194
+ fetchTradingFee(symbol: string, params?: {}): Promise<TradingFeeInterface>;
195
+ fetchTradingFees(params?: {}): Promise<TradingFees>;
204
196
  parseDepositWithdrawFee(fee: any, currency?: Currency): {
205
197
  info: any;
206
198
  withdraw: {
package/js/src/bybit.js CHANGED
@@ -84,6 +84,7 @@ export default class bybit extends Exchange {
84
84
  'fetchLedger': true,
85
85
  'fetchLeverage': true,
86
86
  'fetchLeverageTiers': true,
87
+ 'fetchMarginAdjustmentHistory': false,
87
88
  'fetchMarketLeverageTiers': true,
88
89
  'fetchMarkets': true,
89
90
  'fetchMarkOHLCV': true,
@@ -154,6 +155,13 @@ export default class bybit extends Exchange {
154
155
  'public': 'https://api.{hostname}',
155
156
  'private': 'https://api.{hostname}',
156
157
  },
158
+ 'demotrading': {
159
+ 'spot': 'https://api-demo.{hostname}',
160
+ 'futures': 'https://api-demo.{hostname}',
161
+ 'v2': 'https://api-demo.{hostname}',
162
+ 'public': 'https://api-demo.{hostname}',
163
+ 'private': 'https://api-demo.{hostname}',
164
+ },
157
165
  'www': 'https://www.bybit.com',
158
166
  'doc': [
159
167
  'https://bybit-exchange.github.io/docs/inverse/',
@@ -342,6 +350,7 @@ export default class bybit extends Exchange {
342
350
  'v5/user/get-member-type': 5,
343
351
  'v5/user/aff-customer-info': 5,
344
352
  'v5/user/del-submember': 5,
353
+ 'v5/user/submembers': 5,
345
354
  // spot leverage token
346
355
  'v5/spot-lever-token/order-record': 1,
347
356
  // spot margin trade
@@ -502,6 +511,8 @@ export default class bybit extends Exchange {
502
511
  'v5/lending/redeem-cancel': 5,
503
512
  'v5/account/set-collateral-switch': 5,
504
513
  'v5/account/set-collateral-switch-batch': 5,
514
+ // demo trading
515
+ 'v5/account/demo-apply-money': 5,
505
516
  },
506
517
  },
507
518
  },
@@ -968,6 +979,8 @@ export default class bybit extends Exchange {
968
979
  },
969
980
  'precisionMode': TICK_SIZE,
970
981
  'options': {
982
+ 'sandboxMode': false,
983
+ 'enableDemoTrading': false,
971
984
  'fetchMarkets': ['spot', 'linear', 'inverse', 'option'],
972
985
  'createOrder': {
973
986
  'method': 'privatePostV5OrderCreate', // 'privatePostV5PositionTradingStop'
@@ -1051,6 +1064,39 @@ export default class bybit extends Exchange {
1051
1064
  },
1052
1065
  });
1053
1066
  }
1067
+ setSandboxMode(enable) {
1068
+ /**
1069
+ * @method
1070
+ * @name bybit#setSandboxMode
1071
+ * @description enables or disables sandbox mode
1072
+ * @param {boolean} [enable] true if demo trading should be enabled, false otherwise
1073
+ */
1074
+ super.setSandboxMode(enable);
1075
+ this.options['sandboxMode'] = enable;
1076
+ }
1077
+ enableDemoTrading(enable) {
1078
+ /**
1079
+ * @method
1080
+ * @name bybit#enableDemoTrading
1081
+ * @description enables or disables demo trading mode
1082
+ * @see https://bybit-exchange.github.io/docs/v5/demo
1083
+ * @param {boolean} [enable] true if demo trading should be enabled, false otherwise
1084
+ */
1085
+ if (this.options['sandboxMode']) {
1086
+ throw new NotSupported(this.id + ' demo trading does not support in sandbox environment');
1087
+ }
1088
+ // enable demo trading in bybit, see: https://bybit-exchange.github.io/docs/v5/demo
1089
+ if (enable) {
1090
+ this.urls['apiBackupDemoTrading'] = this.urls['api'];
1091
+ this.urls['api'] = this.urls['demotrading'];
1092
+ }
1093
+ else if ('apiBackupDemoTrading' in this.urls) {
1094
+ this.urls['api'] = this.urls['apiBackupDemoTrading'];
1095
+ const newUrls = this.omit(this.urls, 'apiBackupDemoTrading');
1096
+ this.urls = newUrls;
1097
+ }
1098
+ this.options['enableDemoTrading'] = enable;
1099
+ }
1054
1100
  nonce() {
1055
1101
  return this.milliseconds() - this.options['timeDifference'];
1056
1102
  }
@@ -1067,12 +1113,24 @@ export default class bybit extends Exchange {
1067
1113
  return data;
1068
1114
  }
1069
1115
  async isUnifiedEnabled(params = {}) {
1116
+ /**
1117
+ * @method
1118
+ * @name bybit#isUnifiedEnabled
1119
+ * @description returns [enableUnifiedMargin, enableUnifiedAccount] so the user can check if unified account is enabled
1120
+ */
1070
1121
  // The API key of user id must own one of permissions will be allowed to call following API endpoints.
1071
1122
  // SUB UID: "Account Transfer"
1072
1123
  // MASTER UID: "Account Transfer", "Subaccount Transfer", "Withdrawal"
1073
1124
  const enableUnifiedMargin = this.safeValue(this.options, 'enableUnifiedMargin');
1074
1125
  const enableUnifiedAccount = this.safeValue(this.options, 'enableUnifiedAccount');
1075
1126
  if (enableUnifiedMargin === undefined || enableUnifiedAccount === undefined) {
1127
+ if (this.options['enableDemoTrading']) {
1128
+ // info endpoint is not available in demo trading
1129
+ // so we're assuming UTA is enabled
1130
+ this.options['enableUnifiedMargin'] = false;
1131
+ this.options['enableUnifiedAccount'] = true;
1132
+ return [this.options['enableUnifiedMargin'], this.options['enableUnifiedAccount']];
1133
+ }
1076
1134
  const response = await this.privateGetV5UserQueryApi(params);
1077
1135
  //
1078
1136
  // {
@@ -1242,6 +1300,9 @@ export default class bybit extends Exchange {
1242
1300
  if (!this.checkRequiredCredentials(false)) {
1243
1301
  return undefined;
1244
1302
  }
1303
+ if (this.options['enableDemoTrading']) {
1304
+ return undefined;
1305
+ }
1245
1306
  const response = await this.privateGetV5AssetCoinQueryInfo(params);
1246
1307
  //
1247
1308
  // {
@@ -7271,6 +7332,8 @@ export default class bybit extends Exchange {
7271
7332
  'symbol': symbol,
7272
7333
  'maker': this.safeNumber(fee, 'makerFeeRate'),
7273
7334
  'taker': this.safeNumber(fee, 'takerFeeRate'),
7335
+ 'percentage': undefined,
7336
+ 'tierBased': undefined,
7274
7337
  };
7275
7338
  }
7276
7339
  async fetchTradingFee(symbol, params = {}) {
package/js/src/cex.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/cex.js';
2
- import type { Balances, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade } from './base/types.js';
2
+ import type { Balances, Currencies, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFees } from './base/types.js';
3
3
  /**
4
4
  * @class cex
5
5
  * @augments Exchange
@@ -7,7 +7,7 @@ import type { Balances, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, Or
7
7
  export default class cex extends Exchange {
8
8
  describe(): any;
9
9
  fetchCurrenciesFromCache(params?: {}): Promise<any>;
10
- fetchCurrencies(params?: {}): Promise<{}>;
10
+ fetchCurrencies(params?: {}): Promise<Currencies>;
11
11
  fetchMarkets(params?: {}): Promise<Market[]>;
12
12
  parseBalance(response: any): Balances;
13
13
  fetchBalance(params?: {}): Promise<Balances>;
@@ -19,7 +19,7 @@ export default class cex extends Exchange {
19
19
  fetchTicker(symbol: string, params?: {}): Promise<Ticker>;
20
20
  parseTrade(trade: any, market?: Market): Trade;
21
21
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
22
- fetchTradingFees(params?: {}): Promise<{}>;
22
+ fetchTradingFees(params?: {}): Promise<TradingFees>;
23
23
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): Promise<Order>;
24
24
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<any>;
25
25
  cancelAllOrders(symbol?: Str, params?: {}): Promise<any>;
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/coinbase.js';
2
- import type { Int, OrderSide, OrderType, Order, Trade, OHLCV, Ticker, OrderBook, Str, Transaction, Balances, Tickers, Strings, Market, Currency, Num, Account } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Order, Trade, OHLCV, Ticker, OrderBook, Str, Transaction, Balances, Tickers, Strings, Market, Currency, Num, Account, Currencies } from './base/types.js';
3
3
  /**
4
4
  * @class coinbase
5
5
  * @augments Exchange
@@ -34,7 +34,7 @@ export default class coinbase extends Exchange {
34
34
  fetchMarketsV2(params?: {}): Promise<any[]>;
35
35
  fetchMarketsV3(params?: {}): Promise<any[]>;
36
36
  fetchCurrenciesFromCache(params?: {}): Promise<import("./base/types.js").Dictionary<any>>;
37
- fetchCurrencies(params?: {}): Promise<{}>;
37
+ fetchCurrencies(params?: {}): Promise<Currencies>;
38
38
  fetchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
39
39
  fetchTickersV2(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Dictionary<Ticker>>;
40
40
  fetchTickersV3(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Dictionary<Ticker>>;
@@ -10,6 +10,7 @@ import { ExchangeError, ArgumentsRequired, AuthenticationError, BadRequest, Inva
10
10
  import { Precise } from './base/Precise.js';
11
11
  import { TICK_SIZE } from './base/functions/number.js';
12
12
  import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
13
+ import { jwt } from './base/functions/rsa.js';
13
14
  // ----------------------------------------------------------------------------
14
15
  /**
15
16
  * @class coinbase
@@ -3786,31 +3787,16 @@ export default class coinbase extends Exchange {
3786
3787
  const url = this.urls['api']['rest'] + fullPath;
3787
3788
  if (signed) {
3788
3789
  const authorization = this.safeString(this.headers, 'Authorization');
3790
+ let authorizationString = undefined;
3789
3791
  if (authorization !== undefined) {
3790
- headers = {
3791
- 'Authorization': authorization,
3792
- 'Content-Type': 'application/json',
3793
- };
3794
- if (method !== 'GET') {
3795
- if (Object.keys(query).length) {
3796
- body = this.json(query);
3797
- }
3798
- }
3792
+ authorizationString = authorization;
3799
3793
  }
3800
3794
  else if (this.token && !this.checkRequiredCredentials(false)) {
3801
- headers = {
3802
- 'Authorization': 'Bearer ' + this.token,
3803
- 'Content-Type': 'application/json',
3804
- };
3805
- if (method !== 'GET') {
3806
- if (Object.keys(query).length) {
3807
- body = this.json(query);
3808
- }
3809
- }
3795
+ authorizationString = 'Bearer ' + this.token;
3810
3796
  }
3811
3797
  else {
3812
3798
  this.checkRequiredCredentials();
3813
- const timestampString = this.seconds().toString();
3799
+ const seconds = this.seconds();
3814
3800
  let payload = '';
3815
3801
  if (method !== 'GET') {
3816
3802
  if (Object.keys(query).length) {
@@ -3829,14 +3815,52 @@ export default class coinbase extends Exchange {
3829
3815
  // https://docs.cloud.coinbase.com/advanced-trade-api/docs/auth#example-request
3830
3816
  // v2: 'GET' require payload in the signature
3831
3817
  // https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-key-authentication
3832
- const auth = timestampString + method + savedPath + payload;
3833
- const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256);
3818
+ const isCloudAPiKey = (this.apiKey.indexOf('organizations/') >= 0) || (this.secret.startsWith('-----BEGIN'));
3819
+ if (isCloudAPiKey) {
3820
+ if (this.apiKey.startsWith('-----BEGIN')) {
3821
+ throw new ArgumentsRequired(this.id + ' apiKey should contain the name (eg: organizations/3b910e93....) and not the public key');
3822
+ }
3823
+ // it may not work for v2
3824
+ let uri = method + ' ' + url.replace('https://', '');
3825
+ const quesPos = uri.indexOf('?');
3826
+ if (quesPos >= 0) {
3827
+ uri = uri.slice(0, quesPos);
3828
+ }
3829
+ const nonce = this.randomBytes(16);
3830
+ const request = {
3831
+ 'aud': ['retail_rest_api_proxy'],
3832
+ 'iss': 'coinbase-cloud',
3833
+ 'nbf': seconds,
3834
+ 'exp': seconds + 120,
3835
+ 'sub': this.apiKey,
3836
+ 'uri': uri,
3837
+ 'iat': seconds,
3838
+ };
3839
+ const token = jwt(request, this.encode(this.secret), sha256, false, { 'kid': this.apiKey, 'nonce': nonce, 'alg': 'ES256' });
3840
+ authorizationString = 'Bearer ' + token;
3841
+ }
3842
+ else {
3843
+ const timestampString = this.seconds().toString();
3844
+ const auth = timestampString + method + savedPath + payload;
3845
+ const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256);
3846
+ headers = {
3847
+ 'CB-ACCESS-KEY': this.apiKey,
3848
+ 'CB-ACCESS-SIGN': signature,
3849
+ 'CB-ACCESS-TIMESTAMP': timestampString,
3850
+ 'Content-Type': 'application/json',
3851
+ };
3852
+ }
3853
+ }
3854
+ if (authorizationString !== undefined) {
3834
3855
  headers = {
3835
- 'CB-ACCESS-KEY': this.apiKey,
3836
- 'CB-ACCESS-SIGN': signature,
3837
- 'CB-ACCESS-TIMESTAMP': timestampString,
3856
+ 'Authorization': authorizationString,
3838
3857
  'Content-Type': 'application/json',
3839
3858
  };
3859
+ if (method !== 'GET') {
3860
+ if (Object.keys(query).length) {
3861
+ body = this.json(query);
3862
+ }
3863
+ }
3840
3864
  }
3841
3865
  }
3842
3866
  return { 'url': url, 'method': method, 'body': body, 'headers': headers };
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/coinbaseinternational.js';
2
- import type { Int, OrderSide, OrderType, Order, Trade, Ticker, Str, Transaction, Balances, Tickers, Strings, Market, Currency, TransferEntry, Position, FundingRateHistory } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Order, Trade, Ticker, Str, Transaction, Balances, Tickers, Strings, Market, Currency, TransferEntry, Position, FundingRateHistory, Currencies } from './base/types.js';
3
3
  /**
4
4
  * @class coinbaseinternational
5
5
  * @augments Exchange
@@ -78,7 +78,7 @@ export default class coinbaseinternational extends Exchange {
78
78
  parseTrade(trade: any, market?: Market): Trade;
79
79
  fetchMarkets(params?: {}): Promise<Market[]>;
80
80
  parseMarket(market: any): Market;
81
- fetchCurrencies(params?: {}): Promise<any>;
81
+ fetchCurrencies(params?: {}): Promise<Currencies>;
82
82
  parseCurrency(currency: any): {
83
83
  id: string;
84
84
  name: string;
@@ -79,6 +79,7 @@ export default class coinbaseinternational extends Exchange {
79
79
  'fetchLedger': false,
80
80
  'fetchLeverage': false,
81
81
  'fetchLeverageTiers': false,
82
+ 'fetchMarginAdjustmentHistory': false,
82
83
  'fetchMarginMode': false,
83
84
  'fetchMarkets': true,
84
85
  'fetchMarkOHLCV': false,
@@ -1,12 +1,12 @@
1
1
  import Exchange from './abstract/coinbasepro.js';
2
- import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Strings, Market, Currency, Num, Account } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Strings, Market, Currency, Num, Account, Currencies, TradingFees } from './base/types.js';
3
3
  /**
4
4
  * @class coinbasepro
5
5
  * @augments Exchange
6
6
  */
7
7
  export default class coinbasepro extends Exchange {
8
8
  describe(): any;
9
- fetchCurrencies(params?: {}): Promise<{}>;
9
+ fetchCurrencies(params?: {}): Promise<Currencies>;
10
10
  fetchMarkets(params?: {}): Promise<Market[]>;
11
11
  fetchAccounts(params?: {}): Promise<Account[]>;
12
12
  parseAccount(account: any): {
@@ -24,7 +24,7 @@ export default class coinbasepro extends Exchange {
24
24
  parseTrade(trade: any, market?: Market): Trade;
25
25
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
26
26
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
27
- fetchTradingFees(params?: {}): Promise<{}>;
27
+ fetchTradingFees(params?: {}): Promise<TradingFees>;
28
28
  parseOHLCV(ohlcv: any, market?: Market): OHLCV;
29
29
  fetchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
30
30
  fetchTime(params?: {}): Promise<number>;
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/coincheck.js';
2
- import type { Balances, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Ticker, Trade, Transaction } from './base/types.js';
2
+ import type { Balances, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Ticker, Trade, TradingFees, Transaction } from './base/types.js';
3
3
  /**
4
4
  * @class coincheck
5
5
  * @augments Exchange
@@ -16,7 +16,7 @@ export default class coincheck extends Exchange {
16
16
  parseTrade(trade: any, market?: Market): Trade;
17
17
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
18
18
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
19
- fetchTradingFees(params?: {}): Promise<{}>;
19
+ fetchTradingFees(params?: {}): Promise<TradingFees>;
20
20
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): Promise<Order>;
21
21
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<any>;
22
22
  fetchDeposits(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Transaction[]>;
@@ -1,12 +1,12 @@
1
1
  import Exchange from './abstract/coinex.js';
2
- import type { Balances, Currency, FundingHistory, FundingRateHistory, Int, Market, OHLCV, Order, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, OrderRequest, TransferEntry, Leverage, Leverages, Num, MarginModification } from './base/types.js';
2
+ import type { Balances, Currency, FundingHistory, FundingRateHistory, Int, Market, OHLCV, Order, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, OrderRequest, TransferEntry, Leverage, Leverages, Num, MarginModification, TradingFeeInterface, Currencies, TradingFees } from './base/types.js';
3
3
  /**
4
4
  * @class coinex
5
5
  * @augments Exchange
6
6
  */
7
7
  export default class coinex extends Exchange {
8
8
  describe(): any;
9
- fetchCurrencies(params?: {}): Promise<{}>;
9
+ fetchCurrencies(params?: {}): Promise<Currencies>;
10
10
  fetchMarkets(params?: {}): Promise<Market[]>;
11
11
  fetchSpotMarkets(params: any): Promise<any[]>;
12
12
  fetchContractMarkets(params: any): Promise<any[]>;
@@ -17,23 +17,9 @@ export default class coinex extends Exchange {
17
17
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<import("./base/types.js").OrderBook>;
18
18
  parseTrade(trade: any, market?: Market): Trade;
19
19
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
20
- fetchTradingFee(symbol: string, params?: {}): Promise<{
21
- info: any;
22
- symbol: string;
23
- maker: number;
24
- taker: number;
25
- percentage: boolean;
26
- tierBased: boolean;
27
- }>;
28
- fetchTradingFees(params?: {}): Promise<{}>;
29
- parseTradingFee(fee: any, market?: Market): {
30
- info: any;
31
- symbol: string;
32
- maker: number;
33
- taker: number;
34
- percentage: boolean;
35
- tierBased: boolean;
36
- };
20
+ fetchTradingFee(symbol: string, params?: {}): Promise<TradingFeeInterface>;
21
+ fetchTradingFees(params?: {}): Promise<TradingFees>;
22
+ parseTradingFee(fee: any, market?: Market): TradingFeeInterface;
37
23
  parseOHLCV(ohlcv: any, market?: Market): OHLCV;
38
24
  fetchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
39
25
  fetchMarginBalance(params?: {}): Promise<Balances>;
@@ -138,6 +124,7 @@ export default class coinex extends Exchange {
138
124
  transfer(code: string, amount: number, fromAccount: string, toAccount: string, params?: {}): Promise<TransferEntry>;
139
125
  parseTransferStatus(status: any): string;
140
126
  parseTransfer(transfer: any, currency?: Currency): {
127
+ info: any;
141
128
  id: number;
142
129
  timestamp: number;
143
130
  datetime: string;
@@ -211,4 +198,5 @@ export default class coinex extends Exchange {
211
198
  headers: any;
212
199
  };
213
200
  handleErrors(httpCode: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
201
+ fetchMarginAdjustmentHistory(symbol?: Str, type?: Str, since?: Num, limit?: Num, params?: {}): Promise<MarginModification[]>;
214
202
  }
package/js/src/coinex.js CHANGED
@@ -83,6 +83,7 @@ export default class coinex extends Exchange {
83
83
  'fetchLeverage': 'emulated',
84
84
  'fetchLeverages': true,
85
85
  'fetchLeverageTiers': true,
86
+ 'fetchMarginAdjustmentHistory': true,
86
87
  'fetchMarketLeverageTiers': 'emulated',
87
88
  'fetchMarkets': true,
88
89
  'fetchMarkOHLCV': false,
@@ -4242,11 +4243,10 @@ export default class coinex extends Exchange {
4242
4243
  // "message":"OK"
4243
4244
  // }
4244
4245
  //
4246
+ const data = this.safeDict(response, 'data');
4245
4247
  const status = this.safeString(response, 'message');
4246
- const type = (addOrReduce === 1) ? 'add' : 'reduce';
4247
- return this.extend(this.parseMarginModification(response, market), {
4248
+ return this.extend(this.parseMarginModification(data, market), {
4248
4249
  'amount': this.parseNumber(amount),
4249
- 'type': type,
4250
4250
  'status': status,
4251
4251
  });
4252
4252
  }
@@ -4306,13 +4306,34 @@ export default class coinex extends Exchange {
4306
4306
  // "user_id": 3620173
4307
4307
  // }
4308
4308
  //
4309
- const timestamp = this.safeIntegerProduct(data, 'update_time', 1000);
4309
+ // fetchMarginAdjustmentHistory
4310
+ //
4311
+ // {
4312
+ // bkr_price: '0',
4313
+ // leverage: '3',
4314
+ // liq_price: '0',
4315
+ // margin_amount: '5.33236666666666666666',
4316
+ // margin_change: '3',
4317
+ // market: 'XRPUSDT',
4318
+ // position_amount: '11',
4319
+ // position_id: '297155652',
4320
+ // position_type: '2',
4321
+ // settle_price: '0.6361',
4322
+ // time: '1711050906.382891',
4323
+ // type: '1',
4324
+ // user_id: '3685860'
4325
+ // }
4326
+ //
4327
+ const marketId = this.safeString(data, 'market');
4328
+ const type = this.safeString(data, 'type');
4329
+ const timestamp = this.safeIntegerProduct2(data, 'time', 'update_time', 1000);
4310
4330
  return {
4311
4331
  'info': data,
4312
- 'symbol': this.safeSymbol(undefined, market),
4313
- 'type': undefined,
4314
- 'amount': this.safeNumber(data, 'margin_amount'),
4315
- 'total': undefined,
4332
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
4333
+ 'type': (type === '1') ? 'add' : 'reduce',
4334
+ 'marginMode': 'isolated',
4335
+ 'amount': this.safeNumber(data, 'margin_change'),
4336
+ 'total': this.safeNumber(data, 'position_amount'),
4316
4337
  'code': market['quote'],
4317
4338
  'status': undefined,
4318
4339
  'timestamp': timestamp,
@@ -4963,6 +4984,7 @@ export default class coinex extends Exchange {
4963
4984
  const currencyId = this.safeString(transfer, 'asset');
4964
4985
  const currencyCode = this.safeCurrencyCode(currencyId, currency);
4965
4986
  return {
4987
+ 'info': transfer,
4966
4988
  'id': this.safeInteger(transfer, 'id'),
4967
4989
  'timestamp': timestamp,
4968
4990
  'datetime': this.iso8601(timestamp),
@@ -5795,4 +5817,76 @@ export default class coinex extends Exchange {
5795
5817
  }
5796
5818
  return undefined;
5797
5819
  }
5820
+ async fetchMarginAdjustmentHistory(symbol = undefined, type = undefined, since = undefined, limit = undefined, params = {}) {
5821
+ /**
5822
+ * @method
5823
+ * @name coinex#fetchMarginAdjustmentHistory
5824
+ * @description fetches the history of margin added or reduced from contract isolated positions
5825
+ * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http046_position_margin_history
5826
+ * @param {string} [symbol] unified market symbol
5827
+ * @param {string} [type] not used by coinex fetchMarginAdjustmentHistory
5828
+ * @param {int} [since] timestamp in ms of the earliest change to fetch
5829
+ * @param {int} [limit] the maximum amount of changes to fetch, default=100, max=100
5830
+ * @param {object} params extra parameters specific to the exchange api endpoint
5831
+ * @param {int} [params.until] timestamp in ms of the latest change to fetch
5832
+ *
5833
+ * EXCHANGE SPECIFIC PARAMETERS
5834
+ * @param {int} [params.offset] offset
5835
+ * @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5836
+ */
5837
+ await this.loadMarkets();
5838
+ const until = this.safeInteger(params, 'until');
5839
+ params = this.omit(params, 'until');
5840
+ if (limit === undefined) {
5841
+ limit = 100;
5842
+ }
5843
+ const request = {
5844
+ 'market': '',
5845
+ 'position_id': 0,
5846
+ 'offset': 0,
5847
+ 'limit': limit,
5848
+ };
5849
+ if (symbol !== undefined) {
5850
+ const market = this.market(symbol);
5851
+ request['market'] = market['id'];
5852
+ }
5853
+ if (since !== undefined) {
5854
+ request['start_time'] = since;
5855
+ }
5856
+ if (until !== undefined) {
5857
+ request['end_time'] = until;
5858
+ }
5859
+ const response = await this.v1PerpetualPrivateGetPositionMarginHistory(this.extend(request, params));
5860
+ //
5861
+ // {
5862
+ // code: '0',
5863
+ // data: {
5864
+ // limit: '100',
5865
+ // offset: '0',
5866
+ // records: [
5867
+ // {
5868
+ // bkr_price: '0',
5869
+ // leverage: '3',
5870
+ // liq_price: '0',
5871
+ // margin_amount: '5.33236666666666666666',
5872
+ // margin_change: '3',
5873
+ // market: 'XRPUSDT',
5874
+ // position_amount: '11',
5875
+ // position_id: '297155652',
5876
+ // position_type: '2',
5877
+ // settle_price: '0.6361',
5878
+ // time: '1711050906.382891',
5879
+ // type: '1',
5880
+ // user_id: '3685860'
5881
+ // }
5882
+ // ]
5883
+ // },
5884
+ // message: 'OK'
5885
+ // }
5886
+ //
5887
+ const data = this.safeDict(response, 'data', {});
5888
+ const records = this.safeList(data, 'records', []);
5889
+ const modifications = this.parseMarginModifications(records, undefined, 'market', 'swap');
5890
+ return this.filterBySymbolSinceLimit(modifications, symbol, since, limit);
5891
+ }
5798
5892
  }
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/coinlist.js';
2
- import type { Account, Balances, Currency, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry } from './base/types.js';
2
+ import type { Account, Balances, Currencies, Currency, Int, Market, Num, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFees, Transaction, TransferEntry } from './base/types.js';
3
3
  /**
4
4
  * @class coinlist
5
5
  * @augments Exchange
@@ -8,7 +8,7 @@ export default class coinlist extends Exchange {
8
8
  describe(): any;
9
9
  calculateRateLimiterCost(api: any, method: any, path: any, params: any, config?: {}): number;
10
10
  fetchTime(params?: {}): Promise<number>;
11
- fetchCurrencies(params?: {}): Promise<{}>;
11
+ fetchCurrencies(params?: {}): Promise<Currencies>;
12
12
  fetchMarkets(params?: {}): Promise<Market[]>;
13
13
  parseMarket(market: any): Market;
14
14
  fetchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
@@ -19,7 +19,7 @@ export default class coinlist extends Exchange {
19
19
  parseOHLCV(ohlcv: any, market?: Market): OHLCV;
20
20
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
21
21
  parseTrade(trade: any, market?: Market): Trade;
22
- fetchTradingFees(params?: {}): Promise<{}>;
22
+ fetchTradingFees(params?: {}): Promise<TradingFees>;
23
23
  parseFeeTiers(feeTiers: any, market?: Market): {
24
24
  maker: any[];
25
25
  taker: any[];
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/coinmate.js';
2
- import type { Balances, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
2
+ import type { Balances, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, Transaction } from './base/types.js';
3
3
  /**
4
4
  * @class coinmate
5
5
  * @augments Exchange
@@ -20,14 +20,7 @@ export default class coinmate extends Exchange {
20
20
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
21
21
  parseTrade(trade: any, market?: Market): Trade;
22
22
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
23
- fetchTradingFee(symbol: string, params?: {}): Promise<{
24
- info: any;
25
- symbol: string;
26
- maker: number;
27
- taker: number;
28
- percentage: boolean;
29
- tierBased: boolean;
30
- }>;
23
+ fetchTradingFee(symbol: string, params?: {}): Promise<TradingFeeInterface>;
31
24
  fetchOpenOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
32
25
  fetchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
33
26
  parseOrderStatus(status: any): string;