ccxt 4.4.40 → 4.4.41

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 (46) hide show
  1. package/README.md +3 -3
  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 +20 -3
  5. package/dist/cjs/src/binance.js +24 -24
  6. package/dist/cjs/src/bingx.js +3 -1
  7. package/dist/cjs/src/bitfinex.js +1 -1
  8. package/dist/cjs/src/bitget.js +1 -0
  9. package/dist/cjs/src/bitmart.js +254 -1
  10. package/dist/cjs/src/bybit.js +8 -8
  11. package/dist/cjs/src/exmo.js +62 -4
  12. package/dist/cjs/src/gate.js +1 -1
  13. package/dist/cjs/src/htx.js +1 -1
  14. package/dist/cjs/src/hyperliquid.js +65 -1
  15. package/dist/cjs/src/kraken.js +129 -26
  16. package/dist/cjs/src/kucoin.js +6 -1
  17. package/dist/cjs/src/mexc.js +3 -3
  18. package/dist/cjs/src/okx.js +6 -1
  19. package/dist/cjs/src/xt.js +5 -2
  20. package/js/ccxt.d.ts +3 -3
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/bitmart.d.ts +2 -0
  23. package/js/src/abstract/okx.d.ts +5 -0
  24. package/js/src/base/Exchange.d.ts +6 -3
  25. package/js/src/base/Exchange.js +20 -3
  26. package/js/src/base/types.d.ts +2 -0
  27. package/js/src/binance.js +24 -24
  28. package/js/src/bingx.js +3 -1
  29. package/js/src/bitfinex.js +1 -1
  30. package/js/src/bitget.js +1 -0
  31. package/js/src/bitmart.d.ts +52 -1
  32. package/js/src/bitmart.js +254 -1
  33. package/js/src/bybit.js +8 -8
  34. package/js/src/exmo.d.ts +35 -0
  35. package/js/src/exmo.js +62 -4
  36. package/js/src/gate.js +1 -1
  37. package/js/src/htx.js +1 -1
  38. package/js/src/hyperliquid.d.ts +20 -1
  39. package/js/src/hyperliquid.js +65 -1
  40. package/js/src/kraken.d.ts +13 -7
  41. package/js/src/kraken.js +129 -26
  42. package/js/src/kucoin.js +6 -1
  43. package/js/src/mexc.js +3 -3
  44. package/js/src/okx.js +6 -1
  45. package/js/src/xt.js +5 -2
  46. package/package.json +2 -2
package/dist/cjs/ccxt.js CHANGED
@@ -200,7 +200,7 @@ var xt$1 = require('./src/pro/xt.js');
200
200
 
201
201
  //-----------------------------------------------------------------------------
202
202
  // this is updated by vss.js when building
203
- const version = '4.4.40';
203
+ const version = '4.4.41';
204
204
  Exchange["default"].ccxtVersion = version;
