ccxt 4.3.22 → 4.3.23

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.
package/README.md CHANGED
@@ -215,13 +215,13 @@ console.log(version, Object.keys(exchanges));
215
215
 
216
216
  All-in-one browser bundle (dependencies included), served from a CDN of your choice:
217
217
 
218
- * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.3.22/dist/ccxt.browser.js
219
- * unpkg: https://unpkg.com/ccxt@4.3.22/dist/ccxt.browser.js
218
+ * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.3.23/dist/ccxt.browser.js
219
+ * unpkg: https://unpkg.com/ccxt@4.3.23/dist/ccxt.browser.js
220
220
 
221
221
  CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.
222
222
 
223
223
  ```HTML
224
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.3.22/dist/ccxt.browser.js"></script>
224
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.3.23/dist/ccxt.browser.js"></script>
225
225
  ```
226
226
 
227
227
  Creates a global `ccxt` object:
package/dist/cjs/ccxt.js CHANGED
@@ -184,7 +184,7 @@ var woofipro$1 = require('./src/pro/woofipro.js');
184
184
 
185
185
  //-----------------------------------------------------------------------------
186
186
  // this is updated by vss.js when building
187
- const version = '4.3.22';
187
+ const version = '4.3.23';
188
188
  Exchange["default"].ccxtVersion = version;
