ccxt 4.1.8 → 4.1.10

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 (69) hide show
  1. package/.git-templates/hooks/pre-push +55 -0
  2. package/README.md +3 -3
  3. package/dist/ccxt.browser.js +1458 -302
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +3 -1
  6. package/dist/cjs/src/base/Exchange.js +59 -3
  7. package/dist/cjs/src/bingx.js +103 -41
  8. package/dist/cjs/src/bitbns.js +107 -83
  9. package/dist/cjs/src/bitget.js +35 -17
  10. package/dist/cjs/src/btcalpha.js +9 -1
  11. package/dist/cjs/src/btcmarkets.js +5 -5
  12. package/dist/cjs/src/coinex.js +14 -2
  13. package/dist/cjs/src/deribit.js +6 -0
  14. package/dist/cjs/src/gate.js +9 -1
  15. package/dist/cjs/src/hitbtc.js +20 -2
  16. package/dist/cjs/src/kucoinfutures.js +2 -2
  17. package/dist/cjs/src/phemex.js +20 -1
  18. package/dist/cjs/src/pro/bingx.js +891 -0
  19. package/dist/cjs/src/probit.js +3 -0
  20. package/dist/cjs/src/woo.js +21 -1
  21. package/js/ccxt.d.ts +6 -3
  22. package/js/ccxt.js +3 -1
  23. package/js/src/abstract/bingx.d.ts +1 -0
  24. package/js/src/base/Exchange.d.ts +6 -3
  25. package/js/src/base/Exchange.js +59 -3
  26. package/js/src/base/types.d.ts +7 -0
  27. package/js/src/binance.d.ts +17 -17
  28. package/js/src/bingx.d.ts +4 -3
  29. package/js/src/bingx.js +103 -41
  30. package/js/src/bitbns.d.ts +1 -1
  31. package/js/src/bitbns.js +107 -83
  32. package/js/src/bitfinex2.d.ts +13 -13
  33. package/js/src/bitget.d.ts +15 -15
  34. package/js/src/bitget.js +35 -17
  35. package/js/src/bitmex.d.ts +15 -15
  36. package/js/src/btcalpha.js +9 -1
  37. package/js/src/btcmarkets.js +5 -5
  38. package/js/src/bybit.d.ts +23 -23
  39. package/js/src/coinbase.d.ts +16 -16
  40. package/js/src/coinbasepro.d.ts +12 -12
  41. package/js/src/coinex.d.ts +2 -2
  42. package/js/src/coinex.js +14 -2
  43. package/js/src/cryptocom.d.ts +12 -12
  44. package/js/src/deribit.d.ts +2 -2
  45. package/js/src/deribit.js +6 -0
  46. package/js/src/digifinex.d.ts +2 -2
  47. package/js/src/gate.d.ts +10 -10
  48. package/js/src/gate.js +9 -1
  49. package/js/src/hitbtc.d.ts +2 -2
  50. package/js/src/hitbtc.js +20 -2
  51. package/js/src/huobi.d.ts +16 -16
  52. package/js/src/kraken.d.ts +2 -2
  53. package/js/src/krakenfutures.d.ts +6 -6
  54. package/js/src/kucoin.d.ts +13 -13
  55. package/js/src/kucoinfutures.d.ts +10 -10
  56. package/js/src/kucoinfutures.js +2 -2
  57. package/js/src/mexc.d.ts +3 -3
  58. package/js/src/okx.d.ts +13 -13
  59. package/js/src/phemex.d.ts +2 -2
  60. package/js/src/phemex.js +20 -1
  61. package/js/src/poloniex.d.ts +5 -5
  62. package/js/src/pro/bingx.d.ts +24 -0
  63. package/js/src/pro/bingx.js +892 -0
  64. package/js/src/probit.js +3 -0
  65. package/js/src/woo.d.ts +2 -2
  66. package/js/src/woo.js +21 -1
  67. package/package.json +1 -1
  68. package/pyproject.toml +8 -0
  69. package/skip-tests.json +4 -1
package/dist/cjs/ccxt.js CHANGED
@@ -124,6 +124,7 @@ var binance$1 = require('./src/pro/binance.js');
124
124
  var binancecoinm$1 = require('./src/pro/binancecoinm.js');
125
125
  var binanceus$1 = require('./src/pro/binanceus.js');
126
126
  var binanceusdm$1 = require('./src/pro/binanceusdm.js');
127
+ var bingx$1 = require('./src/pro/bingx.js');
127
128
  var bitcoincom$1 = require('./src/pro/bitcoincom.js');
128
129
  var bitfinex$1 = require('./src/pro/bitfinex.js');
