ccxt 4.2.68 → 4.2.70

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
@@ -177,7 +177,7 @@ var woo$1 = require('./src/pro/woo.js');
177
177
 
178
178
  //-----------------------------------------------------------------------------
179
179
  // this is updated by vss.js when building
180
- const version = '4.2.68';
180
+ const version = '4.2.70';
181
181
  Exchange["default"].ccxtVersion = version;
182
182
  const exchanges = {
183
183
  'ace': ace,
@@ -236,7 +236,7 @@ class Exchange {
236
236
  this.socksProxyAgentModule = undefined;
237
237
  this.socksProxyAgentModuleChecked = false;
238
238
  this.proxyDictionaries = {};
239
- this.proxyModulesLoaded = false;
239
+ this.proxiesModulesLoading = undefined;
240
240
  Object.assign(this, functions);
241
241
  //
242
242
  // if (isNode) {
@@ -731,36 +731,38 @@ class Exchange {
731
731
  console.log(...args);
732
732
  }
733
733
  async loadProxyModules() {
734
- if (this.proxyModulesLoaded) {
735
- return;
736
- }
737
- this.proxyModulesLoaded = true;
738
- // we have to handle it with below nested way, because of dynamic
739
- // import issues (https://github.com/ccxt/ccxt/pull/20687)
740
- try {
741
- // todo: possible sync alternatives: https://stackoverflow.com/questions/51069002/convert-import-to-synchronous
742
- this.httpProxyAgentModule = await Promise.resolve().then(function () { return require(/* webpackIgnore: true */ '../static_dependencies/proxies/http-proxy-agent/index.js'); });
743
- this.httpsProxyAgentModule = await Promise.resolve().then(function () { return require(/* webpackIgnore: true */ '../static_dependencies/proxies/https-proxy-agent/index.js'); });
744
- }
745
- catch (e) {
746
- // if several users are using those frameworks which cause exceptions,
747
- // let them to be able to load modules still, by installing them
748
- try {
749
- // @ts-ignore
750
- this.httpProxyAgentModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */ 'http-proxy-agent')); });
751
- // @ts-ignore
752
- this.httpProxyAgentModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */ 'https-proxy-agent')); });
753
- }
754
- catch (e) { }
755
- }
756
- if (this.socksProxyAgentModuleChecked === false) {
757
- this.socksProxyAgentModuleChecked = true;
758
- try {
759
- // @ts-ignore
760
- this.socksProxyAgentModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */ 'socks-proxy-agent')); });
761
- }
762
- catch (e) { }
734
+ // when loading markets, multiple parallel calls are made, so need one promise
735
+ if (this.proxiesModulesLoading === undefined) {
736
+ this.proxiesModulesLoading = (async () => {
737
+ // we have to handle it with below nested way, because of dynamic
738
+ // import issues (https://github.com/ccxt/ccxt/pull/20687)
739
+ try {
740
+ // todo: possible sync alternatives: https://stackoverflow.com/questions/51069002/convert-import-to-synchronous
741
+ this.httpProxyAgentModule = await Promise.resolve().then(function () { return require(/* webpackIgnore: true */ '../static_dependencies/proxies/http-proxy-agent/index.js'); });
742
+ this.httpsProxyAgentModule = await Promise.resolve().then(function () { return require(/* webpackIgnore: true */ '../static_dependencies/proxies/https-proxy-agent/index.js'); });
743
+ }
744
+ catch (e) {
745
+ // if several users are using those frameworks which cause exceptions,
746
+ // let them to be able to load modules still, by installing them
747
+ try {
748
+ // @ts-ignore
749
+ this.httpProxyAgentModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */ 'http-proxy-agent')); });
750
+ // @ts-ignore
751
+ this.httpProxyAgentModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */ 'https-proxy-agent')); });
752
+ }
753
+ catch (e) { }
754
+ }
755
+ if (this.socksProxyAgentModuleChecked === false) {
756
+ try {
757
+ // @ts-ignore
758
+ this.socksProxyAgentModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */ 'socks-proxy-agent')); });
759
+ }
760
+ catch (e) { }
761
+ this.socksProxyAgentModuleChecked = true;
762
+ }
763
+ })();
763
764
  }
