ccxt 4.4.23 → 4.4.24

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/js/src/gate.js CHANGED
@@ -102,6 +102,7 @@ export default class gate extends Exchange {
102
102
  'createTriggerOrder': true,
103
103
  'editOrder': true,
104
104
  'fetchBalance': true,
105
+ 'fetchBorrowInterest': true,
105
106
  'fetchBorrowRateHistories': false,
106
107
  'fetchBorrowRateHistory': false,
107
108
  'fetchClosedOrders': true,
@@ -1539,7 +1540,7 @@ export default class gate extends Exchange {
1539
1540
  }
1540
1541
  return [request, query];
1541
1542
  }
1542
- multiOrderSpotPrepareRequest(market = undefined, stop = false, params = {}) {
1543
+ multiOrderSpotPrepareRequest(market = undefined, trigger = false, params = {}) {
1543
1544
  /**
1544
1545
  * @ignore
1545
1546
  * @method
@@ -1550,12 +1551,12 @@ export default class gate extends Exchange {
1550
1551
  * @param {object} [params] request parameters
1551
1552
  * @returns the api request object, and the new params object with non-needed parameters removed
1552
1553
  */
1553
- const [marginMode, query] = this.getMarginMode(stop, params);
1554
+ const [marginMode, query] = this.getMarginMode(trigger, params);
1554
1555
  const request = {
1555
1556
  'account': marginMode,
1556
1557
  };
1557
1558
  if (market !== undefined) {
1558
- if (stop) {
1559
+ if (trigger) {
1559
1560
  // gate spot and margin stop orders use the term market instead of currency_pair, and normal instead of spot. Neither parameter is used when fetching/cancelling a single order. They are used for creating a single stop order, but createOrder does not call this method
1560
1561
  request['market'] = market['id'];
1561
1562
  }
@@ -1596,6 +1597,11 @@ export default class gate extends Exchange {
1596
1597
  throw new BadRequest(this.id + ' getMarginMode() does not support stop orders for cross margin');
1597
1598
  }
1598
1599
  }
1600
+ let isUnifiedAccount = false;
1601
+ [isUnifiedAccount, params] = this.handleOptionAndParams(params, 'getMarginMode', 'unifiedAccount');
1602
+ if (isUnifiedAccount) {
1603
+ marginMode = 'unified';
1604
+ }
1599
1605
  return [marginMode, params];
1600
1606
  }
1601
1607
  getSettlementCurrencies(type, method) {
@@ -3371,10 +3377,12 @@ export default class gate extends Exchange {
3371
3377
  * @param {int} [params.offset] *contract only* list offset, starting from 0
3372
3378
  * @param {string} [params.last_id] *contract only* specify list staring point using the id of last record in previous list-query results
3373
3379
  * @param {int} [params.count_total] *contract only* whether to return total number matched, default to 0(no return)
3374
- * @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)
3380
+ * @param {bool} [params.unifiedAccount] set to true for fetching trades in a unified account
3381
+ * @param {bool} [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)
3375
3382
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
3376
3383
  */
3377
3384
  await this.loadMarkets();
3385
+ await this.loadUnifiedStatus();
3378
3386
  let paginate = false;
3379
3387
  [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
3380
3388
  if (paginate) {
@@ -3932,9 +3940,11 @@ export default class gate extends Exchange {
3932
3940
  * @param {bool} [params.auto_size] *contract only* Set side to close dual-mode position, close_long closes the long side, while close_short the short one, size also needs to be set to 0
3933
3941
  * @param {int} [params.price_type] *contract only* 0 latest deal price, 1 mark price, 2 index price
3934
3942
  * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
3943
+ * @param {bool} [params.unifiedAccount] set to true for creating an order in the unified account
3935
3944
  * @returns {object|undefined} [An order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3936
3945
  */
3937
3946
  await this.loadMarkets();
3947
+ await this.loadUnifiedStatus();
3938
3948
  const market = this.market(symbol);
3939
3949
  const trigger = this.safeValue(params, 'trigger');
3940
3950
  const triggerPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
@@ -4086,6 +4096,7 @@ export default class gate extends Exchange {
4086
4096
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4087
4097
  */
4088
4098
  await this.loadMarkets();
4099
+ await this.loadUnifiedStatus();
4089
4100
  const ordersRequests = this.createOrdersRequest(orders, params);
4090
4101
  const firstOrder = orders[0];
4091
4102
  const market = this.market(firstOrder['symbol']);
@@ -4367,9 +4378,11 @@ export default class gate extends Exchange {
4367
4378
  * @param {string} symbol unified symbol of the market to create an order in
4368
4379
  * @param {float} cost how much you want to trade in units of the quote currency
4369
4380
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4381
+ * @param {bool} [params.unifiedAccount] set to true for creating a unified account order
4370
4382
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4371
4383
  */
4372
4384
  await this.loadMarkets();
4385
+ await this.loadUnifiedStatus();
4373
4386
  const market = this.market(symbol);
4374
4387
  if (!market['spot']) {
4375
4388
  throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
@@ -4379,8 +4392,14 @@ export default class gate extends Exchange {
4379
4392
  }
4380
4393
  editOrderRequest(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
4381
4394
  const market = this.market(symbol);
4382
- const [marketType, query] = this.handleMarketTypeAndParams('editOrder', market, params);
4383
- const account = this.convertTypeToAccount(marketType);
4395
+ let marketType = undefined;
4396
+ [marketType, params] = this.handleMarketTypeAndParams('editOrder', market, params);
4397
+ let account = this.convertTypeToAccount(marketType);
4398
+ let isUnifiedAccount = false;
4399
+ [isUnifiedAccount, params] = this.handleOptionAndParams(params, 'editOrder', 'unifiedAccount');
4400
+ if (isUnifiedAccount) {
4401
+ account = 'unified';
4402
+ }
4384
4403
  const isLimitOrder = (type === 'limit');
4385
4404
  if (account === 'spot') {
4386
4405
  if (!isLimitOrder) {
@@ -4412,7 +4431,7 @@ export default class gate extends Exchange {
4412
4431
  if (!market['spot']) {
4413
4432
  request['settle'] = market['settleId'];
4414
4433
  }
4415
- return this.extend(request, query);
4434
+ return this.extend(request, params);
4416
4435
  }
4417
4436
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
4418
4437
  /**
@@ -4428,9 +4447,11 @@ export default class gate extends Exchange {
4428
4447
  * @param {float} amount how much of the currency you want to trade in units of the base currency
4429
4448
  * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
4430
4449
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4450
+ * @param {bool} [params.unifiedAccount] set to true for editing an order in a unified account
4431
4451
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4432
4452
  */
4433
4453
  await this.loadMarkets();
4454
+ await this.loadUnifiedStatus();
4434
4455
  const market = this.market(symbol);
4435
4456
  const extendedRequest = this.editOrderRequest(id, symbol, type, side, amount, price, params);
4436
4457
  let response = undefined;
@@ -4692,21 +4713,21 @@ export default class gate extends Exchange {
4692
4713
  // Everything below this(above return) is related to fees
4693
4714
  const fees = [];
4694
4715
  const gtFee = this.safeString(order, 'gt_fee');
4695
- if (gtFee) {
4716
+ if (gtFee !== undefined) {
4696
4717
  fees.push({
4697
4718
  'currency': 'GT',
4698
4719
  'cost': gtFee,
4699
4720
  });
4700
4721
  }
4701
4722
  const fee = this.safeString(order, 'fee');
4702
- if (fee) {
4723
+ if (fee !== undefined) {
4703
4724
  fees.push({
4704
4725
  'currency': this.safeCurrencyCode(this.safeString(order, 'fee_currency')),
4705
4726
  'cost': fee,
4706
4727
  });
4707
4728
  }
4708
4729
  const rebate = this.safeString(order, 'rebated_fee');
4709
- if (rebate) {
4730
+ if (rebate !== undefined) {
4710
4731
  fees.push({
4711
4732
  'currency': this.safeCurrencyCode(this.safeString(order, 'rebated_fee_currency')),
4712
4733
  'cost': Precise.stringNeg(rebate),
@@ -4790,9 +4811,11 @@ export default class gate extends Exchange {
4790
4811
  * @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
4791
4812
  * @param {string} [params.type] 'spot', 'swap', or 'future', if not provided this.options['defaultMarginMode'] is used
4792
4813
  * @param {string} [params.settle] 'btc' or 'usdt' - settle currency for perpetual swap and future - market settle currency is used if symbol !== undefined, default="usdt" for swap and "btc" for future
4814
+ * @param {bool} [params.unifiedAccount] set to true for fetching a unified account order
4793
4815
  * @returns An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4794
4816
  */
4795
4817
  await this.loadMarkets();
4818
+ await this.loadUnifiedStatus();
4796
4819
  const market = (symbol === undefined) ? undefined : this.market(symbol);
4797
4820
  const result = this.handleMarketTypeAndParams('fetchOrder', market, params);
4798
4821
  const type = this.safeString(result, 0);
@@ -4845,6 +4868,7 @@ export default class gate extends Exchange {
4845
4868
  * @param {bool} [params.stop] true for fetching stop orders
4846
4869
  * @param {string} [params.type] spot, margin, swap or future, if not provided this.options['defaultType'] is used
4847
4870
  * @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for type='margin', if not provided this.options['defaultMarginMode'] is used
4871
+ * @param {bool} [params.unifiedAccount] set to true for fetching unified account orders
4848
4872
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
4849
4873
  */
4850
4874
  return await this.fetchOrdersByStatus('open', symbol, since, limit, params);
@@ -4870,9 +4894,11 @@ export default class gate extends Exchange {
4870
4894
  * @param {string} [params.type] spot, swap or future, if not provided this.options['defaultType'] is used
4871
4895
  * @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
4872
4896
  * @param {boolean} [params.historical] *swap only* true for using historical endpoint
4897
+ * @param {bool} [params.unifiedAccount] set to true for fetching unified account orders
4873
4898
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
4874
4899
  */
4875
4900
  await this.loadMarkets();
4901
+ await this.loadUnifiedStatus();
4876
4902
  const until = this.safeInteger(params, 'until');
4877
4903
  let market = undefined;
4878
4904
  if (symbol !== undefined) {
@@ -4908,13 +4934,16 @@ export default class gate extends Exchange {
4908
4934
  market = this.market(symbol);
4909
4935
  symbol = market['symbol'];
4910
4936
  }
4911
- const stop = this.safeBool2(params, 'stop', 'trigger');
4912
- params = this.omit(params, ['stop', 'trigger']);
4937
+ let trigger = undefined;
4938
+ [trigger, params] = this.handleParamBool2(params, 'trigger', 'stop');
4913
4939
  let type = undefined;
4914
4940
  [type, params] = this.handleMarketTypeAndParams('fetchOrdersByStatus', market, params);
4915
4941
  const spot = (type === 'spot') || (type === 'margin');
4916
4942
  let request = {};
4917
- [request, params] = spot ? this.multiOrderSpotPrepareRequest(market, stop, params) : this.prepareRequest(market, type, params);
4943
+ [request, params] = spot ? this.multiOrderSpotPrepareRequest(market, trigger, params) : this.prepareRequest(market, type, params);
4944
+ if (spot && trigger) {
4945
+ request = this.omit(request, 'account');
4946
+ }
4918
4947
  if (status === 'closed') {
4919
4948
  status = 'finished';
4920
4949
  }
@@ -4940,33 +4969,36 @@ export default class gate extends Exchange {
4940
4969
  }
4941
4970
  async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
4942
4971
  await this.loadMarkets();
4972
+ await this.loadUnifiedStatus();
4943
4973
  let market = undefined;
4944
4974
  if (symbol !== undefined) {
4945
4975
  market = this.market(symbol);
4946
4976
  symbol = market['symbol'];
4947
4977
  }
4948
- const stop = this.safeBool2(params, 'stop', 'trigger');
4949
- params = this.omit(params, ['trigger', 'stop']);
4978
+ // don't omit here, omits done in prepareOrdersByStatusRequest
4979
+ const trigger = this.safeBool2(params, 'trigger', 'stop');
4950
4980
  const res = this.handleMarketTypeAndParams('fetchOrdersByStatus', market, params);
4951
4981
  const type = this.safeString(res, 0);
4952
- params['type'] = type;
4953
4982
  const [request, requestParams] = this.prepareOrdersByStatusRequest(status, symbol, since, limit, params);
4954
4983
  const spot = (type === 'spot') || (type === 'margin');
4955
- const openSpotOrders = spot && (status === 'open') && !stop;
4984
+ const openStatus = (status === 'open');
4985
+ const openSpotOrders = spot && openStatus && !trigger;
4956
4986
  let response = undefined;
4957
- if (type === 'spot' || type === 'margin') {
4958
- if (openSpotOrders) {
4959
- response = await this.privateSpotGetOpenOrders(this.extend(request, requestParams));
4960
- }
4961
- else if (stop) {
4962
- response = await this.privateSpotGetPriceOrders(this.extend(request, requestParams));
4987
+ if (spot) {
4988
+ if (!trigger) {
4989
+ if (openStatus) {
4990
+ response = await this.privateSpotGetOpenOrders(this.extend(request, requestParams));
4991
+ }
4992
+ else {
4993
+ response = await this.privateSpotGetOrders(this.extend(request, requestParams));
4994
+ }
4963
4995
  }
4964
4996
  else {
4965
- response = await this.privateSpotGetOrders(this.extend(request, requestParams));
4997
+ response = await this.privateSpotGetPriceOrders(this.extend(request, requestParams));
4966
4998
  }
4967
4999
  }
4968
5000
  else if (type === 'swap') {
4969
- if (stop) {
5001
+ if (trigger) {
4970
5002
  response = await this.privateFuturesGetSettlePriceOrders(this.extend(request, requestParams));
4971
5003
  }
4972
5004
  else {
@@ -4974,7 +5006,7 @@ export default class gate extends Exchange {
4974
5006
  }
4975
5007
  }
4976
5008
  else if (type === 'future') {
4977
- if (stop) {
5009
+ if (trigger) {
4978
5010
  response = await this.privateDeliveryGetSettlePriceOrders(this.extend(request, requestParams));
4979
5011
  }
4980
5012
  else {
@@ -5157,9 +5189,11 @@ export default class gate extends Exchange {
5157
5189
  * @param {string} symbol Unified market symbol
5158
5190
  * @param {object} [params] Parameters specified by the exchange api
5159
5191
  * @param {bool} [params.stop] True if the order to be cancelled is a trigger order
5192
+ * @param {bool} [params.unifiedAccount] set to true for canceling unified account orders
5160
5193
  * @returns An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
5161
5194
  */
5162
5195
  await this.loadMarkets();
5196
+ await this.loadUnifiedStatus();
5163
5197
  const market = (symbol === undefined) ? undefined : this.market(symbol);
5164
5198
  const stop = this.safeBoolN(params, ['is_stop_order', 'stop', 'trigger'], false);
5165
5199
  params = this.omit(params, ['is_stop_order', 'stop', 'trigger']);
@@ -5290,9 +5324,11 @@ export default class gate extends Exchange {
5290
5324
  * @param {string[]} ids order ids
5291
5325
  * @param {string} symbol unified symbol of the market the order was made in
5292
5326
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5327
+ * @param {bool} [params.unifiedAccount] set to true for canceling unified account orders
5293
5328
  * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5294
5329
  */
5295
5330
  await this.loadMarkets();
5331
+ await this.loadUnifiedStatus();
5296
5332
  let market = undefined;
5297
5333
  if (symbol !== undefined) {
5298
5334
  market = this.market(symbol);
@@ -5336,9 +5372,11 @@ export default class gate extends Exchange {
5336
5372
  * @param {CancellationRequest[]} orders list of order ids with symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
5337
5373
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5338
5374
  * @param {string[]} [params.clientOrderIds] client order ids
5375
+ * @param {bool} [params.unifiedAccount] set to true for canceling unified account orders
5339
5376
  * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5340
5377
  */
5341
5378
  await this.loadMarkets();
5379
+ await this.loadUnifiedStatus();
5342
5380
  const ordersRequests = [];
5343
5381
  for (let i = 0; i < orders.length; i++) {
5344
5382
  const order = orders[i];
@@ -5376,9 +5414,11 @@ export default class gate extends Exchange {
5376
5414
  * @see https://www.gate.io/docs/developers/apiv4/en/#cancel-all-open-orders-matched-3
5377
5415
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
5378
5416
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5417
+ * @param {bool} [params.unifiedAccount] set to true for canceling unified account orders
5379
5418
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
5380
5419
  */
5381
5420
  await this.loadMarkets();
5421
+ await this.loadUnifiedStatus();
5382
5422
  const market = (symbol === undefined) ? undefined : this.market(symbol);
5383
5423
  const stop = this.safeBool2(params, 'stop', 'trigger');
5384
5424
  params = this.omit(params, ['stop', 'trigger']);
@@ -6196,38 +6236,50 @@ export default class gate extends Exchange {
6196
6236
  * @name gate#repayCrossMargin
6197
6237
  * @description repay cross margin borrowed margin and interest
6198
6238
  * @see https://www.gate.io/docs/developers/apiv4/en/#cross-margin-repayments
6239
+ * @see https://www.gate.io/docs/developers/apiv4/en/#borrow-or-repay
6199
6240
  * @param {string} code unified currency code of the currency to repay
6200
6241
  * @param {float} amount the amount to repay
6201
6242
  * @param {string} symbol unified market symbol, required for isolated margin
6202
6243
  * @param {object} [params] extra parameters specific to the exchange API endpoint
6203
6244
  * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
6204
6245
  * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
6246
+ * @param {boolean} [params.unifiedAccount] set to true for repaying in the unified account
6205
6247
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6206
6248
  */
6207
6249
  await this.loadMarkets();
6250
+ await this.loadUnifiedStatus();
6208
6251
  const currency = this.currency(code);
6209
6252
  const request = {
6210
6253
  'currency': currency['id'].toUpperCase(),
6211
6254
  'amount': this.currencyToPrecision(code, amount),
6212
6255
  };
6213
- let response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
6214
- //
6215
- // [
6216
- // {
6217
- // "id": "17",
6218
- // "create_time": 1620381696159,
6219
- // "update_time": 1620381696159,
6220
- // "currency": "EOS",
6221
- // "amount": "110.553635",
6222
- // "text": "web",
6223
- // "status": 2,
6224
- // "repaid": "110.506649705159",
6225
- // "repaid_interest": "0.046985294841",
6226
- // "unpaid_interest": "0.0000074393366667"
6227
- // }
6228
- // ]
6229
- //
6230
- response = this.safeValue(response, 0);
6256
+ let isUnifiedAccount = false;
6257
+ [isUnifiedAccount, params] = this.handleOptionAndParams(params, 'repayCrossMargin', 'unifiedAccount');
6258
+ let response = undefined;
6259
+ if (isUnifiedAccount) {
6260
+ request['type'] = 'repay';
6261
+ response = await this.privateUnifiedPostLoans(this.extend(request, params));
6262
+ }
6263
+ else {
6264
+ response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
6265
+ response = this.safeDict(response, 0);
6266
+ //
6267
+ // [
6268
+ // {
6269
+ // "id": "17",
6270
+ // "create_time": 1620381696159,
6271
+ // "update_time": 1620381696159,
6272
+ // "currency": "EOS",
6273
+ // "amount": "110.553635",
6274
+ // "text": "web",
6275
+ // "status": 2,
6276
+ // "repaid": "110.506649705159",
6277
+ // "repaid_interest": "0.046985294841",
6278
+ // "unpaid_interest": "0.0000074393366667"
6279
+ // }
6280
+ // ]
6281
+ //
6282
+ }
6231
6283
  return this.parseMarginLoan(response, currency);
6232
6284
  }
6233
6285
  async borrowIsolatedMargin(symbol, code, amount, params = {}) {
@@ -6281,34 +6333,46 @@ export default class gate extends Exchange {
6281
6333
  * @name gate#borrowMargin
6282
6334
  * @description create a loan to borrow margin
6283
6335
  * @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
6336
+ * @see https://www.gate.io/docs/developers/apiv4/en/#borrow-or-repay
6284
6337
  * @param {string} code unified currency code of the currency to borrow
6285
6338
  * @param {float} amount the amount to borrow
6286
6339
  * @param {string} symbol unified market symbol, required for isolated margin
6287
6340
  * @param {object} [params] extra parameters specific to the exchange API endpoint
6288
6341
  * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
6342
+ * @param {boolean} [params.unifiedAccount] set to true for borrowing in the unified account
6289
6343
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6290
6344
  */
6291
6345
  await this.loadMarkets();
6346
+ await this.loadUnifiedStatus();
6292
6347
  const currency = this.currency(code);
6293
6348
  const request = {
6294
6349
  'currency': currency['id'].toUpperCase(),
6295
6350
  'amount': this.currencyToPrecision(code, amount),
6296
6351
  };
6297
- const response = await this.privateMarginPostCrossLoans(this.extend(request, params));
6298
- //
6299
- // {
6300
- // "id": "17",
6301
- // "create_time": 1620381696159,
6302
- // "update_time": 1620381696159,
6303
- // "currency": "EOS",
6304
- // "amount": "110.553635",
6305
- // "text": "web",
6306
- // "status": 2,
6307
- // "repaid": "110.506649705159",
6308
- // "repaid_interest": "0.046985294841",
6309
- // "unpaid_interest": "0.0000074393366667"
6310
- // }
6311
- //
6352
+ let isUnifiedAccount = false;
6353
+ [isUnifiedAccount, params] = this.handleOptionAndParams(params, 'borrowCrossMargin', 'unifiedAccount');
6354
+ let response = undefined;
6355
+ if (isUnifiedAccount) {
6356
+ request['type'] = 'borrow';
6357
+ response = await this.privateUnifiedPostLoans(this.extend(request, params));
6358
+ }
6359
+ else {
6360
+ response = await this.privateMarginPostCrossLoans(this.extend(request, params));
6361
+ //
6362
+ // {
6363
+ // "id": "17",
6364
+ // "create_time": 1620381696159,
6365
+ // "update_time": 1620381696159,
6366
+ // "currency": "EOS",
6367
+ // "amount": "110.553635",
6368
+ // "text": "web",
6369
+ // "status": 2,
6370
+ // "repaid": "110.506649705159",
6371
+ // "repaid_interest": "0.046985294841",
6372
+ // "unpaid_interest": "0.0000074393366667"
6373
+ // }
6374
+ //
6375
+ }
6312
6376
  return this.parseMarginLoan(response, currency);
6313
6377
  }
6314
6378
  parseMarginLoan(info, currency = undefined) {
@@ -6365,6 +6429,78 @@ export default class gate extends Exchange {
6365
6429
  'info': info,
6366
6430
  };
6367
6431
  }
6432
+ async fetchBorrowInterest(code = undefined, symbol = undefined, since = undefined, limit = undefined, params = {}) {
6433
+ /**
6434
+ * @method
6435
+ * @name gate#fetchBorrowInterest
6436
+ * @description fetch the interest owed by the user for borrowing currency for margin trading
6437
+ * @see https://www.gate.io/docs/developers/apiv4/en/#list-interest-records
6438
+ * @see https://www.gate.io/docs/developers/apiv4/en/#interest-records-for-the-cross-margin-account
6439
+ * @see https://www.gate.io/docs/developers/apiv4/en/#list-interest-records-2
6440
+ * @param {string} [code] unified currency code
6441
+ * @param {string} [symbol] unified market symbol when fetching interest in isolated markets
6442
+ * @param {int} [since] the earliest time in ms to fetch borrow interest for
6443
+ * @param {int} [limit] the maximum number of structures to retrieve
6444
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
6445
+ * @param {boolean} [params.unifiedAccount] set to true for fetching borrow interest in the unified account
6446
+ * @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/#/?id=borrow-interest-structure}
6447
+ */
6448
+ await this.loadMarkets();
6449
+ await this.loadUnifiedStatus();
6450
+ let isUnifiedAccount = false;
6451
+ [isUnifiedAccount, params] = this.handleOptionAndParams(params, 'fetchBorrowInterest', 'unifiedAccount');
6452
+ let request = {};
6453
+ [request, params] = this.handleUntilOption('to', request, params);
6454
+ let currency = undefined;
6455
+ if (code !== undefined) {
6456
+ currency = this.currency(code);
6457
+ request['currency'] = currency['id'];
6458
+ }
6459
+ let market = undefined;
6460
+ if (symbol !== undefined) {
6461
+ market = this.market(symbol);
6462
+ }
6463
+ if (since !== undefined) {
6464
+ request['from'] = since;
6465
+ }
6466
+ if (limit !== undefined) {
6467
+ request['limit'] = limit;
6468
+ }
6469
+ let response = undefined;
6470
+ let marginMode = undefined;
6471
+ [marginMode, params] = this.handleMarginModeAndParams('fetchBorrowInterest', params, 'cross');
6472
+ if (isUnifiedAccount) {
6473
+ response = await this.privateUnifiedGetInterestRecords(this.extend(request, params));
6474
+ }
6475
+ else if (marginMode === 'isolated') {
6476
+ if (market !== undefined) {
6477
+ request['currency_pair'] = market['id'];
6478
+ }
6479
+ response = await this.privateMarginGetUniInterestRecords(this.extend(request, params));
6480
+ }
6481
+ else if (marginMode === 'cross') {
6482
+ response = await this.privateMarginGetCrossInterestRecords(this.extend(request, params));
6483
+ }
6484
+ const interest = this.parseBorrowInterests(response, market);
6485
+ return this.filterByCurrencySinceLimit(interest, code, since, limit);
6486
+ }
6487
+ parseBorrowInterest(info, market = undefined) {
6488
+ const marketId = this.safeString(info, 'currency_pair');
6489
+ market = this.safeMarket(marketId, market);
6490
+ const marginMode = (marketId !== undefined) ? 'isolated' : 'cross';
6491
+ const timestamp = this.safeInteger(info, 'create_time');
6492
+ return {
6493
+ 'info': info,
6494
+ 'timestamp': timestamp,
6495
+ 'datetime': this.iso8601(timestamp),
6496
+ 'symbol': this.safeString(market, 'symbol'),
6497
+ 'currency': this.safeCurrencyCode(this.safeString(info, 'currency')),
6498
+ 'marginMode': marginMode,
6499
+ 'interest': this.safeNumber(info, 'interest'),
6500
+ 'interestRate': this.safeNumber(info, 'actual_rate'),
6501
+ 'amountBorrowed': undefined,
6502
+ };
6503
+ }
6368
6504
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
6369
6505
  const authentication = api[0]; // public, private
6370
6506
  const type = api[1]; // spot, margin, future, delivery
@@ -2257,7 +2257,7 @@ export default class hyperliquid extends Exchange {
2257
2257
  'notional': this.safeNumber(entry, 'positionValue'),
2258
2258
  'leverage': this.safeNumber(leverage, 'value'),
2259
2259
  'collateral': this.safeNumber(entry, 'marginUsed'),
2260
- 'initialMargin': initialMargin,
2260
+ 'initialMargin': this.parseNumber(initialMargin),
2261
2261
  'maintenanceMargin': undefined,
2262
2262
  'initialMarginPercentage': undefined,
2263
2263
  'maintenanceMarginPercentage': undefined,
package/js/src/kucoin.js CHANGED
@@ -206,6 +206,7 @@ export default class kucoin extends Exchange {
206
206
  'market/orderbook/level{level}': 3,
207
207
  'market/orderbook/level2': 3,
208
208
  'market/orderbook/level3': 3,
209
+ 'hf/accounts/opened': 2,
209
210
  'hf/orders/active': 2,
210
211
  'hf/orders/active/symbols': 2,
211
212
  'hf/margin/order/active/symbols': 2,
@@ -635,7 +636,7 @@ export default class kucoin extends Exchange {
635
636
  'FUD': 'FTX Users\' Debt',
636
637
  },
637
638
  'options': {
638
- 'hf': false,
639
+ 'hf': undefined,
639
640
  'version': 'v1',
640
641
  'symbolSeparator': '-',
641
642
  'fetchMyTradesMethod': 'private_get_fills',
@@ -1073,7 +1074,8 @@ export default class kucoin extends Exchange {
1073
1074
  // "enableTrading": true
1074
1075
  // },
1075
1076
  //
1076
- const requestMarginables = this.checkRequiredCredentials(false);
1077
+ const credentialsSet = this.checkRequiredCredentials(false);
1078
+ const requestMarginables = credentialsSet && this.safeBool(params, 'marginables', true);
1077
1079
  if (requestMarginables) {
1078
1080
  promises.push(this.privateGetMarginSymbols(params)); // cross margin symbols
1079
1081
  //
@@ -1138,6 +1140,10 @@ export default class kucoin extends Exchange {
1138
1140
  // }
1139
1141
  //
1140
1142
  }
1143
+ if (credentialsSet) {
1144
+ // load migration status for account
1145
+ promises.push(this.loadMigrationStatus());
1146
+ }
1141
1147
  const responses = await Promise.all(promises);
1142
1148
  const symbolsData = this.safeList(responses[0], 'data');
1143
1149
  const crossData = requestMarginables ? this.safeDict(responses[1], 'data', {}) : {};
@@ -1225,15 +1231,19 @@ export default class kucoin extends Exchange {
1225
1231
  return result;
1226
1232
  }
1227
1233
  async loadMigrationStatus(force = false) {
1228
- if (!('hfMigrated' in this.options) || (this.options['hfMigrated'] === undefined) || force) {
1229
- const result = await this.privateGetMigrateUserAccountStatus();
1230
- const data = this.safeDict(result, 'data', {});
1231
- const status = this.safeInteger(data, 'status');
1232
- this.options['hfMigrated'] = (status === 2);
1234
+ /**
1235
+ * @method
1236
+ * @name kucoin#loadMigrationStatus
1237
+ * @description loads the migration status for the account (hf or not)
1238
+ * @see https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/get-user-type
1239
+ */
1240
+ if (!('hf' in this.options) || (this.options['hf'] === undefined) || force) {
1241
+ const result = await this.privateGetHfAccountsOpened();
1242
+ this.options['hf'] = this.safeBool(result, 'data');
1233
1243
  }
1234
1244
  }
1235
1245
  handleHfAndParams(params = {}) {
1236
- const migrated = this.safeBool2(this.options, 'hfMigrated', 'hf', false);
1246
+ const migrated = this.safeBool(this.options, 'hf', false);
1237
1247
  let loadedHf = undefined;
1238
1248
  if (migrated !== undefined) {
1239
1249
  if (migrated) {
@@ -1180,7 +1180,8 @@ export default class kucoin extends kucoinRest {
1180
1180
  }
1181
1181
  const data = this.safeDict(message, 'data');
1182
1182
  const parsed = this.parseWsTrade(data);
1183
- this.myTrades.append(parsed);
1183
+ const myTrades = this.myTrades;
1184
+ myTrades.append(parsed);
1184
1185
  const messageHash = 'myTrades';
1185
1186
  client.resolve(this.myTrades, messageHash);
1186
1187
  const symbolSpecificMessageHash = messageHash + ':' + parsed['symbol'];
@@ -1001,7 +1001,8 @@ export default class onetrading extends onetradingRest {
1001
1001
  if (updateType === 'TRADE_SETTLED') {
1002
1002
  const parsed = this.parseTrade(update);
1003
1003
  symbol = this.safeString(parsed, 'symbol', '');
1004
- this.myTrades.append(parsed);
1004
+ const myTrades = this.myTrades;
1005
+ myTrades.append(parsed);
1005
1006
  client.resolve(this.myTrades, 'myTrades:' + symbol);
1006
1007
  client.resolve(this.myTrades, 'myTrades');
1007
1008
  }
package/js/src/yobit.js CHANGED
@@ -1176,7 +1176,7 @@ export default class yobit extends Exchange {
1176
1176
  const ids = Object.keys(trades);
1177
1177
  const result = [];
1178
1178
  for (let i = 0; i < ids.length; i++) {
1179
- const id = ids[i];
1179
+ const id = this.safeString(ids, i);
1180
1180
  const trade = this.parseTrade(this.extend(trades[id], {
1181
1181
  'trade_id': id,
1182
1182
  }), market);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.4.23",
3
+ "version": "4.4.24",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.min.js",
6
6
  "type": "module",