ccxt 4.1.67 → 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/dist/cjs/ccxt.js CHANGED
@@ -173,7 +173,7 @@ var woo$1 = require('./src/pro/woo.js');
173
173
 
174
174
  //-----------------------------------------------------------------------------
175
175
  // this is updated by vss.js when building
176
- const version = '4.1.67';
176
+ const version = '4.1.68';
177
177
  Exchange["default"].ccxtVersion = version;
178
178
  const exchanges = {
179
179
  'ace': ace,
@@ -2517,7 +2517,7 @@ class Exchange {
2517
2517
  'bidVolume': this.safeNumber(ticker, 'bidVolume'),
2518
2518
  'ask': this.parseNumber(this.omitZero(this.safeNumber(ticker, 'ask'))),
2519
2519
  'askVolume': this.safeNumber(ticker, 'askVolume'),
2520
- 'high': this.parseNumber(this.omitZero(this.safeString(ticker, 'high"'))),
2520
+ 'high': this.parseNumber(this.omitZero(this.safeString(ticker, 'high'))),
2521
2521
  'low': this.parseNumber(this.omitZero(this.safeNumber(ticker, 'low'))),
2522
2522
  'open': this.parseNumber(this.omitZero(this.parseNumber(open))),
2523
2523
  'close': this.parseNumber(this.omitZero(this.parseNumber(close))),
@@ -3186,7 +3186,7 @@ class Exchange {
3186
3186
  throw new errors.NotSupported(this.id + ' watchPositions() is not supported yet');
3187
3187
  }
3188
3188
  async watchPositionForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
3189
- return this.watchPositions(symbols, since, limit, params);
3189
+ return await this.watchPositions(symbols, since, limit, params);
3190
3190
  }
3191
3191
  async fetchPositionsForSymbol(symbol, params = {}) {
3192
3192
  /**
@@ -2115,8 +2115,8 @@ class bybit extends bybit$1 {
2115
2115
  }
2116
2116
  const request = {
2117
2117
  // 'symbol': market['id'],
2118
- // 'baseCoin': '', Base coin. For option only
2119
- // 'expDate': '', Expiry date. e.g., 25DEC22. For option only
2118
+ // 'baseCoin': '', // Base coin. For option only
2119
+ // 'expDate': '', // Expiry date. e.g., 25DEC22. For option only
2120
2120
  };
2121
2121
  let type = undefined;
2122
2122
  [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
@@ -553,8 +553,6 @@ class gate extends gate$1 {
553
553
  'AXIS': 'Axis DeFi',
554
554
  'BIFI': 'Bitcoin File',
555
555
  'BOX': 'DefiBox',
556
- 'BTCBEAR': 'BEAR',
557
- 'BTCBULL': 'BULL',
558
556
  'BYN': 'BeyondFi',
559
557
  'EGG': 'Goose Finance',
560
558
  'GTC': 'Game.com',
@@ -850,6 +848,7 @@ class gate extends gate$1 {
850
848
  'AUTO_TRIGGER_PRICE_LESS_LAST': errors.InvalidOrder,
851
849
  'AUTO_TRIGGER_PRICE_GREATE_LAST': errors.InvalidOrder,
852
850
  'POSITION_HOLDING': errors.BadRequest,
851
+ 'USER_LOAN_EXCEEDED': errors.BadRequest, // {"label":"USER_LOAN_EXCEEDED","message":"Max loan amount per user would be exceeded"}
853
852
  },
854
853
  'broad': {},
855
854
  },
@@ -5569,6 +5568,216 @@ class gate extends gate$1 {
5569
5568
  }
5570
5569
  return tiers;
5571
5570
  }
5571
+ async repayMargin(code, amount, symbol = undefined, params = {}) {
5572
+ /**
5573
+ * @method
5574
+ * @name gate#repayMargin
5575
+ * @description repay borrowed margin and interest
5576
+ * @see https://www.gate.io/docs/apiv4/en/#repay-cross-margin-loan
5577
+ * @see https://www.gate.io/docs/apiv4/en/#repay-a-loan
5578
+ * @param {string} code unified currency code of the currency to repay
5579
+ * @param {float} amount the amount to repay
5580
+ * @param {string} symbol unified market symbol, required for isolated margin
5581
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5582
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
5583
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
5584
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5585
+ */
5586
+ let marginMode = undefined;
5587
+ [marginMode, params] = this.handleOptionAndParams(params, 'repayMargin', 'marginMode');
5588
+ this.checkRequiredArgument('repayMargin', marginMode, 'marginMode', ['cross', 'isolated']);
5589
+ this.checkRequiredMarginArgument('repayMargin', symbol, marginMode);
5590
+ await this.loadMarkets();
5591
+ const currency = this.currency(code);
5592
+ const request = {
5593
+ 'currency': currency['id'].toUpperCase(),
5594
+ 'amount': this.currencyToPrecision(code, amount),
5595
+ };
5596
+ let response = undefined;
5597
+ if ((marginMode === 'cross') && (symbol === undefined)) {
5598
+ response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
5599
+ }
5600
+ else if ((marginMode === 'isolated') || (symbol !== undefined)) {
5601
+ if (symbol === undefined) {
5602
+ throw new errors.BadRequest(this.id + ' repayMargin() requires a symbol argument for isolated margin');
5603
+ }
5604
+ const market = this.market(symbol);
5605
+ request['currency_pair'] = market['id'];
5606
+ request['type'] = 'repay';
5607
+ response = await this.privateMarginPostUniLoans(this.extend(request, params));
5608
+ }
5609
+ //
5610
+ // Cross
5611
+ //
5612
+ // [
5613
+ // {
5614
+ // "id": "17",
5615
+ // "create_time": 1620381696159,
5616
+ // "update_time": 1620381696159,
5617
+ // "currency": "EOS",
5618
+ // "amount": "110.553635",
5619
+ // "text": "web",
5620
+ // "status": 2,
5621
+ // "repaid": "110.506649705159",
5622
+ // "repaid_interest": "0.046985294841",
5623
+ // "unpaid_interest": "0.0000074393366667"
5624
+ // }
5625
+ // ]
5626
+ //
5627
+ // Isolated
5628
+ //
5629
+ // {
5630
+ // "id": "34267567",
5631
+ // "create_time": "1656394778",
5632
+ // "expire_time": "1657258778",
5633
+ // "status": "finished",
5634
+ // "side": "borrow",
5635
+ // "currency": "USDT",
5636
+ // "rate": "0.0002",
5637
+ // "amount": "100",
5638
+ // "days": 10,
5639
+ // "auto_renew": false,
5640
+ // "currency_pair": "LTC_USDT",
5641
+ // "left": "0",
5642
+ // "repaid": "100",
5643
+ // "paid_interest": "0.003333333333",
5644
+ // "unpaid_interest": "0"
5645
+ // }
5646
+ //
5647
+ if (marginMode === 'cross') {
5648
+ response = response[0];
5649
+ }
5650
+ return this.parseMarginLoan(response, currency);
5651
+ }
5652
+ async borrowMargin(code, amount, symbol = undefined, params = {}) {
5653
+ /**
5654
+ * @method
5655
+ * @name gate#borrowMargin
5656
+ * @description create a loan to borrow margin
5657
+ * @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
5658
+ * @see https://www.gate.io/docs/developers/apiv4/en/#marginuni
5659
+ * @param {string} code unified currency code of the currency to borrow
5660
+ * @param {float} amount the amount to borrow
5661
+ * @param {string} symbol unified market symbol, required for isolated margin
5662
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5663
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
5664
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5665
+ */
5666
+ let marginMode = undefined;
5667
+ [marginMode, params] = this.handleOptionAndParams(params, 'borrowMargin', 'marginMode');
5668
+ this.checkRequiredArgument('borrowMargin', marginMode, 'marginMode', ['cross', 'isolated']);
5669
+ this.checkRequiredMarginArgument('borrowMargin', symbol, marginMode);
5670
+ await this.loadMarkets();
5671
+ const currency = this.currency(code);
5672
+ const request = {
5673
+ 'currency': currency['id'].toUpperCase(),
5674
+ 'amount': this.currencyToPrecision(code, amount),
5675
+ };
5676
+ let response = undefined;
5677
+ if ((marginMode === 'cross') && (symbol === undefined)) {
5678
+ response = await this.privateMarginPostCrossLoans(this.extend(request, params));
5679
+ }
5680
+ else if ((marginMode === 'isolated') || (symbol !== undefined)) {
5681
+ if (symbol === undefined) {
5682
+ throw new errors.BadRequest(this.id + ' borrowMargin() requires a symbol argument for isolated margin');
5683
+ }
5684
+ const market = this.market(symbol);
5685
+ request['currency_pair'] = market['id'];
5686
+ request['type'] = 'borrow';
5687
+ response = await this.privateMarginPostUniLoans(this.extend(request, params));
5688
+ }
5689
+ //
5690
+ // Cross
5691
+ //
5692
+ // {
5693
+ // "id": "17",
5694
+ // "create_time": 1620381696159,
5695
+ // "update_time": 1620381696159,
5696
+ // "currency": "EOS",
5697
+ // "amount": "110.553635",
5698
+ // "text": "web",
5699
+ // "status": 2,
5700
+ // "repaid": "110.506649705159",
5701
+ // "repaid_interest": "0.046985294841",
5702
+ // "unpaid_interest": "0.0000074393366667"
5703
+ // }
5704
+ //
5705
+ // Isolated
5706
+ //
5707
+ // {
5708
+ // "id": "34267567",
5709
+ // "create_time": "1656394778",
5710
+ // "expire_time": "1657258778",
5711
+ // "status": "loaned",
5712
+ // "side": "borrow",
5713
+ // "currency": "USDT",
5714
+ // "rate": "0.0002",
5715
+ // "amount": "100",
5716
+ // "days": 10,
5717
+ // "auto_renew": false,
5718
+ // "currency_pair": "LTC_USDT",
5719
+ // "left": "0",
5720
+ // "repaid": "0",
5721
+ // "paid_interest": "0",
5722
+ // "unpaid_interest": "0.003333333333"
5723
+ // }
5724
+ //
5725
+ return this.parseMarginLoan(response, currency);
5726
+ }
5727
+ parseMarginLoan(info, currency = undefined) {
5728
+ //
5729
+ // Cross
5730
+ //
5731
+ // {
5732
+ // "id": "17",
5733
+ // "create_time": 1620381696159,
5734
+ // "update_time": 1620381696159,
5735
+ // "currency": "EOS",
5736
+ // "amount": "110.553635",
5737
+ // "text": "web",
5738
+ // "status": 2,
5739
+ // "repaid": "110.506649705159",
5740
+ // "repaid_interest": "0.046985294841",
5741
+ // "unpaid_interest": "0.0000074393366667"
5742
+ // }
5743
+ //
5744
+ // Isolated
5745
+ //
5746
+ // {
5747
+ // "id": "34267567",
5748
+ // "create_time": "1656394778",
5749
+ // "expire_time": "1657258778",
5750
+ // "status": "loaned",
5751
+ // "side": "borrow",
5752
+ // "currency": "USDT",
5753
+ // "rate": "0.0002",
5754
+ // "amount": "100",
5755
+ // "days": 10,
5756
+ // "auto_renew": false,
5757
+ // "currency_pair": "LTC_USDT",
5758
+ // "left": "0",
5759
+ // "repaid": "0",
5760
+ // "paid_interest": "0",
5761
+ // "unpaid_interest": "0.003333333333"
5762
+ // }
5763
+ //
5764
+ const marginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
5765
+ let timestamp = this.safeInteger(info, 'create_time');
5766
+ if (marginMode === 'isolated') {
5767
+ timestamp = this.safeTimestamp(info, 'create_time');
5768
+ }
5769
+ const currencyId = this.safeString(info, 'currency');
5770
+ const marketId = this.safeString(info, 'currency_pair');
5771
+ return {
5772
+ 'id': this.safeInteger(info, 'id'),
5773
+ 'currency': this.safeCurrencyCode(currencyId, currency),
5774
+ 'amount': this.safeNumber(info, 'amount'),
5775
+ 'symbol': this.safeSymbol(marketId, undefined, '_', 'margin'),
5776
+ 'timestamp': timestamp,
5777
+ 'datetime': this.iso8601(timestamp),
5778
+ 'info': info,
5779
+ };
5780
+ }
5572
5781
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
5573
5782
  const authentication = api[0]; // public, private
5574
5783
  const type = api[1]; // spot, margin, future, delivery
@@ -737,7 +737,7 @@ class binance extends binance$1 {
737
737
  handleTrade(client, message) {
738
738
  // the trade streams push raw trade information in real-time
739
739
  // each trade has a unique buyer and seller
740
- const isSpot = ((client.url.indexOf('/stream') > -1) || (client.url.indexOf('/testnet.binance') > -1));
740
+ const isSpot = ((client.url.indexOf('wss://stream.binance.com') > -1) || (client.url.indexOf('/testnet.binance') > -1));
741
741
  const marketType = (isSpot) ? 'spot' : 'contract';
742
742
  const marketId = this.safeString(message, 's');
743
743
  const market = this.safeMarket(marketId, undefined, undefined, marketType);
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
7
- declare const version = "4.1.66";
7
+ declare const version = "4.1.67";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.1.67';
41
+ const version = '4.1.68';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -844,7 +844,7 @@ export default class Exchange {
844
844
  handleTimeInForce(params?: {}): string;
845
845
  convertTypeToAccount(account: any): any;
846
846
  checkRequiredArgument(methodName: any, argument: any, argumentName: any, options?: any[]): void;
847
- checkRequiredMarginArgument(methodName: string, symbol: string, marginMode: string): void;
847
+ checkRequiredMarginArgument(methodName: string, symbol: Str, marginMode: string): void;
848
848
  parseDepositWithdrawFees(response: any, codes?: string[], currencyIdKey?: any): any;
849
849
  parseDepositWithdrawFee(fee: any, currency?: Currency): any;
850
850
  depositWithdrawFee(info: any): any;
@@ -2513,7 +2513,7 @@ export default class Exchange {
2513
2513
  'bidVolume': this.safeNumber(ticker, 'bidVolume'),
2514
2514
  'ask': this.parseNumber(this.omitZero(this.safeNumber(ticker, 'ask'))),
2515
2515
  'askVolume': this.safeNumber(ticker, 'askVolume'),
2516
- 'high': this.parseNumber(this.omitZero(this.safeString(ticker, 'high"'))),
2516
+ 'high': this.parseNumber(this.omitZero(this.safeString(ticker, 'high'))),
2517
2517
  'low': this.parseNumber(this.omitZero(this.safeNumber(ticker, 'low'))),
2518
2518
  'open': this.parseNumber(this.omitZero(this.parseNumber(open))),
2519
2519
  'close': this.parseNumber(this.omitZero(this.parseNumber(close))),
@@ -3182,7 +3182,7 @@ export default class Exchange {
3182
3182
  throw new NotSupported(this.id + ' watchPositions() is not supported yet');
3183
3183
  }
3184
3184
  async watchPositionForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
3185
- return this.watchPositions(symbols, since, limit, params);
3185
+ return await this.watchPositions(symbols, since, limit, params);
3186
3186
  }
3187
3187
  async fetchPositionsForSymbol(symbol, params = {}) {
3188
3188
  /**
package/js/src/bybit.js CHANGED
@@ -2118,8 +2118,8 @@ export default class bybit extends Exchange {
2118
2118
  }
2119
2119
  const request = {
2120
2120
  // 'symbol': market['id'],
2121
- // 'baseCoin': '', Base coin. For option only
2122
- // 'expDate': '', Expiry date. e.g., 25DEC22. For option only
2121
+ // 'baseCoin': '', // Base coin. For option only
2122
+ // 'expDate': '', // Expiry date. e.g., 25DEC22. For option only
2123
2123
  };
2124
2124
  let type = undefined;
2125
2125
  [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
package/js/src/gate.d.ts CHANGED
@@ -220,6 +220,33 @@ export default class gate extends Exchange {
220
220
  fetchPositions(symbols?: Strings, params?: {}): Promise<import("./base/types.js").Position[]>;
221
221
  fetchLeverageTiers(symbols?: Strings, params?: {}): Promise<{}>;
222
222
  parseMarketLeverageTiers(info: any, market?: Market): any[];
223
+ repayMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<{
224
+ id: number;
225
+ currency: string;
226
+ amount: number;
227
+ symbol: string;
228
+ timestamp: number;
229
+ datetime: string;
230
+ info: any;
231
+ }>;
232
+ borrowMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<{
233
+ id: number;
234
+ currency: string;
235
+ amount: number;
236
+ symbol: string;
237
+ timestamp: number;
238
+ datetime: string;
239
+ info: any;
240
+ }>;
241
+ parseMarginLoan(info: any, currency?: Currency): {
242
+ id: number;
243
+ currency: string;
244
+ amount: number;
245
+ symbol: string;
246
+ timestamp: number;
247
+ datetime: string;
248
+ info: any;
249
+ };
223
250
  sign(path: any, api?: any[], method?: string, params?: {}, headers?: any, body?: any): {
224
251
  url: any;
225
252
  method: string;
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.67",
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",