129
130
  var bitfinex2$1 = require('./src/pro/bitfinex2.js');
@@ -179,7 +180,7 @@ var woo$1 = require('./src/pro/woo.js');
179
180
 
180
181
  //-----------------------------------------------------------------------------
181
182
  // this is updated by vss.js when building
182
- const version = '4.1.8';
183
+ const version = '4.1.10';
183
184
  Exchange["default"].ccxtVersion = version;
184
185
  const exchanges = {
185
186
  'ace': ace,
@@ -296,6 +297,7 @@ const pro = {
296
297
  'binancecoinm': binancecoinm$1,
297
298
  'binanceus': binanceus$1,
298
299
  'binanceusdm': binanceusdm$1,
300
+ 'bingx': bingx$1,
299
301
  'bitcoincom': bitcoincom$1,
300
302
  'bitfinex': bitfinex$1,
301
303
  'bitfinex2': bitfinex2$1,
@@ -2101,7 +2101,7 @@ class Exchange {
2101
2101
  // string = true
2102
2102
  //
2103
2103
  // [
2104
- // { 'currency': 'BTC', 'cost': '0.3' },
2104
+ // { 'currency': 'BTC', 'cost': '0.4' },
2105
2105
  // { 'currency': 'BTC', 'cost': '0.6', 'rate': '0.00123' },
2106
2106
  // { 'currency': 'BTC', 'cost': '0.5', 'rate': '0.00456' },
2107
2107
  // { 'currency': 'USDT', 'cost': '12.3456' },
@@ -3291,6 +3291,9 @@ class Exchange {
3291
3291
  async fetchOpenInterest(symbol, params = {}) {
3292
3292
  throw new errors.NotSupported(this.id + ' fetchOpenInterest() is not supported yet');
3293
3293
  }
3294
+ async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3295
+ throw new errors.NotSupported(this.id + ' fetchFundingRateHistory() is not supported yet');
3296
+ }
3294
3297
  parseLastPrice(price, market = undefined) {
3295
3298
  throw new errors.NotSupported(this.id + ' parseLastPrice() is not supported yet');
3296
3299
  }
@@ -4181,7 +4184,9 @@ class Exchange {
4181
4184
  }
4182
4185
  }
4183
4186
  }
4184
- return this.removeRepeatedElementsFromArray(result);
4187
+ const uniqueResults = this.removeRepeatedElementsFromArray(result);
4188
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4189
+ return this.filterBySinceLimit(uniqueResults, since, limit, key);
4185
4190
  }
4186
4191
  async safeDeterministicCall(method, symbol = undefined, since = undefined, limit = undefined, timeframe = undefined, params = {}) {
4187
4192
  let maxRetries = undefined;
@@ -4236,7 +4241,9 @@ class Exchange {
4236
4241
  for (let i = 0; i < results.length; i++) {
4237
4242
  result = this.arrayConcat(result, results[i]);
4238
4243
  }
4239
- return this.removeRepeatedElementsFromArray(result);
4244
+ const uniqueResults = this.removeRepeatedElementsFromArray(result);
4245
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4246
+ return this.filterBySinceLimit(uniqueResults, since, limit, key);
4240
4247
  }
4241
4248
  async fetchPaginatedCallCursor(method, symbol = undefined, since = undefined, limit = undefined, params = {}, cursorReceived = undefined, cursorSent = undefined, cursorIncrement = undefined, maxEntriesPerRequest = undefined) {
4242
4249
  let maxCalls = undefined;
@@ -4280,6 +4287,55 @@ class Exchange {
4280
4287
  }
4281
4288
  i += 1;
4282
4289
  }
4290
+ const sorted = this.sortCursorPaginatedResult(result);
4291
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4292
+ return this.filterBySinceLimit(sorted, since, limit, key);
4293
+ }
4294
+ async fetchPaginatedCallIncremental(method, symbol = undefined, since = undefined, limit = undefined, params = {}, pageKey = undefined, maxEntriesPerRequest = undefined) {
4295
+ let maxCalls = undefined;
4296
+ [maxCalls, params] = this.handleOptionAndParams(params, method, 'paginationCalls', 10);
4297
+ let maxRetries = undefined;
4298
+ [maxRetries, params] = this.handleOptionAndParams(params, method, 'maxRetries', 3);
4299
+ [maxEntriesPerRequest, params] = this.handleMaxEntriesPerRequestAndParams(method, maxEntriesPerRequest, params);
4300
+ let i = 0;
4301
+ let errors = 0;
4302
+ let result = [];
4303
+ while (i < maxCalls) {
4304
+ try {
4305
+ params[pageKey] = i + 1;
4306
+ const response = await this[method](symbol, since, maxEntriesPerRequest, params);
4307
+ errors = 0;
4308
+ const responseLength = response.length;
4309
+ if (this.verbose) {
4310
+ this.log('Incremental pagination call', i + 1, 'method', method, 'response length', responseLength);
4311
+ }
4312
+ if (responseLength === 0) {
4313
+ break;
4314
+ }
4315
+ result = this.arrayConcat(result, response);
4316
+ }
4317
+ catch (e) {
4318
+ errors += 1;
4319
+ if (errors > maxRetries) {
4320
+ throw e;
4321
+ }
4322
+ }
4323
+ i += 1;
4324
+ }
4325
+ const sorted = this.sortCursorPaginatedResult(result);
4326
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4327
+ return this.filterBySinceLimit(sorted, since, limit, key);
4328
+ }
4329
+ sortCursorPaginatedResult(result) {
4330
+ const first = this.safeValue(result, 0);
4331
+ if (first !== undefined) {
4332
+ if ('timestamp' in first) {
4333
+ return this.sortBy(result, 'timestamp');
4334
+ }
4335
+ if ('id' in first) {
4336
+ return this.sortBy(result, 'id');
4337
+ }
4338
+ }
4283
4339
  return result;
4284
4340
  }