189
189
  const exchanges = {
190
190
  'ace': ace,
@@ -9689,7 +9689,7 @@ class binance extends binance$1 {
9689
9689
  await this.loadMarkets();
9690
9690
  // by default cache the leverage bracket
9691
9691
  // it contains useful stuff like the maintenance margin and initial margin for positions
9692
- const leverageBrackets = this.safeDict(this.options, 'leverageBrackets', {});
9692
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets');
9693
9693
  if ((leverageBrackets === undefined) || (reload)) {
9694
9694
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
9695
9695
  const type = this.safeString(params, 'type', defaultType);
@@ -1810,6 +1810,11 @@ class coinbase extends coinbase$1 {
1810
1810
  if (symbols !== undefined) {
1811
1811
  request['product_ids'] = this.marketIds(symbols);
1812
1812
  }
1813
+ let marketType = undefined;
1814
+ [marketType, params] = this.handleMarketTypeAndParams('fetchTickers', this.getMarketFromSymbols(symbols), params, 'default');
1815
+ if (marketType !== undefined && marketType !== 'default') {
1816
+ request['product_type'] = (marketType === 'swap') ? 'FUTURE' : 'SPOT';
1817
+ }
1813
1818
  const response = await this.v3PublicGetBrokerageMarketProducts(this.extend(request, params));
1814
1819
  //
1815
1820
  // {
@@ -468,10 +468,53 @@ class coinex extends coinex$1 {
468
468
  '36': errors.RequestTimeout,
469
469
  '213': errors.RateLimitExceeded,
470
470
  '107': errors.InsufficientFunds,
471
+ '158': errors.PermissionDenied,
471
472
  '600': errors.OrderNotFound,
472
473
  '601': errors.InvalidOrder,
473
474
  '602': errors.InvalidOrder,
474
475
  '606': errors.InvalidOrder,
476
+ '3008': errors.RequestTimeout,
477
+ '3109': errors.InsufficientFunds,
478
+ '3127': errors.InvalidOrder,
479
+ '3606': errors.InvalidOrder,
480
+ '3610': errors.ExchangeError,
481
+ '3612': errors.InvalidOrder,
482
+ '3613': errors.InvalidOrder,
483
+ '3614': errors.InvalidOrder,
484
+ '3615': errors.InvalidOrder,
485
+ '3616': errors.InvalidOrder,
486
+ '3617': errors.InvalidOrder,
487
+ '3618': errors.InvalidOrder,
488
+ '3619': errors.InvalidOrder,
489
+ '3620': errors.InvalidOrder,
490
+ '3621': errors.InvalidOrder,
491
+ '3622': errors.InvalidOrder,
492
+ '3627': errors.InvalidOrder,
493
+ '3628': errors.InvalidOrder,
494
+ '3629': errors.InvalidOrder,
495
+ '3632': errors.InvalidOrder,
496
+ '3633': errors.InvalidOrder,
497
+ '3634': errors.InvalidOrder,
498
+ '3635': errors.InvalidOrder,
499
+ '4001': errors.ExchangeNotAvailable,
500
+ '4002': errors.RequestTimeout,
501
+ '4003': errors.ExchangeError,
502
+ '4004': errors.BadRequest,
503
+ '4005': errors.AuthenticationError,
504
+ '4006': errors.AuthenticationError,
505
+ '4007': errors.PermissionDenied,
506
+ '4008': errors.AuthenticationError,
507
+ '4009': errors.ExchangeError,
508
+ '4010': errors.ExchangeError,
509
+ '4011': errors.PermissionDenied,
510
+ '4017': errors.ExchangeError,
511
+ '4115': errors.AccountSuspended,
512
+ '4117': errors.BadSymbol,
513
+ '4123': errors.RateLimitExceeded,
514
+ '4130': errors.ExchangeError,
515
+ '4158': errors.ExchangeError,
516
+ '4213': errors.RateLimitExceeded,
517
+ '4512': errors.PermissionDenied, // Insufficient sub-account permissions, please check.
475
518
  },
476
519
  'broad': {
477
520
  'ip not allow visit': errors.PermissionDenied,
@@ -4394,8 +4437,8 @@ class coinex extends coinex$1 {
4394
4437
  /**
4395
4438
  * @method
4396
4439
  * @name coinex#fetchFundingHistory
4397
- * @description fetch the history of funding payments paid and received on this account
4398
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http034_funding_position
4440
+ * @description fetch the history of funding fee payments paid and received on this account
4441
+ * @see https://docs.coinex.com/api/v2/futures/position/http/list-position-funding-history
4399
4442
  * @param {string} symbol unified market symbol
4400
4443
  * @param {int} [since] the earliest time in ms to fetch funding history for
4401
4444
  * @param {int} [limit] the maximum number of funding history structures to retrieve
@@ -4405,54 +4448,47 @@ class coinex extends coinex$1 {
4405
4448
  if (symbol === undefined) {
4406
4449
  throw new errors.ArgumentsRequired(this.id + ' fetchFundingHistory() requires a symbol argument');
4407
4450
  }
4408
- limit = (limit === undefined) ? 100 : limit;
4409
4451
  await this.loadMarkets();
4410
4452
  const market = this.market(symbol);
4411
- const request = {
4453
+ let request = {
4412
4454
  'market': market['id'],
4413
- 'limit': limit,
4414
- // 'offset': 0,
4415
- // 'end_time': 1638990636000,
4416
- // 'windowtime': 1638990636000,
4455
+ 'market_type': 'FUTURES',
4417
4456
  };
4457
+ [request, params] = this.handleUntilOption('end_time', request, params);
4418
4458
  if (since !== undefined) {
4419
4459
  request['start_time'] = since;
4420
4460
  }
4421
- const response = await this.v1PerpetualPrivateGetPositionFunding(this.extend(request, params));
4461
+ if (limit !== undefined) {
4462
+ request['limit'] = limit;
4463
+ }
4464
+ const response = await this.v2PrivateGetFuturesPositionFundingHistory(this.extend(request, params));
4422
4465
  //
4423
4466
  // {
4424
4467
  // "code": 0,
4425
- // "data": {
4426
- // "limit": 100,
4427
- // "offset": 0,
4428
- // "records": [
4429
- // {
4430
- // "amount": "0.0012",
4431
- // "asset": "USDT",
4432
- // "funding": "-0.0095688273996",
4433
- // "funding_rate": "0.00020034",
4434
- // "market": "BTCUSDT",
4435
- // "position_id": 62052321,
4436
- // "price": "39802.45",
4437
- // "real_funding_rate": "0.00020034",
4438
- // "side": 2,
4439
- // "time": 1650729623.933885,
4440
- // "type": 1,
4441
- // "user_id": 3620173,
4442
- // "value": "47.76294"
4443
- // },
4444
- // ]
4445
- // },
4446
- // "message": "OK"
4468
+ // "data": [
4469
+ // {
4470
+ // "ccy": "USDT",
4471
+ // "created_at": 1715673620183,
4472
+ // "funding_rate": "0",
4473
+ // "funding_value": "0",
4474
+ // "market": "BTCUSDT",
4475
+ // "market_type": "FUTURES",
4476
+ // "position_id": 306458800,
4477
+ // "side": "long"
4478
+ // },
4479
+ // ],
4480
+ // "message": "OK",
4481
+ // "pagination": {
4482
+ // "has_next": true
4483
+ // }
4447
4484
  // }
4448
4485
  //
4449
- const data = this.safeValue(response, 'data', {});
4450
- const resultList = this.safeValue(data, 'records', []);
4486
+ const data = this.safeList(response, 'data', []);
4451
4487
  const result = [];
4452
- for (let i = 0; i < resultList.length; i++) {
4453
- const entry = resultList[i];
4454
- const timestamp = this.safeTimestamp(entry, 'time');
4455
- const currencyId = this.safeString(entry, 'asset');
4488
+ for (let i = 0; i < data.length; i++) {
4489
+ const entry = data[i];
4490
+ const timestamp = this.safeInteger(entry, 'created_at');
4491
+ const currencyId = this.safeString(entry, 'ccy');
4456
4492
  const code = this.safeCurrencyCode(currencyId);
4457
4493
  result.push({
4458
4494
  'info': entry,
@@ -4461,7 +4497,7 @@ class coinex extends coinex$1 {
4461
4497
  'timestamp': timestamp,
4462
4498
  'datetime': this.iso8601(timestamp),
4463
4499
  'id': this.safeNumber(entry, 'position_id'),
4464
- 'amount': this.safeNumber(entry, 'funding'),
4500
+ 'amount': this.safeNumber(entry, 'funding_value'),
4465
4501
  });
4466
4502
  }
4467
4503
  return result;
@@ -4471,7 +4507,7 @@ class coinex extends coinex$1 {
4471
4507
  * @method
4472
4508
  * @name coinex#fetchFundingRate
4473
4509
  * @description fetch the current funding rate
4474
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http008_market_ticker
4510
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate
4475
4511
  * @param {string} symbol unified market symbol
4476
4512
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4477
4513
  * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
@@ -4484,93 +4520,63 @@ class coinex extends coinex$1 {
4484
4520
  const request = {
4485
4521
  'market': market['id'],
4486
4522
  };
4487
- const response = await this.v1PerpetualPublicGetMarketTicker(this.extend(request, params));
4523
+ const response = await this.v2PublicGetFuturesFundingRate(this.extend(request, params));
4488
4524
  //
4489
4525
  // {
4490
- // "code": 0,
4491
- // "data":
4492
- // {
4493
- // "date": 1650678472474,
4494
- // "ticker": {
4495
- // "vol": "6090.9430",
4496
- // "low": "39180.30",
4497
- // "open": "40474.97",
4498
- // "high": "40798.01",
4499
- // "last": "39659.30",
4500
- // "buy": "39663.79",
4501
- // "period": 86400,
4502
- // "funding_time": 372,
4503
- // "position_amount": "270.1956",
4504
- // "funding_rate_last": "0.00022913",
4505
- // "funding_rate_next": "0.00013158",
4506
- // "funding_rate_predict": "0.00016552",
4507
- // "insurance": "16045554.83969682659674035672",
4508
- // "sign_price": "39652.48",
4509
- // "index_price": "39648.44250000",
4510
- // "sell_total": "22.3913",
4511
- // "buy_total": "19.4498",
4512
- // "buy_amount": "12.8942",
4513
- // "sell": "39663.80",
4514
- // "sell_amount": "0.9388"
4526
+ // "code": 0,
4527
+ // "data": [
4528
+ // {
4529
+ // "latest_funding_rate": "0",
4530
+ // "latest_funding_time": 1715731200000,
4531
+ // "mark_price": "61602.22",
4532
+ // "market": "BTCUSDT",
4533
+ // "max_funding_rate": "0.00375",
4534
+ // "min_funding_rate": "-0.00375",
4535
+ // "next_funding_rate": "0.00021074",
4536
+ // "next_funding_time": 1715760000000
4515
4537
  // }
4516
- // },
4538
+ // ],
4517
4539
  // "message": "OK"
4518
4540
  // }
4519
4541
  //
4520
- const data = this.safeValue(response, 'data', {});
4521
- const ticker = this.safeValue(data, 'ticker', {});
4522
- const timestamp = this.safeInteger(data, 'date');
4523
- ticker['timestamp'] = timestamp; // avoid changing parseFundingRate signature
4524
- return this.parseFundingRate(ticker, market);
4542
+ const data = this.safeList(response, 'data', []);
4543
+ const first = this.safeDict(data, 0, {});
4544
+ return this.parseFundingRate(first, market);
4525
4545
  }
4526
4546
  parseFundingRate(contract, market = undefined) {
4527
4547
  //
4528
- // fetchFundingRate
4548
+ // fetchFundingRate, fetchFundingRates
4529
4549
  //
4530
4550
  // {
4531
- // "vol": "6090.9430",
4532
- // "low": "39180.30",
4533
- // "open": "40474.97",
4534
- // "high": "40798.01",
4535
- // "last": "39659.30",
4536
- // "buy": "39663.79",
4537
- // "period": 86400,
4538
- // "funding_time": 372,
4539
- // "position_amount": "270.1956",
4540
- // "funding_rate_last": "0.00022913",
4541
- // "funding_rate_next": "0.00013158",
4542
- // "funding_rate_predict": "0.00016552",
4543
- // "insurance": "16045554.83969682659674035672",
4544
- // "sign_price": "39652.48",
4545
- // "index_price": "39648.44250000",
4546
- // "sell_total": "22.3913",
4547
- // "buy_total": "19.4498",
4548
- // "buy_amount": "12.8942",
4549
- // "sell": "39663.80",
4550
- // "sell_amount": "0.9388"
4551
+ // "latest_funding_rate": "0",
4552
+ // "latest_funding_time": 1715731200000,
4553
+ // "mark_price": "61602.22",
4554
+ // "market": "BTCUSDT",
4555
+ // "max_funding_rate": "0.00375",
4556
+ // "min_funding_rate": "-0.00375",
4557
+ // "next_funding_rate": "0.00021074",
4558
+ // "next_funding_time": 1715760000000
4551
4559
  // }
4552
4560
  //
4553
- const timestamp = this.safeInteger(contract, 'timestamp');
4554
- contract = this.omit(contract, 'timestamp');
4555
- const fundingDelta = this.safeInteger(contract, 'funding_time') * 60 * 1000;
4556
- const fundingHour = (timestamp + fundingDelta) / 3600000;
4557
- const fundingTimestamp = Math.round(fundingHour) * 3600000;
4561
+ const currentFundingTimestamp = this.safeInteger(contract, 'latest_funding_time');
4562
+ const futureFundingTimestamp = this.safeInteger(contract, 'next_funding_time');
4563
+ const marketId = this.safeString(contract, 'market');
4558
4564
  return {
4559
4565
  'info': contract,
4560
- 'symbol': this.safeSymbol(undefined, market),
4561
- 'markPrice': this.safeNumber(contract, 'sign_price'),
4562
- 'indexPrice': this.safeNumber(contract, 'index_price'),
4566
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
4567
+ 'markPrice': this.safeNumber(contract, 'mark_price'),
4568
+ 'indexPrice': undefined,
4563
4569
  'interestRate': undefined,
4564
4570
  'estimatedSettlePrice': undefined,
4565
- 'timestamp': timestamp,
4566
- 'datetime': this.iso8601(timestamp),
4567
- 'fundingRate': this.safeNumber(contract, 'funding_rate_next'),
4568
- 'fundingTimestamp': fundingTimestamp,
4569
- 'fundingDatetime': this.iso8601(fundingTimestamp),
4570
- 'nextFundingRate': this.safeNumber(contract, 'funding_rate_predict'),
4571
- 'nextFundingTimestamp': undefined,
4572
- 'nextFundingDatetime': undefined,
4573
- 'previousFundingRate': this.safeNumber(contract, 'funding_rate_last'),
4571
+ 'timestamp': undefined,
4572
+ 'datetime': undefined,
4573
+ 'fundingRate': this.safeNumber(contract, 'latest_funding_rate'),
4574
+ 'fundingTimestamp': currentFundingTimestamp,
4575
+ 'fundingDatetime': this.iso8601(currentFundingTimestamp),
4576
+ 'nextFundingRate': this.safeNumber(contract, 'next_funding_rate'),
4577
+ 'nextFundingTimestamp': futureFundingTimestamp,
4578
+ 'nextFundingDatetime': this.iso8601(futureFundingTimestamp),
4579
+ 'previousFundingRate': undefined,
4574
4580
  'previousFundingTimestamp': undefined,
4575
4581
  'previousFundingDatetime': undefined,
4576
4582
  };
@@ -4580,13 +4586,14 @@ class coinex extends coinex$1 {
4580
4586
  * @method
4581
4587
  * @name coinex#fetchFundingRates
4582
4588
  * @description fetch the current funding rates
4583
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http009_market_ticker_all
4589
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate
4584
4590
  * @param {string[]} symbols unified market symbols
4585
4591
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4586
4592
  * @returns {object[]} an array of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
4587
4593
  */
4588
4594
  await this.loadMarkets();
4589
4595
  symbols = this.marketSymbols(symbols);
4596
+ const request = {};
4590
4597
  let market = undefined;
4591
4598
  if (symbols !== undefined) {
4592
4599
  const symbol = this.safeValue(symbols, 0);
@@ -4594,55 +4601,30 @@ class coinex extends coinex$1 {
4594
4601
  if (!market['swap']) {
4595
4602
  throw new errors.BadSymbol(this.id + ' fetchFundingRates() supports swap contracts only');
4596
4603
  }
4604
+ const marketIds = this.marketIds(symbols);
4605
+ request['market'] = marketIds.join(',');
4597
4606
  }
4598
- const response = await this.v1PerpetualPublicGetMarketTickerAll(params);
4607
+ const response = await this.v2PublicGetFuturesFundingRate(this.extend(request, params));
4599
4608
  //
4600
4609
  // {
4601
4610
  // "code": 0,
4602
- // "data":
4603
- // {
4604
- // "date": 1650678472474,
4605
- // "ticker": {
4606
- // "BTCUSDT": {
4607
- // "vol": "6090.9430",
4608
- // "low": "39180.30",
4609
- // "open": "40474.97",
4610
- // "high": "40798.01",
4611
- // "last": "39659.30",
4612
- // "buy": "39663.79",
4613
- // "period": 86400,
4614
- // "funding_time": 372,
4615
- // "position_amount": "270.1956",
4616
- // "funding_rate_last": "0.00022913",
4617
- // "funding_rate_next": "0.00013158",
4618
- // "funding_rate_predict": "0.00016552",
4619
- // "insurance": "16045554.83969682659674035672",
4620
- // "sign_price": "39652.48",
4621
- // "index_price": "39648.44250000",
4622
- // "sell_total": "22.3913",
4623
- // "buy_total": "19.4498",
4624
- // "buy_amount": "12.8942",
4625
- // "sell": "39663.80",
4626
- // "sell_amount": "0.9388"
4627
- // }
4611
+ // "data": [
4612
+ // {
4613
+ // "latest_funding_rate": "0",
4614
+ // "latest_funding_time": 1715731200000,
4615
+ // "mark_price": "61602.22",
4616
+ // "market": "BTCUSDT",
4617
+ // "max_funding_rate": "0.00375",
4618
+ // "min_funding_rate": "-0.00375",
4619
+ // "next_funding_rate": "0.00021074",
4620
+ // "next_funding_time": 1715760000000
4628
4621
  // }
4629
- // },
4622
+ // ],
4630
4623
  // "message": "OK"
4631
4624
  // }
4632
- const data = this.safeValue(response, 'data', {});
4633
- const tickers = this.safeValue(data, 'ticker', {});
4634
- const timestamp = this.safeInteger(data, 'date');
4635
- const result = [];
4636
- const marketIds = Object.keys(tickers);
4637
- for (let i = 0; i < marketIds.length; i++) {
4638
- const marketId = marketIds[i];
4639
- if (marketId.indexOf('_') === -1) { // skip _signprice and _indexprice
4640
- const marketInner = this.safeMarket(marketId, undefined, undefined, 'swap');
4641
- const ticker = tickers[marketId];
4642
- ticker['timestamp'] = timestamp;
4643
- result.push(this.parseFundingRate(ticker, marketInner));
4644
- }
4645
- }
4625
+ //
4626
+ const data = this.safeList(response, 'data', []);
4627
+ const result = this.parseFundingRates(data, market);
4646
4628
  return this.filterByArray(result, 'symbol', symbols);
4647
4629
  }
4648
4630
  async withdraw(code, amount, address, tag = undefined, params = {}) {
@@ -4716,13 +4698,13 @@ class coinex extends coinex$1 {
4716
4698
  /**
4717
4699
  * @method
4718
4700
  * @name coinex#fetchFundingRateHistory
4719
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http038_funding_history
4720
4701
  * @description fetches historical funding rate prices
4702
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate-history
4721
4703
  * @param {string} symbol unified symbol of the market to fetch the funding rate history for
4722
4704
  * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
4723
4705
  * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
4724
4706
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4725
- * @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)
4707
+ * @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)
4726
4708
  * @param {int} [params.until] timestamp in ms of the latest funding rate
4727
4709
  * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
4728
4710
  */
@@ -4735,52 +4717,46 @@ class coinex extends coinex$1 {
4735
4717
  if (paginate) {
4736
4718
  return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params, 1000);
4737
4719
  }
4738
- if (limit === undefined) {
4739
- limit = 100;
4740
- }
4741
4720
  const market = this.market(symbol);
4742
4721
  let request = {
4743
4722
  'market': market['id'],
4744
- 'limit': limit,
4745
- 'offset': 0,
4746
- // 'end_time': 1638990636,
4747
4723
  };
4748
4724
  if (since !== undefined) {
4749
4725
  request['start_time'] = since;
4750
4726
  }
4727
+ if (limit !== undefined) {
4728
+ request['limit'] = limit;
4729
+ }
4751
4730
  [request, params] = this.handleUntilOption('end_time', request, params);
4752
- const response = await this.v1PerpetualPublicGetMarketFundingHistory(this.extend(request, params));
4731
+ const response = await this.v2PublicGetFuturesFundingRateHistory(this.extend(request, params));
4753
4732
  //
4754
4733
  // {
4755
4734
  // "code": 0,
4756
- // "data": {
4757
- // "offset": 0,
4758
- // "limit": 3,
4759
- // "records": [
4760
- // {
4761
- // "time": 1650672021.6230309,
4762
- // "market": "BTCUSDT",
4763
- // "asset": "USDT",
4764
- // "funding_rate": "0.00022913",
4765
- // "funding_rate_real": "0.00022913"
4766
- // },
4767
- // ]
4768
- // },
4769
- // "message": "OK"
4735
+ // "data": [
4736
+ // {
4737
+ // "actual_funding_rate": "0",
4738
+ // "funding_time": 1715731221761,
4739
+ // "market": "BTCUSDT",
4740
+ // "theoretical_funding_rate": "0"
4741
+ // },
4742
+ // ],
4743
+ // "message": "OK",
4744
+ // "pagination": {
4745
+ // "has_next": true
4746
+ // }
4770
4747
  // }
4771
4748
  //
4772
- const data = this.safeValue(response, 'data');
4773
- const result = this.safeValue(data, 'records', []);
4749
+ const data = this.safeList(response, 'data', []);
4774
4750
  const rates = [];
4775
- for (let i = 0; i < result.length; i++) {
4776
- const entry = result[i];
4751
+ for (let i = 0; i < data.length; i++) {
4752
+ const entry = data[i];
4777
4753
  const marketId = this.safeString(entry, 'market');
4778
4754
  const symbolInner = this.safeSymbol(marketId, market, undefined, 'swap');
4779
- const timestamp = this.safeTimestamp(entry, 'time');
4755
+ const timestamp = this.safeInteger(entry, 'funding_time');
4780
4756
  rates.push({
4781
4757
  'info': entry,
4782
4758
  'symbol': symbolInner,
4783
- 'fundingRate': this.safeNumber(entry, 'funding_rate'),
4759
+ 'fundingRate': this.safeNumber(entry, 'actual_funding_rate'),
4784
4760
  'timestamp': timestamp,
4785
4761
  'datetime': this.iso8601(timestamp),
4786
4762
  });
@@ -3907,7 +3907,8 @@ class phemex extends phemex$1 {
3907
3907
  request['limit'] = limit;
3908
3908
  }
3909
3909
  let response = undefined;
3910
- if (market['settle'] === 'USDT') {
3910
+ const isUsdt = market['settle'] === 'USDT';
3911
+ if (isUsdt) {
3911
3912
  response = await this.privateGetApiDataGFuturesFundingFees(this.extend(request, params));
3912
3913
  }
3913
3914
  else {
@@ -3922,13 +3923,13 @@ class phemex extends phemex$1 {
3922
3923
  // {
3923
3924
  // "symbol": "BTCUSD",
3924
3925
  // "currency": "BTC",
3925
- // "execQty": 18,
3926
+ // "execQty": 18, // "execQty" regular, but "execQtyRq" in hedge
3926
3927
  // "side": "Buy",
3927
- // "execPriceEp": 360086455,
3928
- // "execValueEv": 49987,
3929
- // "fundingRateEr": 10000,
3930
- // "feeRateEr": 10000,
3931
- // "execFeeEv": 5,
3928
+ // "execPriceEp": 360086455, // "execPriceEp" regular, but "execPriceRp" in hedge
3929
+ // "execValueEv": 49987, // "execValueEv" regular, but "execValueRv" in hedge
3930
+ // "fundingRateEr": 10000, // "fundingRateEr" regular, but "fundingRateRr" in hedge
3931
+ // "feeRateEr": 10000, // "feeRateEr" regular, but "feeRateRr" in hedge
3932
+ // "execFeeEv": 5, // "execFeeEv" regular, but "execFeeRv" in hedge
3932
3933
  // "createTime": 1651881600000
3933
3934
  // }
3934
3935
  // ]
@@ -3941,18 +3942,34 @@ class phemex extends phemex$1 {
3941
3942
  for (let i = 0; i < rows.length; i++) {
3942
3943
  const entry = rows[i];
3943
3944
  const timestamp = this.safeInteger(entry, 'createTime');
3945
+ const execFee = this.safeString2(entry, 'execFeeEv', 'execFeeRv');
3946
+ const currencyCode = this.safeCurrencyCode(this.safeString(entry, 'currency'));
3944
3947
  result.push({
3945
3948
  'info': entry,
3946
3949
  'symbol': this.safeString(entry, 'symbol'),
3947
- 'code': this.safeCurrencyCode(this.safeString(entry, 'currency')),
3950
+ 'code': currencyCode,
3948
3951
  'timestamp': timestamp,
3949
3952
  'datetime': this.iso8601(timestamp),
3950
3953
  'id': undefined,
3951
- 'amount': this.fromEv(this.safeString(entry, 'execFeeEv'), market),
3954
+ 'amount': this.parseFundingFeeToPrecision(execFee, market, currencyCode),
3952
3955
  });
3953
3956
  }
3954
3957
  return result;
3955
3958
  }
3959
+ parseFundingFeeToPrecision(value, market = undefined, currencyCode = undefined) {
3960
+ if (value === undefined || currencyCode === undefined) {
3961
+ return value;
3962
+ }
3963
+ // it was confirmed by phemex support, that USDT contracts use direct amounts in funding fees, while USD & INVERSE needs 'valueScale'
3964
+ const isUsdt = market['settle'] === 'USDT';
3965
+ if (!isUsdt) {
3966
+ const currency = this.safeCurrency(currencyCode);
3967
+ const scale = this.safeString(currency['info'], 'valueScale');
3968
+ const tickPrecision = this.parsePrecision(scale);
3969
+ value = Precise["default"].stringMul(value, tickPrecision);
3970
+ }
3971
+ return value;
3972
+ }
3956
3973
  async fetchFundingRate(symbol, params = {}) {
3957
3974
  /**
3958
3975
  * @method