765
+ return await this.proxiesModulesLoading;
764
766
  }
765
767
  setProxyAgents(httpProxy, httpsProxy, socksProxy) {
766
768
  let chosenAgent = undefined;
@@ -85,6 +85,7 @@ class bitstamp extends bitstamp$1 {
85
85
  'setLeverage': false,
86
86
  'setMarginMode': false,
87
87
  'setPositionMode': false,
88
+ 'transfer': true,
88
89
  'withdraw': true,
89
90
  },
90
91
  'urls': {
@@ -2119,6 +2120,73 @@ class bitstamp extends bitstamp$1 {
2119
2120
  const response = await this[method](this.extend(request, params));
2120
2121
  return this.parseTransaction(response, currency);
2121
2122
  }
2123
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
2124
+ /**
2125
+ * @method
2126
+ * @name bitstamp#transfer
2127
+ * @description transfer currency internally between wallets on the same account
2128
+ * @see https://www.bitstamp.net/api/#tag/Sub-account/operation/TransferFromMainToSub
2129
+ * @see https://www.bitstamp.net/api/#tag/Sub-account/operation/TransferFromSubToMain
2130
+ * @param {string} code unified currency code
2131
+ * @param {float} amount amount to transfer
2132
+ * @param {string} fromAccount account to transfer from
2133
+ * @param {string} toAccount account to transfer to
2134
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2135
+ * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2136
+ */
2137
+ await this.loadMarkets();
2138
+ const currency = this.currency(code);
2139
+ amount = this.currencyToPrecision(code, amount);
2140
+ amount = this.parseToNumeric(amount);
2141
+ const request = {
2142
+ 'amount': amount,
2143
+ 'currency': currency['id'].toUpperCase(),
2144
+ };
2145
+ let response = undefined;
2146
+ if (fromAccount === 'main') {
2147
+ request['subAccount'] = toAccount;
2148
+ response = await this.privatePostTransferFromMain(this.extend(request, params));
2149
+ }
2150
+ else if (toAccount === 'main') {
2151
+ request['subAccount'] = fromAccount;
2152
+ response = await this.privatePostTransferToMain(this.extend(request, params));
2153
+ }
2154
+ else {
2155
+ throw new errors.BadRequest(this.id + ' transfer() only supports from or to main');
2156
+ }
2157
+ //
2158
+ // { status: 'ok' }
2159
+ //
2160
+ const transfer = this.parseTransfer(response, currency);
2161
+ transfer['amount'] = amount;
2162
+ transfer['fromAccount'] = fromAccount;
2163
+ transfer['toAccount'] = toAccount;
2164
+ return transfer;
2165
+ }
2166
+ parseTransfer(transfer, currency = undefined) {
2167
+ //
2168
+ // { status: 'ok' }
2169
+ //
2170
+ const status = this.safeString(transfer, 'status');
2171
+ return {
2172
+ 'info': transfer,
2173
+ 'id': undefined,
2174
+ 'timestamp': undefined,
2175
+ 'datetime': undefined,
2176
+ 'currency': currency['code'],
2177
+ 'amount': undefined,
2178
+ 'fromAccount': undefined,
2179
+ 'toAccount': undefined,
2180
+ 'status': this.parseTransferStatus(status),
2181
+ };
2182
+ }
2183
+ parseTransferStatus(status) {
2184
+ const statuses = {
2185
+ 'ok': 'ok',
2186
+ 'error': 'failed',
2187
+ };
2188
+ return this.safeString(statuses, status, status);
2189
+ }
2122
2190
  nonce() {
2123
2191
  return this.milliseconds();
2124
2192
  }
@@ -115,7 +115,8 @@ class gate extends gate$1 {
115
115
  'fetchIsolatedBorrowRate': false,
116
116
  'fetchIsolatedBorrowRates': false,
117
117
  'fetchLedger': true,
118
- 'fetchLeverage': false,
118
+ 'fetchLeverage': true,
119
+ 'fetchLeverages': true,
119
120
  'fetchLeverageTiers': true,
120
121
  'fetchLiquidations': true,
121
122
  'fetchMarginMode': false,
@@ -4480,7 +4481,10 @@ class gate extends gate$1 {
4480
4481
  if (lastTradeTimestamp === undefined) {
4481
4482
  lastTradeTimestamp = this.safeTimestamp2(order, 'update_time', 'finish_time');
4482
4483
  }
4483
- const marketType = ('currency_pair' in order) ? 'spot' : 'contract';
4484
+ let marketType = 'contract';
4485
+ if (('currency_pair' in order) || ('market' in order)) {
4486
+ marketType = 'spot';
4487
+ }
4484
4488
  const exchangeSymbol = this.safeString2(order, 'currency_pair', 'market', contract);
4485
4489
  const symbol = this.safeSymbol(exchangeSymbol, market, '_', marketType);
4486
4490
  // Everything below this(above return) is related to fees
@@ -7012,6 +7016,178 @@ class gate extends gate$1 {
7012
7016
  }
7013
7017
  return await this.createOrder(symbol, 'market', side, 0, undefined, params);
7014
7018
  }
7019
+ async fetchLeverage(symbol, params = {}) {
7020
+ /**
7021
+ * @method
7022
+ * @name gate#fetchLeverage
7023
+ * @description fetch the set leverage for a market
7024
+ * @see https://www.gate.io/docs/developers/apiv4/en/#get-unified-account-information
7025
+ * @see https://www.gate.io/docs/developers/apiv4/en/#get-detail-of-lending-market
7026
+ * @see https://www.gate.io/docs/developers/apiv4/en/#query-one-single-margin-currency-pair-deprecated
7027
+ * @param {string} symbol unified market symbol
7028
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
7029
+ * @param {boolean} [params.unified] default false, set to true for fetching the unified accounts leverage
7030
+ * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
7031
+ */
7032
+ await this.loadMarkets();
7033
+ let market = undefined;
7034
+ if (symbol !== undefined) {
7035
+ // unified account does not require a symbol
7036
+ market = this.market(symbol);
7037
+ }
7038
+ const request = {};
7039
+ let response = undefined;
7040
+ const isUnified = this.safeBool(params, 'unified');
7041
+ params = this.omit(params, 'unified');
7042
+ if (market['spot']) {
7043
+ request['currency_pair'] = market['id'];
7044
+ if (isUnified) {
7045
+ response = await this.publicMarginGetUniCurrencyPairsCurrencyPair(this.extend(request, params));
7046
+ //
7047
+ // {
7048
+ // "currency_pair": "BTC_USDT",
7049
+ // "base_min_borrow_amount": "0.0001",
7050
+ // "quote_min_borrow_amount": "1",
7051
+ // "leverage": "10"
7052
+ // }
7053
+ //
7054
+ }
7055
+ else {
7056
+ response = await this.publicMarginGetCurrencyPairsCurrencyPair(this.extend(request, params));
7057
+ //
7058
+ // {
7059
+ // "id": "BTC_USDT",
7060
+ // "base": "BTC",
7061
+ // "quote": "USDT",
7062
+ // "leverage": 10,
7063
+ // "min_base_amount": "0.0001",
7064
+ // "min_quote_amount": "1",
7065
+ // "max_quote_amount": "40000000",
7066
+ // "status": 1
7067
+ // }
7068
+ //
7069
+ }
7070
+ }
7071
+ else if (isUnified) {
7072
+ response = await this.privateUnifiedGetAccounts(this.extend(request, params));
7073
+ //
7074
+ // {
7075
+ // "user_id": 10001,
7076
+ // "locked": false,
7077
+ // "balances": {
7078
+ // "ETH": {
7079
+ // "available": "0",
7080
+ // "freeze": "0",
7081
+ // "borrowed": "0.075393666654",
7082
+ // "negative_liab": "0",
7083
+ // "futures_pos_liab": "0",
7084
+ // "equity": "1016.1",
7085
+ // "total_freeze": "0",
7086
+ // "total_liab": "0"
7087
+ // },
7088
+ // "POINT": {
7089
+ // "available": "9999999999.017023138734",
7090
+ // "freeze": "0",
7091
+ // "borrowed": "0",
7092
+ // "negative_liab": "0",
7093
+ // "futures_pos_liab": "0",
7094
+ // "equity": "12016.1",
7095
+ // "total_freeze": "0",
7096
+ // "total_liab": "0"
7097
+ // },
7098
+ // "USDT": {
7099
+ // "available": "0.00000062023",
7100
+ // "freeze": "0",
7101
+ // "borrowed": "0",
7102
+ // "negative_liab": "0",
7103
+ // "futures_pos_liab": "0",
7104
+ // "equity": "16.1",
7105
+ // "total_freeze": "0",
7106
+ // "total_liab": "0"
7107
+ // }
7108
+ // },
7109
+ // "total": "230.94621713",
7110
+ // "borrowed": "161.66395521",
7111
+ // "total_initial_margin": "1025.0524665088",
7112
+ // "total_margin_balance": "3382495.944473949183",
7113
+ // "total_maintenance_margin": "205.01049330176",
7114
+ // "total_initial_margin_rate": "3299.827135672679",
7115
+ // "total_maintenance_margin_rate": "16499.135678363399",
7116
+ // "total_available_margin": "3381470.892007440383",
7117
+ // "unified_account_total": "3381470.892007440383",
7118
+ // "unified_account_total_liab": "0",
7119
+ // "unified_account_total_equity": "100016.1",
7120
+ // "leverage": "2"
7121
+ // }
7122
+ //
7123
+ }
7124
+ else {
7125
+ throw new errors.NotSupported(this.id + ' fetchLeverage() does not support ' + market['type'] + ' markets');
7126
+ }
7127
+ return this.parseLeverage(response, market);
7128
+ }
7129
+ async fetchLeverages(symbols = undefined, params = {}) {
7130
+ /**
7131
+ * @method
7132
+ * @name gate#fetchLeverages
7133
+ * @description fetch the set leverage for all leverage markets, only spot margin is supported on gate
7134
+ * @see https://www.gate.io/docs/developers/apiv4/en/#list-lending-markets
7135
+ * @see https://www.gate.io/docs/developers/apiv4/en/#list-all-supported-currency-pairs-supported-in-margin-trading-deprecated
7136
+ * @param {string[]} symbols a list of unified market symbols
7137
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
7138
+ * @param {boolean} [params.unified] default false, set to true for fetching unified account leverages
7139
+ * @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/#/?id=leverage-structure}
7140
+ */
7141
+ await this.loadMarkets();
7142
+ symbols = this.marketSymbols(symbols);
7143
+ let response = undefined;
7144
+ const isUnified = this.safeBool(params, 'unified');
7145
+ params = this.omit(params, 'unified');
7146
+ let marketIdRequest = 'id';
7147
+ if (isUnified) {
7148
+ marketIdRequest = 'currency_pair';
7149
+ response = await this.publicMarginGetUniCurrencyPairs(params);
7150
+ //
7151
+ // [
7152
+ // {
7153
+ // "currency_pair": "1INCH_USDT",
7154
+ // "base_min_borrow_amount": "8",
7155
+ // "quote_min_borrow_amount": "1",
7156
+ // "leverage": "3"
7157
+ // },
7158
+ // ]
7159
+ //
7160
+ }
7161
+ else {
7162
+ response = await this.publicMarginGetCurrencyPairs(params);
7163
+ //
7164
+ // [
7165
+ // {
7166
+ // "id": "1CAT_USDT",
7167
+ // "base": "1CAT",
7168
+ // "quote": "USDT",
7169
+ // "leverage": 3,
7170
+ // "min_base_amount": "71",
7171
+ // "min_quote_amount": "1",
7172
+ // "max_quote_amount": "10000",
7173
+ // "status": 1
7174
+ // },
7175
+ // ]
7176
+ //
7177
+ }
7178
+ return this.parseLeverages(response, symbols, marketIdRequest, 'spot');
7179
+ }
7180
+ parseLeverage(leverage, market = undefined) {
7181
+ const marketId = this.safeString2(leverage, 'currency_pair', 'id');
7182
+ const leverageValue = this.safeInteger(leverage, 'leverage');
7183
+ return {
7184
+ 'info': leverage,
7185
+ 'symbol': this.safeSymbol(marketId, market, '_', 'spot'),
7186
+ 'marginMode': undefined,
7187
+ 'longLeverage': leverageValue,
7188
+ 'shortLeverage': leverageValue,
7189
+ };
7190
+ }
7015
7191
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
7016
7192
  if (response === undefined) {
7017
7193
  return undefined;