ccxt 4.1.66 → 4.1.68

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
@@ -556,8 +556,6 @@ export default class gate extends Exchange {
556
556
  'AXIS': 'Axis DeFi',
557
557
  'BIFI': 'Bitcoin File',
558
558
  'BOX': 'DefiBox',
559
- 'BTCBEAR': 'BEAR',
560
- 'BTCBULL': 'BULL',
561
559
  'BYN': 'BeyondFi',
562
560
  'EGG': 'Goose Finance',
563
561
  'GTC': 'Game.com',
@@ -853,6 +851,7 @@ export default class gate extends Exchange {
853
851
  'AUTO_TRIGGER_PRICE_LESS_LAST': InvalidOrder,
854
852
  'AUTO_TRIGGER_PRICE_GREATE_LAST': InvalidOrder,
855
853
  'POSITION_HOLDING': BadRequest,
854
+ 'USER_LOAN_EXCEEDED': BadRequest, // {"label":"USER_LOAN_EXCEEDED","message":"Max loan amount per user would be exceeded"}
856
855
  },
857
856
  'broad': {},
858
857
  },
@@ -5572,6 +5571,216 @@ export default class gate extends Exchange {
5572
5571
  }
5573
5572
  return tiers;
5574
5573
  }
5574
+ async repayMargin(code, amount, symbol = undefined, params = {}) {
5575
+ /**
5576
+ * @method
5577
+ * @name gate#repayMargin
5578
+ * @description repay borrowed margin and interest
5579
+ * @see https://www.gate.io/docs/apiv4/en/#repay-cross-margin-loan
5580
+ * @see https://www.gate.io/docs/apiv4/en/#repay-a-loan
5581
+ * @param {string} code unified currency code of the currency to repay
5582
+ * @param {float} amount the amount to repay
5583
+ * @param {string} symbol unified market symbol, required for isolated margin
5584
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5585
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
5586
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
5587
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5588
+ */
5589
+ let marginMode = undefined;
5590
+ [marginMode, params] = this.handleOptionAndParams(params, 'repayMargin', 'marginMode');
5591
+ this.checkRequiredArgument('repayMargin', marginMode, 'marginMode', ['cross', 'isolated']);
5592
+ this.checkRequiredMarginArgument('repayMargin', symbol, marginMode);
5593
+ await this.loadMarkets();
5594
+ const currency = this.currency(code);
5595
+ const request = {
5596
+ 'currency': currency['id'].toUpperCase(),
5597
+ 'amount': this.currencyToPrecision(code, amount),
5598
+ };
5599
+ let response = undefined;
5600
+ if ((marginMode === 'cross') && (symbol === undefined)) {
5601
+ response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
5602
+ }
5603
+ else if ((marginMode === 'isolated') || (symbol !== undefined)) {
5604
+ if (symbol === undefined) {
5605
+ throw new BadRequest(this.id + ' repayMargin() requires a symbol argument for isolated margin');
5606
+ }
5607
+ const market = this.market(symbol);
5608
+ request['currency_pair'] = market['id'];
5609
+ request['type'] = 'repay';
5610
+ response = await this.privateMarginPostUniLoans(this.extend(request, params));
5611
+ }
5612
+ //
5613
+ // Cross
5614
+ //
5615
+ // [
5616
+ // {
5617
+ // "id": "17",
5618
+ // "create_time": 1620381696159,
5619
+ // "update_time": 1620381696159,
5620
+ // "currency": "EOS",
5621
+ // "amount": "110.553635",
5622
+ // "text": "web",
5623
+ // "status": 2,
5624
+ // "repaid": "110.506649705159",
5625
+ // "repaid_interest": "0.046985294841",
5626
+ // "unpaid_interest": "0.0000074393366667"
5627
+ // }
5628
+ // ]
5629
+ //
5630
+ // Isolated
5631
+ //
5632
+ // {
5633
+ // "id": "34267567",
5634
+ // "create_time": "1656394778",
5635
+ // "expire_time": "1657258778",
5636
+ // "status": "finished",
5637
+ // "side": "borrow",
5638
+ // "currency": "USDT",
5639
+ // "rate": "0.0002",
5640
+ // "amount": "100",
5641
+ // "days": 10,
5642
+ // "auto_renew": false,
5643
+ // "currency_pair": "LTC_USDT",
5644
+ // "left": "0",
5645
+ // "repaid": "100",
5646
+ // "paid_interest": "0.003333333333",
5647
+ // "unpaid_interest": "0"
5648
+ // }
5649
+ //
5650
+ if (marginMode === 'cross') {
5651
+ response = response[0];
5652
+ }
5653
+ return this.parseMarginLoan(response, currency);
5654
+ }
5655
+ async borrowMargin(code, amount, symbol = undefined, params = {}) {
5656
+ /**
5657
+ * @method
5658
+ * @name gate#borrowMargin
5659
+ * @description create a loan to borrow margin
5660
+ * @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
5661
+ * @see https://www.gate.io/docs/developers/apiv4/en/#marginuni
5662
+ * @param {string} code unified currency code of the currency to borrow
5663
+ * @param {float} amount the amount to borrow
5664
+ * @param {string} symbol unified market symbol, required for isolated margin
5665
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5666
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
5667
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5668
+ */
5669
+ let marginMode = undefined;
5670
+ [marginMode, params] = this.handleOptionAndParams(params, 'borrowMargin', 'marginMode');
5671
+ this.checkRequiredArgument('borrowMargin', marginMode, 'marginMode', ['cross', 'isolated']);
5672
+ this.checkRequiredMarginArgument('borrowMargin', symbol, marginMode);
5673
+ await this.loadMarkets();
5674
+ const currency = this.currency(code);
5675
+ const request = {
5676
+ 'currency': currency['id'].toUpperCase(),
5677
+ 'amount': this.currencyToPrecision(code, amount),
5678
+ };
5679
+ let response = undefined;
5680
+ if ((marginMode === 'cross') && (symbol === undefined)) {
5681
+ response = await this.privateMarginPostCrossLoans(this.extend(request, params));
5682
+ }
5683
+ else if ((marginMode === 'isolated') || (symbol !== undefined)) {
5684
+ if (symbol === undefined) {
5685
+ throw new BadRequest(this.id + ' borrowMargin() requires a symbol argument for isolated margin');
5686
+ }
5687
+ const market = this.market(symbol);
5688
+ request['currency_pair'] = market['id'];
5689
+ request['type'] = 'borrow';
5690
+ response = await this.privateMarginPostUniLoans(this.extend(request, params));
5691
+ }
5692
+ //
5693
+ // Cross
5694
+ //
5695
+ // {
5696
+ // "id": "17",
5697
+ // "create_time": 1620381696159,
5698
+ // "update_time": 1620381696159,
5699
+ // "currency": "EOS",
5700
+ // "amount": "110.553635",
5701
+ // "text": "web",
5702
+ // "status": 2,
5703
+ // "repaid": "110.506649705159",
5704
+ // "repaid_interest": "0.046985294841",
5705
+ // "unpaid_interest": "0.0000074393366667"
5706
+ // }
5707
+ //
5708
+ // Isolated
5709
+ //
5710
+ // {
5711
+ // "id": "34267567",
5712
+ // "create_time": "1656394778",
5713
+ // "expire_time": "1657258778",
5714
+ // "status": "loaned",
5715
+ // "side": "borrow",
5716
+ // "currency": "USDT",
5717
+ // "rate": "0.0002",
5718
+ // "amount": "100",
5719
+ // "days": 10,
5720
+ // "auto_renew": false,
5721
+ // "currency_pair": "LTC_USDT",
5722
+ // "left": "0",
5723
+ // "repaid": "0",
5724
+ // "paid_interest": "0",
5725
+ // "unpaid_interest": "0.003333333333"
5726
+ // }
5727
+ //
5728
+ return this.parseMarginLoan(response, currency);
5729
+ }
5730
+ parseMarginLoan(info, currency = undefined) {
5731
+ //
5732
+ // Cross
5733
+ //
5734
+ // {
5735
+ // "id": "17",
5736
+ // "create_time": 1620381696159,
5737
+ // "update_time": 1620381696159,
5738
+ // "currency": "EOS",
5739
+ // "amount": "110.553635",
5740
+ // "text": "web",
5741
+ // "status": 2,
5742
+ // "repaid": "110.506649705159",
5743
+ // "repaid_interest": "0.046985294841",
5744
+ // "unpaid_interest": "0.0000074393366667"
5745
+ // }
5746
+ //
5747
+ // Isolated
5748
+ //
5749
+ // {
5750
+ // "id": "34267567",
5751
+ // "create_time": "1656394778",
5752
+ // "expire_time": "1657258778",
5753
+ // "status": "loaned",
5754
+ // "side": "borrow",
5755
+ // "currency": "USDT",
5756
+ // "rate": "0.0002",
5757
+ // "amount": "100",
5758
+ // "days": 10,
5759
+ // "auto_renew": false,
5760
+ // "currency_pair": "LTC_USDT",
5761
+ // "left": "0",
5762
+ // "repaid": "0",
5763
+ // "paid_interest": "0",
5764
+ // "unpaid_interest": "0.003333333333"
5765
+ // }
5766
+ //
5767
+ const marginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
5768
+ let timestamp = this.safeInteger(info, 'create_time');
5769
+ if (marginMode === 'isolated') {
5770
+ timestamp = this.safeTimestamp(info, 'create_time');
5771
+ }
5772
+ const currencyId = this.safeString(info, 'currency');
5773
+ const marketId = this.safeString(info, 'currency_pair');
5774
+ return {
5775
+ 'id': this.safeInteger(info, 'id'),
5776
+ 'currency': this.safeCurrencyCode(currencyId, currency),
5777
+ 'amount': this.safeNumber(info, 'amount'),
5778
+ 'symbol': this.safeSymbol(marketId, undefined, '_', 'margin'),
5779
+ 'timestamp': timestamp,
5780
+ 'datetime': this.iso8601(timestamp),
5781
+ 'info': info,
5782
+ };
5783
+ }
5575
5784
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
5576
5785
  const authentication = api[0]; // public, private
5577
5786
  const type = api[1]; // spot, margin, future, delivery
@@ -740,7 +740,7 @@ export default class binance extends binanceRest {
740
740
  handleTrade(client, message) {
741
741
  // the trade streams push raw trade information in real-time
742
742
  // each trade has a unique buyer and seller
743
- const isSpot = ((client.url.indexOf('/stream') > -1) || (client.url.indexOf('/testnet.binance') > -1));
743
+ const isSpot = ((client.url.indexOf('wss://stream.binance.com') > -1) || (client.url.indexOf('/testnet.binance') > -1));
744
744
  const marketType = (isSpot) ? 'spot' : 'contract';
745
745
  const marketId = this.safeString(message, 's');
746
746
  const market = this.safeMarket(marketId, undefined, undefined, marketType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.1.66",
3
+ "version": "4.1.68",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 130+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",