4285
4341
  removeRepeatedElementsFromArray(input) {
@@ -66,6 +66,7 @@ class bingx extends bingx$1 {
66
66
  'swap': 'https://open-api.{hostname}/openApi',
67
67
  'contract': 'https://open-api.{hostname}/openApi',
68
68
  'wallets': 'https://open-api.{hostname}/openApi',
69
+ 'user': 'https://open-api.{hostname}/openApi',
69
70
  'subAccount': 'https://open-api.{hostname}/openApi',
70
71
  'account': 'https://open-api.{hostname}/openApi',
71
72
  },
@@ -234,6 +235,15 @@ class bingx extends bingx$1 {
234
235
  },
235
236
  },
236
237
  },
238
+ 'user': {
239
+ 'auth': {
240
+ 'private': {
241
+ 'post': {
242
+ 'userDataStream': 1,
243
+ },
244
+ },
245
+ },
246
+ },
237
247
  'copyTrading': {
238
248
  'v1': {
239
249
  'private': {
@@ -311,6 +321,7 @@ class bingx extends bingx$1 {
311
321
  },
312
322
  'commonCurrencies': {},
313
323
  'options': {
324
+ 'defaultType': 'spot',
314
325
  'accountsByType': {
315
326
  'spot': 'FUND',
316
327
  'swap': 'PFUTURES',
@@ -830,37 +841,63 @@ class bingx extends bingx$1 {
830
841
  // filledTime: '2023-07-04T20:56:01.000+0800'
831
842
  // }
832
843
  //
833
- let time = this.safeInteger2(trade, 'time', 'filledTm');
844
+ //
845
+ // ws
846
+ //
847
+ // spot
848
+ //
849
+ // {
850
+ // E: 1690214529432,
851
+ // T: 1690214529386,
852
+ // e: 'trade',
853
+ // m: true,
854
+ // p: '29110.19',
855
+ // q: '0.1868',
856
+ // s: 'BTC-USDT',
857
+ // t: '57903921'
858
+ // }
859
+ //
860
+ // swap
861
+ //
862
+ // {
863
+ // q: '0.0421',
864
+ // p: '29023.5',
865
+ // T: 1690221401344,
866
+ // m: false,
867
+ // s: 'BTC-USDT'
868
+ // }
869
+ //
870
+ let time = this.safeIntegerN(trade, ['time', 'filledTm', 'T']);
834
871
  const datetimeId = this.safeString(trade, 'filledTm');
835
872
  if (datetimeId !== undefined) {
836
873
  time = this.parse8601(datetimeId);
837
874
  }
838
- const isBuyerMaker = this.safeValue2(trade, 'buyerMaker', 'isBuyerMaker');
839
- let takeOrMaker = undefined;
840
- let side = undefined;
841
- if (isBuyerMaker !== undefined) {
842
- side = isBuyerMaker ? 'sell' : 'buy';
843
- takeOrMaker = 'taker';
875
+ if (time === 0) {
876
+ time = undefined;
844
877
  }
878
+ const isBuyerMaker = this.safeValue2(trade, 'buyerMaker', 'isBuyerMaker');
879
+ const side = this.safeStringLower2(trade, 'side', 'S');
845
880
  const cost = this.safeString(trade, 'quoteQty');
846
881
  const type = (cost === undefined) ? 'spot' : 'swap';
847
- const currencyId = this.safeString(trade, 'currency');
882
+ const currencyId = this.safeString2(trade, 'currency', 'N');
848
883
  const currencyCode = this.safeCurrencyCode(currencyId);
884
+ const m = this.safeValue(trade, 'm', false);
885
+ const marketId = this.safeString(trade, 's');
849
886
  return this.safeTrade({
850
- 'id': this.safeString2(trade, 'id', 'orderId'),
887
+ 'id': this.safeStringN(trade, ['id', 't']),
851
888
  'info': trade,
852
889
  'timestamp': time,
853
890
  'datetime': this.iso8601(time),
854
- 'symbol': this.safeSymbol(undefined, market, '-', type),
855
- 'order': undefined,
856
- 'type': undefined,
857
- 'side': side,
858
- 'takerOrMaker': takeOrMaker,
859
- 'price': this.safeString(trade, 'price'),
860
- 'amount': this.safeString2(trade, 'qty', 'amount'),
891
+ 'symbol': this.safeSymbol(marketId, market, '-', type),
892
+ 'order': this.safeString2(trade, 'orderId', 'i'),
893
+ 'type': this.safeStringLower(trade, 'o'),
894
+ 'side': this.parseOrderSide(side),
895
+ 'takerOrMaker': (isBuyerMaker || m) ? 'maker' : 'taker',
896
+ 'price': this.safeString2(trade, 'price', 'p'),
897
+ 'amount': this.safeStringN(trade, ['qty', 'amount', 'q']),
861
898
  'cost': cost,
862
899
  'fee': {
863
- 'cost': this.parseNumber(Precise["default"].stringAbs(this.safeString(trade, 'commission'))),
900
+ 'cost': this.parseNumber(Precise["default"].stringAbs(this.safeString2(trade, 'commission', 'n'))),
864
901
  'currency': currencyCode,
865
902
  'rate': undefined,
866
903
  },
@@ -1514,8 +1551,9 @@ class bingx extends bingx$1 {
1514
1551
  'liquidationPrice': undefined,
1515
1552
  'entryPrice': this.safeNumber2(position, 'avgPrice', 'entryPrice'),
1516
1553
  'unrealizedPnl': this.safeNumber(position, 'unrealizedProfit'),
1554
+ 'realizedPnl': this.safeNumber(position, 'realisedProfit'),
1517
1555
  'percentage': undefined,
1518
- 'contracts': undefined,
1556
+ 'contracts': this.safeNumber(position, 'positionAmt'),
1519
1557
  'contractSize': undefined,
1520
1558
  'markPrice': undefined,
1521
1559
  'lastPrice': undefined,
@@ -1526,7 +1564,7 @@ class bingx extends bingx$1 {
1526
1564
  'lastUpdateTimestamp': undefined,
1527
1565
  'maintenanceMargin': undefined,
1528
1566
  'maintenanceMarginPercentage': undefined,
1529
- 'collateral': this.safeString(position, 'positionAmt'),
1567
+ 'collateral': this.safeNumber(position, 'positionAmt'),
1530
1568
  'initialMargin': this.safeNumber(position, 'initialMargin'),
1531
1569
  'initialMarginPercentage': undefined,
1532
1570
  'leverage': this.safeNumber(position, 'leverage'),
@@ -1580,15 +1618,20 @@ class bingx extends bingx$1 {
1580
1618
  request['timeInForce'] = 'POC';
1581
1619
  }
1582
1620
  const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1583
- if (createMarketBuyOrderRequiresPrice && isMarketOrder && (side === 'buy')) {
1584
- if (price === undefined) {
1585
- throw new errors.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1621
+ if (isMarketOrder && (side === 'buy')) {
1622
+ if (createMarketBuyOrderRequiresPrice) {
1623
+ if (price === undefined) {
1624
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1625
+ }
1626
+ else {
1627
+ const amountString = this.numberToString(amount);
1628
+ const priceString = this.numberToString(price);
1629
+ const cost = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
1630
+ request['quoteOrderQty'] = this.priceToPrecision(symbol, cost);
1631
+ }
1586
1632
  }
1587
1633
  else {
1588
- const amountString = this.numberToString(amount);
1589
- const priceString = this.numberToString(price);
1590
- const cost = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
1591
- request['quoteOrderQty'] = this.priceToPrecision(symbol, cost);
1634
+ request['quoteOrderQty'] = this.priceToPrecision(symbol, amount);
1592
1635
  }
1593
1636
  }
1594
1637
  else {
@@ -1704,6 +1747,15 @@ class bingx extends bingx$1 {
1704
1747
  const order = this.safeValue(data, 'order', data);
1705
1748
  return this.parseOrder(order, market);
1706
1749
  }
1750
+ parseOrderSide(side) {
1751
+ const sides = {
1752
+ 'BUY': 'buy',
1753
+ 'SELL': 'sell',
1754
+ 'SHORT': 'sell',
1755
+ 'LONG': 'buy',
1756
+ };
1757
+ return this.safeString(sides, side, side);
1758
+ }
1707
1759
  parseOrder(order, market = undefined) {
1708
1760
  //
1709
1761
  // spot
@@ -1801,39 +1853,49 @@ class bingx extends bingx$1 {
1801
1853
  // "workingType": "MARK_PRICE"
1802
1854
  // }
1803
1855
  //
1804
- const positionSide = this.safeString(order, 'positionSide');
1856
+ const positionSide = this.safeString2(order, 'positionSide', 'ps');
1805
1857
  const marketType = (positionSide === undefined) ? 'spot' : 'swap';
1806
- const marketId = this.safeString(order, 'symbol');
1858
+ const marketId = this.safeString2(order, 'symbol', 's');
1807
1859
  const symbol = this.safeSymbol(marketId, market, '-', marketType);
1808
- const timestamp = this.safeInteger2(order, 'time', 'transactTime');
1860
+ const orderId = this.safeString2(order, 'orderId', 'i');
1861
+ const side = this.safeStringLower2(order, 'side', 'S');
1862
+ const type = this.safeStringLower2(order, 'type', 'o');
1863
+ const timestamp = this.safeIntegerN(order, ['time', 'transactTime', 'E']);
1864
+ const lastTradeTimestamp = this.safeInteger2(order, 'updateTime', 'T');
1865
+ const price = this.safeString2(order, 'price', 'p');
1866
+ const average = this.safeString2(order, 'avgPrice', 'ap');
1867
+ const amount = this.safeString2(order, 'origQty', 'q');
1868
+ const filled = this.safeString2(order, 'executedQty', 'z');
1869
+ const statusId = this.safeString2(order, 'status', 'X');
1809
1870
  const fee = {
1810
- 'currency': this.safeString(order, 'feeAsset'),
1811
- 'rate': this.safeString2(order, 'fee', 'commission'),
1871
+ 'currency': this.safeString2(order, 'feeAsset', 'N'),
1872
+ 'rate': this.safeStringN(order, ['fee', 'commission', 'n']),
1812
1873
  };
1874
+ const clientOrderId = this.safeString2(order, 'clientOrderId', 'c');
1813
1875
  return this.safeOrder({
1814
1876
  'info': order,
1815
- 'id': this.safeString(order, 'orderId'),
1816
- 'clientOrderId': this.safeString(order, 'clientOrderId'),
1877
+ 'id': orderId,
1878
+ 'clientOrderId': clientOrderId,
1817
1879
  'timestamp': timestamp,
1818
1880
  'datetime': this.iso8601(timestamp),
1819
- 'lastTradeTimestamp': this.safeInteger(order, 'updateTime'),
1881
+ 'lastTradeTimestamp': lastTradeTimestamp,
1820
1882
  'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
1821
1883
  'symbol': symbol,
1822
- 'type': this.safeStringLower(order, 'type'),
1884
+ 'type': type,
1823
1885
  'timeInForce': undefined,
1824
1886
  'postOnly': undefined,
1825
- 'side': this.safeStringLower(order, 'side'),
1826
- 'price': this.safeString(order, 'price'),
1887
+ 'side': this.parseOrderSide(side),
1888
+ 'price': price,
1827
1889
  'stopPrice': this.safeNumber(order, 'stopPrice'),
1828
1890
  'triggerPrice': this.safeNumber(order, 'stopPrice'),
1829
1891
  'stopLossPrice': this.safeNumber(order, 'stopLoss'),
1830
1892
  'takeProfitPrice': this.safeNumber(order, 'takeProfit'),
1831
- 'average': this.safeString(order, 'avgPrice'),
1893
+ 'average': average,
1832
1894
  'cost': undefined,
1833
- 'amount': this.safeString(order, 'origQty'),
1834
- 'filled': this.safeString(order, 'executedQty'),
1895
+ 'amount': amount,
1896
+ 'filled': filled,
1835
1897
  'remaining': undefined,
1836
- 'status': this.parseOrderStatus(this.safeString(order, 'status')),
1898
+ 'status': this.parseOrderStatus(statusId),
1837
1899
  'fee': fee,
1838
1900
  'trades': undefined,
1839
1901
  }, market);