205
205
  const exchanges = {
206
206
  'ace': ace,
@@ -1444,6 +1444,7 @@ class Exchange {
1444
1444
  'fetchOHLCV': undefined,
1445
1445
  'fetchOHLCVWs': undefined,
1446
1446
  'fetchOpenInterest': undefined,
1447
+ 'fetchOpenInterests': undefined,
1447
1448
  'fetchOpenInterestHistory': undefined,
1448
1449
  'fetchOpenOrder': undefined,
1449
1450
  'fetchOpenOrders': undefined,
@@ -2278,6 +2279,9 @@ class Exchange {
2278
2279
  async fetchOpenInterest(symbol, params = {}) {
2279
2280
  throw new errors.NotSupported(this.id + ' fetchOpenInterest() is not supported yet');
2280
2281
  }
2282
+ async fetchOpenInterests(symbols = undefined, params = {}) {
2283
+ throw new errors.NotSupported(this.id + ' fetchOpenInterests() is not supported yet');
2284
+ }
2281
2285
  async signIn(params = {}) {
2282
2286
  throw new errors.NotSupported(this.id + ' signIn() is not supported yet');
2283
2287
  }
@@ -5733,6 +5737,14 @@ class Exchange {
5733
5737
  }
5734
5738
  return result;
5735
5739
  }
5740
+ parseOpenInterests(response, market = undefined) {
5741
+ const result = {};
5742
+ for (let i = 0; i < response.length; i++) {
5743
+ const parsed = this.parseOpenInterest(response[i], market);
5744
+ result[parsed['symbol']] = parsed;
5745
+ }
5746
+ return result;
5747
+ }
5736
5748
  parseLongShortRatio(info, market = undefined) {
5737
5749
  throw new errors.NotSupported(this.id + ' parseLongShortRatio() is not supported yet');
5738
5750
  }
@@ -5842,7 +5854,7 @@ class Exchange {
5842
5854
  parseOpenInterest(interest, market = undefined) {
5843
5855
  throw new errors.NotSupported(this.id + ' parseOpenInterest () is not supported yet');
5844
5856
  }
5845
- parseOpenInterests(response, market = undefined, since = undefined, limit = undefined) {
5857
+ parseOpenInterestsHistory(response, market = undefined, since = undefined, limit = undefined) {
5846
5858
  const interests = [];
5847
5859
  for (let i = 0; i < response.length; i++) {
5848
5860
  const entry = response[i];
@@ -6194,7 +6206,7 @@ class Exchange {
6194
6206
  }
6195
6207
  return [maxEntriesPerRequest, params];
6196
6208
  }
6197
- async fetchPaginatedCallDynamic(method, symbol = undefined, since = undefined, limit = undefined, params = {}, maxEntriesPerRequest = undefined) {
6209
+ async fetchPaginatedCallDynamic(method, symbol = undefined, since = undefined, limit = undefined, params = {}, maxEntriesPerRequest = undefined, removeRepeated = true) {
6198
6210
  let maxCalls = undefined;
6199
6211
  [maxCalls, params] = this.handleOptionAndParams(params, method, 'paginationCalls', 10);
6200
6212
  let maxRetries = undefined;
@@ -6202,6 +6214,8 @@ class Exchange {
6202
6214
  let paginationDirection = undefined;
6203
6215
  [paginationDirection, params] = this.handleOptionAndParams(params, method, 'paginationDirection', 'backward');
6204
6216
  let paginationTimestamp = undefined;
6217
+ let removeRepeatedOption = removeRepeated;
6218
+ [removeRepeatedOption, params] = this.handleOptionAndParams(params, method, 'removeRepeated', removeRepeated);
6205
6219
  let calls = 0;
6206
6220
  let result = [];
6207
6221
  let errors$1 = 0;
@@ -6272,7 +6286,10 @@ class Exchange {
6272
6286
  }
6273
6287
  }
6274
6288
  }
6275
- const uniqueResults = this.removeRepeatedElementsFromArray(result);
6289
+ let uniqueResults = result;
6290
+ if (removeRepeatedOption) {
6291
+ uniqueResults = this.removeRepeatedElementsFromArray(result);
6292
+ }
6276
6293
  const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
6277
6294
  return this.filterBySinceLimit(uniqueResults, since, limit, key);
6278
6295
  }
@@ -5229,8 +5229,8 @@ class binance extends binance$1 {
5229
5229
  uppercaseType = 'LIMIT_MAKER';
5230
5230
  }
5231
5231
  request['type'] = uppercaseType;
5232
- const stopPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
5233
- if (stopPrice !== undefined) {
5232
+ const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
5233
+ if (triggerPrice !== undefined) {
5234
5234
  if (uppercaseType === 'MARKET') {
5235
5235
  uppercaseType = 'STOP_LOSS';
5236
5236
  }
@@ -5241,7 +5241,7 @@ class binance extends binance$1 {
5241
5241
  const validOrderTypes = this.safeList(market['info'], 'orderTypes');
5242
5242
  if (!this.inArray(uppercaseType, validOrderTypes)) {
5243
5243
  if (initialUppercaseType !== uppercaseType) {
5244
- throw new errors.InvalidOrder(this.id + ' stopPrice parameter is not allowed for ' + symbol + ' ' + type + ' orders');
5244
+ throw new errors.InvalidOrder(this.id + ' triggerPrice parameter is not allowed for ' + symbol + ' ' + type + ' orders');
5245
5245
  }
5246
5246
  else {
5247
5247
  throw new errors.InvalidOrder(this.id + ' ' + type + ' is not a valid order type for the ' + symbol + ' market');
@@ -5262,7 +5262,7 @@ class binance extends binance$1 {
5262
5262
  request['newOrderRespType'] = this.safeValue(this.options['newOrderRespType'], type, 'RESULT'); // 'ACK' for order id, 'RESULT' for full order or 'FULL' for order with fills
5263
5263
  let timeInForceIsRequired = false;
5264
5264
  let priceIsRequired = false;
5265
- let stopPriceIsRequired = false;
5265
+ let triggerPriceIsRequired = false;
5266
5266
  let quantityIsRequired = false;
5267
5267
  if (uppercaseType === 'MARKET') {
5268
5268
  const quoteOrderQty = this.safeBool(this.options, 'quoteOrderQty', true);
@@ -5292,12 +5292,12 @@ class binance extends binance$1 {
5292
5292
  quantityIsRequired = true;
5293
5293
  }
5294
5294
  else if ((uppercaseType === 'STOP_LOSS') || (uppercaseType === 'TAKE_PROFIT')) {
5295
- stopPriceIsRequired = true;
5295
+ triggerPriceIsRequired = true;
5296
5296
  quantityIsRequired = true;
5297
5297
  }
5298
5298
  else if ((uppercaseType === 'STOP_LOSS_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
5299
5299
  quantityIsRequired = true;
5300
- stopPriceIsRequired = true;
5300
+ triggerPriceIsRequired = true;
5301
5301
  priceIsRequired = true;
5302
5302
  timeInForceIsRequired = true;
5303
5303
  }
@@ -5317,12 +5317,12 @@ class binance extends binance$1 {
5317
5317
  if (timeInForceIsRequired && (this.safeString(params, 'timeInForce') === undefined)) {
5318
5318
  request['timeInForce'] = this.options['defaultTimeInForce']; // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel
5319
5319
  }
5320
- if (stopPriceIsRequired) {
5321
- if (stopPrice === undefined) {
5322
- throw new errors.InvalidOrder(this.id + ' editOrder() requires a stopPrice extra param for a ' + type + ' order');
5320
+ if (triggerPriceIsRequired) {
5321
+ if (triggerPrice === undefined) {
5322
+ throw new errors.InvalidOrder(this.id + ' editOrder() requires a triggerPrice extra param for a ' + type + ' order');
5323
5323
  }
5324
5324
  else {
5325
- request['stopPrice'] = this.priceToPrecision(symbol, stopPrice);
5325
+ request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
5326
5326
  }
5327
5327
  }
5328
5328
  request['cancelReplaceMode'] = 'STOP_ON_FAILURE'; // If the cancel request fails, the new order placement will not be attempted.
@@ -5986,7 +5986,7 @@ class binance extends binance$1 {
5986
5986
  type = 'limit';
5987
5987
  }
5988
5988
  const stopPriceString = this.safeString(order, 'stopPrice');
5989
- const stopPrice = this.parseNumber(this.omitZero(stopPriceString));
5989
+ const triggerPrice = this.parseNumber(this.omitZero(stopPriceString));
5990
5990
  const feeCost = this.safeNumber(order, 'fee');
5991
5991
  let fee = undefined;
5992
5992
  if (feeCost !== undefined) {
@@ -6011,7 +6011,7 @@ class binance extends binance$1 {
6011
6011
  'reduceOnly': this.safeBool(order, 'reduceOnly'),
6012
6012
  'side': side,
6013
6013
  'price': price,
6014
- 'triggerPrice': stopPrice,
6014
+ 'triggerPrice': triggerPrice,
6015
6015
  'amount': amount,
6016
6016
  'cost': cost,
6017
6017
  'average': average,
@@ -6330,7 +6330,7 @@ class binance extends binance$1 {
6330
6330
  const validOrderTypes = this.safeList(market['info'], 'orderTypes');
6331
6331
  if (!this.inArray(uppercaseType, validOrderTypes)) {
6332
6332
  if (initialUppercaseType !== uppercaseType) {
6333
- throw new errors.InvalidOrder(this.id + ' stopPrice parameter is not allowed for ' + symbol + ' ' + type + ' orders');
6333
+ throw new errors.InvalidOrder(this.id + ' triggerPrice parameter is not allowed for ' + symbol + ' ' + type + ' orders');
6334
6334
  }
6335
6335
  else {
6336
6336
  throw new errors.InvalidOrder(this.id + ' ' + type + ' is not a valid order type for the ' + symbol + ' market');
@@ -6385,7 +6385,7 @@ class binance extends binance$1 {
6385
6385
  const closePosition = this.safeBool(params, 'closePosition', false);
6386
6386
  let timeInForceIsRequired = false;
6387
6387
  let priceIsRequired = false;
6388
- let stopPriceIsRequired = false;
6388
+ let triggerPriceIsRequired = false;
6389
6389
  let quantityIsRequired = false;
6390
6390
  //
6391
6391
  // spot/margin
@@ -6440,7 +6440,7 @@ class binance extends binance$1 {
6440
6440
  quantityIsRequired = true;
6441
6441
  }
6442
6442
  else if ((uppercaseType === 'STOP_LOSS') || (uppercaseType === 'TAKE_PROFIT')) {
6443
- stopPriceIsRequired = true;
6443
+ triggerPriceIsRequired = true;
6444
6444
  quantityIsRequired = true;
6445
6445
  if (market['linear'] || market['inverse']) {
6446
6446
  priceIsRequired = true;
@@ -6448,7 +6448,7 @@ class binance extends binance$1 {
6448
6448
  }
6449
6449
  else if ((uppercaseType === 'STOP_LOSS_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
6450
6450
  quantityIsRequired = true;
6451
- stopPriceIsRequired = true;
6451
+ triggerPriceIsRequired = true;
6452
6452
  priceIsRequired = true;
6453
6453
  timeInForceIsRequired = true;
6454
6454
  }
@@ -6458,14 +6458,14 @@ class binance extends binance$1 {
6458
6458
  }
6459
6459
  else if (uppercaseType === 'STOP') {
6460
6460
  quantityIsRequired = true;
6461
- stopPriceIsRequired = true;
6461
+ triggerPriceIsRequired = true;
6462
6462
  priceIsRequired = true;
6463
6463
  }
6464
6464
  else if ((uppercaseType === 'STOP_MARKET') || (uppercaseType === 'TAKE_PROFIT_MARKET')) {
6465
6465
  if (!closePosition) {
6466
6466
  quantityIsRequired = true;
6467
6467
  }
6468
- stopPriceIsRequired = true;
6468
+ triggerPriceIsRequired = true;
6469
6469
  }
6470
6470
  else if (uppercaseType === 'TRAILING_STOP_MARKET') {
6471
6471
  if (!closePosition) {
@@ -6504,16 +6504,16 @@ class binance extends binance$1 {
6504
6504
  request['price'] = this.parseToNumeric(price); // some options don't have the precision available
6505
6505
  }
6506
6506
  }
6507
- if (stopPriceIsRequired) {
6507
+ if (triggerPriceIsRequired) {
6508
6508
  if (market['contract']) {
6509
6509
  if (stopPrice === undefined) {
6510
- throw new errors.InvalidOrder(this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order');
6510
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires a triggerPrice extra param for a ' + type + ' order');
6511
6511
  }
6512
6512
  }
6513
6513
  else {
6514
6514
  // check for delta price as well
6515
6515
  if (trailingDelta === undefined && stopPrice === undefined && trailingPercent === undefined) {
6516
- throw new errors.InvalidOrder(this.id + ' createOrder() requires a stopPrice, trailingDelta or trailingPercent param for a ' + type + ' order');
6516
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires a triggerPrice, trailingDelta or trailingPercent param for a ' + type + ' order');
6517
6517
  }
6518
6518
  }
6519
6519
  if (stopPrice !== undefined) {
@@ -11637,7 +11637,7 @@ class binance extends binance$1 {
11637
11637
  let paginate = false;
11638
11638
  [paginate, params] = this.handleOptionAndParams(params, 'fetchLedger', 'paginate');
11639
11639
  if (paginate) {
11640
- return await this.fetchPaginatedCallDynamic('fetchLedger', code, since, limit, params);
11640
+ return await this.fetchPaginatedCallDynamic('fetchLedger', code, since, limit, params, undefined, false);
11641
11641
  }
11642
11642
  let type = undefined;
11643
11643
  let subType = undefined;
@@ -12819,7 +12819,7 @@ class binance extends binance$1 {
12819
12819
  // ...
12820
12820
  // ]
12821
12821
  //
12822
- return this.parseOpenInterests(response, market, since, limit);
12822
+ return this.parseOpenInterestsHistory(response, market, since, limit);
12823
12823
  }
12824
12824
  /**
12825
12825
  * @method
@@ -12888,7 +12888,7 @@ class binance extends binance$1 {
12888
12888
  //
12889
12889
  if (market['option']) {
12890
12890
  symbol = market['symbol'];
12891
- const result = this.parseOpenInterests(response, market);
12891
+ const result = this.parseOpenInterestsHistory(response, market);
12892
12892
  for (let i = 0; i < result.length; i++) {
12893
12893
  const item = result[i];
12894
12894
  if (item['symbol'] === symbol) {
@@ -48,6 +48,7 @@ class bingx extends bingx$1 {
48
48
  'createTrailingAmountOrder': true,
49
49
  'createTrailingPercentOrder': true,
50
50
  'createTriggerOrder': true,
51
+ 'editOrder': true,
51
52
  'fetchBalance': true,
52
53
  'fetchCanceledOrders': true,
53
54
  'fetchClosedOrders': true,
@@ -70,6 +71,7 @@ class bingx extends bingx$1 {
70
71
  'fetchMarkPrice': true,
71
72
  'fetchMarkPrices': true,
72
73
  'fetchMyLiquidations': true,
74
+ 'fetchMyTrades': true,
73
75
  'fetchOHLCV': true,
74
76
  'fetchOpenInterest': true,
75
77
  'fetchOpenOrders': true,
@@ -1037,7 +1039,7 @@ class bingx extends bingx$1 {
1037
1039
  };
1038
1040
  request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
1039
1041
  if (since !== undefined) {
1040
- request['startTime'] = since;
1042
+ request['startTime'] = Math.max(since - 1, 0);
1041
1043
  }
1042
1044
  if (limit !== undefined) {
1043
1045
  request['limit'] = limit;
@@ -3356,7 +3356,7 @@ class bitfinex extends bitfinex$1 {
3356
3356
  // ],
3357
3357
  // ]
3358
3358
  //
3359
- return this.parseOpenInterests(response, market, since, limit);
3359
+ return this.parseOpenInterestsHistory(response, market, since, limit);
3360
3360
  }
3361
3361
  parseOpenInterest(interest, market = undefined) {
3362
3362
  //
@@ -1243,6 +1243,7 @@ class bitget extends bitget$1 {
1243
1243
  '41103': errors.InvalidOrder,
1244
1244
  '41114': errors.OnMaintenance,
1245
1245
  '43011': errors.InvalidOrder,
1246
+ '43001': errors.OrderNotFound,
1246
1247
  '43012': errors.InsufficientFunds,
1247
1248
  '43025': errors.InvalidOrder,
1248
1249
  '43115': errors.OnMaintenance,
@@ -62,12 +62,13 @@ class bitmart extends bitmart$1 {
62
62
  'fetchDeposits': true,
63
63
  'fetchDepositWithdrawFee': true,
64
64
  'fetchDepositWithdrawFees': false,
65
- 'fetchFundingHistory': undefined,
65
+ 'fetchFundingHistory': true,
66
66
  'fetchFundingRate': true,
67
67
  'fetchFundingRateHistory': false,
68
68
  'fetchFundingRates': false,
69
69
  'fetchIsolatedBorrowRate': true,
70
70
  'fetchIsolatedBorrowRates': true,
71
+ 'fetchLedger': true,
71
72
  'fetchLiquidations': false,
72
73
  'fetchMarginMode': false,
73
74
  'fetchMarkets': true,
@@ -154,6 +155,7 @@ class bitmart extends bitmart$1 {
154
155
  'contract/public/depth': 5,
155
156
  'contract/public/open-interest': 30,
156
157
  'contract/public/funding-rate': 30,
158
+ 'contract/public/funding-rate-history': 30,
157
159
  'contract/public/kline': 6,
158
160
  'account/v1/currencies': 30,
159
161
  },
@@ -204,6 +206,7 @@ class bitmart extends bitmart$1 {
204
206
  'contract/private/position-risk': 10,
205
207
  'contract/private/affilate/rebate-list': 10,
206
208
  'contract/private/affilate/trade-list': 10,
209
+ 'contract/private/transaction-history': 10,
207
210
  },
208
211
  'post': {
209
212
  // sub-account endpoints
@@ -4615,6 +4618,65 @@ class bitmart extends bitmart$1 {
4615
4618
  const data = this.safeDict(response, 'data', {});
4616
4619
  return this.parseFundingRate(data, market);
4617
4620
  }
4621
+ /**
4622
+ * @method
4623
+ * @name bitmart#fetchFundingRateHistory
4624
+ * @description fetches historical funding rate prices
4625
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#get-funding-rate-history
4626
+ * @param {string} symbol unified symbol of the market to fetch the funding rate history for
4627
+ * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
4628
+ * @param {int} [limit] the maximum amount of funding rate structures to fetch
4629
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4630
+ * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
4631
+ */
4632
+ async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
4633
+ if (symbol === undefined) {
4634
+ throw new errors.ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a symbol argument');
4635
+ }
4636
+ await this.loadMarkets();
4637
+ const market = this.market(symbol);
4638
+ const request = {
4639
+ 'symbol': market['id'],
4640
+ };
4641
+ if (limit !== undefined) {
4642
+ request['limit'] = limit;
4643
+ }
4644
+ const response = await this.publicGetContractPublicFundingRateHistory(this.extend(request, params));
4645
+ //
4646
+ // {
4647
+ // "code": 1000,
4648
+ // "message": "Ok",
4649
+ // "data": {
4650
+ // "list": [
4651
+ // {
4652
+ // "symbol": "BTCUSDT",
4653
+ // "funding_rate": "0.000091412174",
4654
+ // "funding_time": "1734336000000"
4655
+ // },
4656
+ // ]
4657
+ // },
4658
+ // "trace": "fg73d949fgfdf6a40c8fc7f5ae6738.54.345345345345"
4659
+ // }
4660
+ //
4661
+ const data = this.safeDict(response, 'data', {});
4662
+ const result = this.safeList(data, 'list', []);
4663
+ const rates = [];
4664
+ for (let i = 0; i < result.length; i++) {
4665
+ const entry = result[i];
4666
+ const marketId = this.safeString(entry, 'symbol');
4667
+ const symbolInner = this.safeSymbol(marketId, market, '-', 'swap');
4668
+ const timestamp = this.safeInteger(entry, 'funding_time');
4669
+ rates.push({
4670
+ 'info': entry,
4671
+ 'symbol': symbolInner,
4672
+ 'fundingRate': this.safeNumber(entry, 'funding_rate'),
4673
+ 'timestamp': timestamp,
4674
+ 'datetime': this.iso8601(timestamp),
4675
+ });
4676
+ }
4677
+ const sorted = this.sortBy(rates, 'timestamp');
4678
+ return this.filterBySymbolSinceLimit(sorted, market['symbol'], since, limit);
4679
+ }
4618
4680
  parseFundingRate(contract, market = undefined) {
4619
4681
  //
4620
4682
  // {
@@ -5049,6 +5111,197 @@ class bitmart extends bitmart$1 {
5049
5111
  const data = this.safeDict(response, 'data', {});
5050
5112
  return this.parseOrder(data, market);
5051
5113
  }
5114
+ /**
5115
+ * @method
5116
+ * @name bitmart#fetchLedger
5117
+ * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
5118
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#get-transaction-history-keyed
5119
+ * @param {string} [code] unified currency code
5120
+ * @param {int} [since] timestamp in ms of the earliest ledger entry
5121
+ * @param {int} [limit] max number of ledger entries to return
5122
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5123
+ * @param {int} [params.until] timestamp in ms of the latest ledger entry
5124
+ * @returns {object[]} a list of [ledger structures]{@link https://docs.ccxt.com/#/?id=ledger}
5125
+ */
5126
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
5127
+ await this.loadMarkets();
5128
+ let currency = undefined;
5129
+ if (code !== undefined) {
5130
+ currency = this.currency(code);
5131
+ }
5132
+ let request = {};
5133
+ [request, params] = this.handleUntilOption('end_time', request, params);
5134
+ const transactionsRequest = this.fetchTransactionsRequest(0, undefined, since, limit, params);
5135
+ const response = await this.privateGetContractPrivateTransactionHistory(transactionsRequest);
5136
+ //
5137
+ // {
5138
+ // "code": 1000,
5139
+ // "message": "Ok",
5140
+ // "data": [
5141
+ // {
5142
+ // "time": "1734422402121",
5143
+ // "type": "Funding Fee",
5144
+ // "amount": "-0.00008253",
5145
+ // "asset": "USDT",
5146
+ // "symbol": "LTCUSDT",
5147
+ // "tran_id": "1734422402121",
5148
+ // "flow_type": 3
5149
+ // },
5150
+ // ],
5151
+ // "trace": "4cd11f83c71egfhfgh842790f07241e.23.173442343427772866"
5152
+ // }
5153
+ //
5154
+ const data = this.safeList(response, 'data', []);
5155
+ return this.parseLedger(data, currency, since, limit);
5156
+ }
5157
+ parseLedgerEntry(item, currency = undefined) {
5158
+ //
5159
+ // {
5160
+ // "time": "1734422402121",
5161
+ // "type": "Funding Fee",
5162
+ // "amount": "-0.00008253",
5163
+ // "asset": "USDT",
5164
+ // "symbol": "LTCUSDT",
5165
+ // "tran_id": "1734422402121",
5166
+ // "flow_type": 3
5167
+ // }
5168
+ //
5169
+ let amount = this.safeString(item, 'amount');
5170
+ let direction = undefined;
5171
+ if (Precise["default"].stringLe(amount, '0')) {
5172
+ direction = 'out';
5173
+ amount = Precise["default"].stringMul('-1', amount);
5174
+ }
5175
+ else {
5176
+ direction = 'in';
5177
+ }
5178
+ const currencyId = this.safeString(item, 'asset');
5179
+ const timestamp = this.safeInteger(item, 'time');
5180
+ const type = this.safeString(item, 'type');
5181
+ return this.safeLedgerEntry({
5182
+ 'info': item,
5183
+ 'id': this.safeString(item, 'tran_id'),
5184
+ 'direction': direction,
5185
+ 'account': undefined,
5186
+ 'referenceAccount': undefined,
5187
+ 'referenceId': this.safeString(item, 'tradeId'),
5188
+ 'type': this.parseLedgerEntryType(type),
5189
+ 'currency': this.safeCurrencyCode(currencyId, currency),
5190
+ 'amount': this.parseNumber(amount),
5191
+ 'timestamp': timestamp,
5192
+ 'datetime': this.iso8601(timestamp),
5193
+ 'before': undefined,
5194
+ 'after': undefined,
5195
+ 'status': undefined,
5196
+ 'fee': undefined,
5197
+ }, currency);
5198
+ }
5199
+ parseLedgerEntryType(type) {
5200
+ const ledgerType = {
5201
+ 'Commission Fee': 'fee',
5202
+ 'Funding Fee': 'fee',
5203
+ 'Realized PNL': 'trade',
5204
+ 'Transfer': 'transfer',
5205
+ 'Liquidation Clearance': 'settlement',
5206
+ };
5207
+ return this.safeString(ledgerType, type, type);
5208
+ }
5209
+ fetchTransactionsRequest(flowType = undefined, symbol = undefined, since = undefined, limit = undefined, params = {}) {
5210
+ let request = {};
5211
+ if (flowType !== undefined) {
5212
+ request['flow_type'] = flowType;
5213
+ }
5214
+ let market = undefined;
5215
+ if (symbol !== undefined) {
5216
+ market = this.market(symbol);
5217
+ request['symbol'] = market['id'];
5218
+ }
5219
+ if (since !== undefined) {
5220
+ request['start_time'] = since;
5221
+ }
5222
+ if (limit !== undefined) {
5223
+ request['page_size'] = limit;
5224
+ }
5225
+ [request, params] = this.handleUntilOption('end_time', request, params);
5226
+ return this.extend(request, params);
5227
+ }
5228
+ /**
5229
+ * @method
5230
+ * @name bitmart#fetchFundingHistory
5231
+ * @description fetch the history of funding payments paid and received on this account
5232
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#get-transaction-history-keyed
5233
+ * @param {string} [symbol] unified market symbol
5234
+ * @param {int} [since] the starting timestamp in milliseconds
5235
+ * @param {int} [limit] the number of entries to return
5236
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5237
+ * @param {int} [params.until] the latest time in ms to fetch funding history for
5238
+ * @returns {object[]} a list of [funding history structures]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
5239
+ */
5240
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
5241
+ await this.loadMarkets();
5242
+ let market = undefined;
5243
+ if (symbol !== undefined) {
5244
+ market = this.market(symbol);
5245
+ }
5246
+ let request = {};
5247
+ [request, params] = this.handleUntilOption('end_time', request, params);
5248
+ const transactionsRequest = this.fetchTransactionsRequest(3, symbol, since, limit, params);
5249
+ const response = await this.privateGetContractPrivateTransactionHistory(transactionsRequest);
5250
+ //
5251
+ // {
5252
+ // "code": 1000,
5253
+ // "message": "Ok",
5254
+ // "data": [
5255
+ // {
5256
+ // "time": "1734422402121",
5257
+ // "type": "Funding Fee",
5258
+ // "amount": "-0.00008253",
5259
+ // "asset": "USDT",
5260
+ // "symbol": "LTCUSDT",
5261
+ // "tran_id": "1734422402121",
5262
+ // "flow_type": 3
5263
+ // },
5264
+ // ],
5265
+ // "trace": "4cd11f83c71egfhfgh842790f07241e.23.173442343427772866"
5266
+ // }
5267
+ //
5268
+ const data = this.safeList(response, 'data', []);
5269
+ return this.parseFundingHistories(data, market, since, limit);
5270
+ }
5271
+ parseFundingHistory(contract, market = undefined) {
5272
+ //
5273
+ // {
5274
+ // "time": "1734422402121",
5275
+ // "type": "Funding Fee",
5276
+ // "amount": "-0.00008253",
5277
+ // "asset": "USDT",
5278
+ // "symbol": "LTCUSDT",
5279
+ // "tran_id": "1734422402121",
5280
+ // "flow_type": 3
5281
+ // }
5282
+ //
5283
+ const marketId = this.safeString(contract, 'symbol');
5284
+ const currencyId = this.safeString(contract, 'asset');
5285
+ const timestamp = this.safeInteger(contract, 'time');
5286
+ return {
5287
+ 'info': contract,
5288
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
5289
+ 'code': this.safeCurrencyCode(currencyId),
5290
+ 'timestamp': timestamp,
5291
+ 'datetime': this.iso8601(timestamp),
5292
+ 'id': this.safeString(contract, 'tran_id'),
5293
+ 'amount': this.safeNumber(contract, 'amount'),
5294
+ };
5295
+ }
5296
+ parseFundingHistories(contracts, market = undefined, since = undefined, limit = undefined) {
5297
+ const result = [];
5298
+ for (let i = 0; i < contracts.length; i++) {
5299
+ const contract = contracts[i];
5300
+ result.push(this.parseFundingHistory(contract, market));
5301
+ }
5302
+ const sorted = this.sortBy(result, 'timestamp');
5303
+ return this.filterBySinceLimit(sorted, since, limit);
5304
+ }
5052
5305
  nonce() {
5053
5306
  return this.milliseconds();
5054
5307
  }
@@ -3682,33 +3682,33 @@ class bybit extends bybit$1 {
3682
3682
  const avgPrice = this.omitZero(this.safeString(order, 'avgPrice'));
3683
3683
  const rawTimeInForce = this.safeString(order, 'timeInForce');
3684
3684
  const timeInForce = this.parseTimeInForce(rawTimeInForce);
3685
- const stopPrice = this.omitZero(this.safeString(order, 'triggerPrice'));
3685
+ const triggerPrice = this.omitZero(this.safeString(order, 'triggerPrice'));
3686
3686
  const reduceOnly = this.safeBool(order, 'reduceOnly');
3687
3687
  let takeProfitPrice = this.omitZero(this.safeString(order, 'takeProfit'));
3688
3688
  let stopLossPrice = this.omitZero(this.safeString(order, 'stopLoss'));
3689
3689
  const triggerDirection = this.safeString(order, 'triggerDirection');
3690
3690
  const isAscending = (triggerDirection === '1');
3691
- const isStopOrderType2 = (stopPrice !== undefined) && reduceOnly;
3691
+ const isStopOrderType2 = (triggerPrice !== undefined) && reduceOnly;
3692
3692
  if ((stopLossPrice === undefined) && isStopOrderType2) {
3693
3693
  // check if order is stop order type 2 - stopLossPrice
3694
3694
  if (isAscending && (side === 'buy')) {
3695
3695
  // stopLoss order against short position
3696
- stopLossPrice = stopPrice;
3696
+ stopLossPrice = triggerPrice;
3697
3697
  }
3698
3698
  if (!isAscending && (side === 'sell')) {
3699
3699
  // stopLoss order against a long position
3700
- stopLossPrice = stopPrice;
3700
+ stopLossPrice = triggerPrice;
3701
3701
  }
3702
3702
  }
3703
3703
  if ((takeProfitPrice === undefined) && isStopOrderType2) {
3704
3704
  // check if order is stop order type 2 - takeProfitPrice
3705
3705
  if (isAscending && (side === 'sell')) {
3706
3706
  // takeprofit order against a long position
3707
- takeProfitPrice = stopPrice;
3707
+ takeProfitPrice = triggerPrice;
3708
3708
  }
3709
3709
  if (!isAscending && (side === 'buy')) {
3710
3710
  // takeprofit order against a short position
3711
- takeProfitPrice = stopPrice;
3711
+ takeProfitPrice = triggerPrice;
3712
3712
  }
3713
3713
  }
3714
3714
  return this.safeOrder({
@@ -3726,7 +3726,7 @@ class bybit extends bybit$1 {
3726
3726
  'reduceOnly': this.safeBool(order, 'reduceOnly'),
3727
3727
  'side': side,
3728
3728
  'price': price,
3729
- 'triggerPrice': stopPrice,
3729
+ 'triggerPrice': triggerPrice,
3730
3730
  'takeProfitPrice': takeProfitPrice,
3731
3731
  'stopLossPrice': stopLossPrice,
3732
3732
  'amount': amount,
@@ -6754,7 +6754,7 @@ class bybit extends bybit$1 {
6754
6754
  const data = this.addPaginationCursorToResult(response);
6755
6755
  const id = this.safeString(result, 'symbol');
6756
6756
  market = this.safeMarket(id, market, undefined, 'contract');
6757
- return this.parseOpenInterests(data, market, since, limit);
6757
+ return this.parseOpenInterestsHistory(data, market, since, limit);
6758
6758
  }
6759
6759
  /**
6760
6760
  * @method