ccxt 4.4.88 → 4.4.90

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.
Files changed (85) hide show
  1. package/README.md +61 -19
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +6 -3
  5. package/dist/cjs/src/base/functions/encode.js +1 -1
  6. package/dist/cjs/src/base/functions/generic.js +6 -0
  7. package/dist/cjs/src/base/functions.js +1 -0
  8. package/dist/cjs/src/binance.js +1 -1
  9. package/dist/cjs/src/bingx.js +60 -32
  10. package/dist/cjs/src/bitget.js +493 -154
  11. package/dist/cjs/src/bitrue.js +72 -66
  12. package/dist/cjs/src/bitvavo.js +34 -0
  13. package/dist/cjs/src/btcalpha.js +35 -0
  14. package/dist/cjs/src/btcbox.js +35 -0
  15. package/dist/cjs/src/btcmarkets.js +35 -0
  16. package/dist/cjs/src/btcturk.js +35 -0
  17. package/dist/cjs/src/bybit.js +9 -3
  18. package/dist/cjs/src/coinbase.js +1 -4
  19. package/dist/cjs/src/cryptocom.js +54 -0
  20. package/dist/cjs/src/delta.js +2 -2
  21. package/dist/cjs/src/digifinex.js +40 -109
  22. package/dist/cjs/src/gate.js +12 -5
  23. package/dist/cjs/src/hashkey.js +15 -28
  24. package/dist/cjs/src/hollaex.js +28 -24
  25. package/dist/cjs/src/kraken.js +30 -53
  26. package/dist/cjs/src/luno.js +92 -0
  27. package/dist/cjs/src/okx.js +2 -1
  28. package/dist/cjs/src/phemex.js +16 -8
  29. package/dist/cjs/src/pro/coinbase.js +2 -0
  30. package/dist/cjs/src/pro/cryptocom.js +27 -0
  31. package/dist/cjs/src/pro/kraken.js +3 -11
  32. package/dist/cjs/src/tradeogre.js +3 -3
  33. package/dist/cjs/src/xt.js +1 -1
  34. package/js/ccxt.d.ts +1 -1
  35. package/js/ccxt.js +1 -1
  36. package/js/src/abstract/bitget.d.ts +58 -0
  37. package/js/src/abstract/cryptocom.d.ts +2 -0
  38. package/js/src/abstract/luno.d.ts +1 -0
  39. package/js/src/base/Exchange.d.ts +4 -1
  40. package/js/src/base/Exchange.js +6 -3
  41. package/js/src/base/functions/encode.d.ts +1 -1
  42. package/js/src/base/functions/encode.js +1 -1
  43. package/js/src/base/functions/generic.d.ts +2 -1
  44. package/js/src/base/functions/generic.js +6 -1
  45. package/js/src/binance.js +1 -1
  46. package/js/src/bingx.d.ts +9 -5
  47. package/js/src/bingx.js +60 -32
  48. package/js/src/bitget.d.ts +4 -1
  49. package/js/src/bitget.js +493 -154
  50. package/js/src/bitrue.js +72 -66
  51. package/js/src/bitvavo.js +34 -0
  52. package/js/src/btcalpha.js +35 -0
  53. package/js/src/btcbox.js +35 -0
  54. package/js/src/btcmarkets.js +35 -0
  55. package/js/src/btcturk.js +35 -0
  56. package/js/src/bybit.js +9 -3
  57. package/js/src/coinbase.d.ts +1 -1
  58. package/js/src/coinbase.js +1 -4
  59. package/js/src/cryptocom.d.ts +17 -0
  60. package/js/src/cryptocom.js +54 -0
  61. package/js/src/delta.js +2 -2
  62. package/js/src/digifinex.js +40 -109
  63. package/js/src/gate.d.ts +1 -1
  64. package/js/src/gate.js +12 -5
  65. package/js/src/hashkey.d.ts +0 -1
  66. package/js/src/hashkey.js +15 -28
  67. package/js/src/hollaex.d.ts +1 -2
  68. package/js/src/hollaex.js +29 -25
  69. package/js/src/kraken.d.ts +0 -1
  70. package/js/src/kraken.js +30 -53
  71. package/js/src/luno.d.ts +9 -1
  72. package/js/src/luno.js +92 -0
  73. package/js/src/okx.js +2 -1
  74. package/js/src/phemex.d.ts +1 -0
  75. package/js/src/phemex.js +16 -8
  76. package/js/src/pro/coinbase.js +2 -0
  77. package/js/src/pro/cryptocom.d.ts +16 -0
  78. package/js/src/pro/cryptocom.js +27 -0
  79. package/js/src/pro/kraken.js +3 -11
  80. package/js/src/tradeogre.js +3 -3
  81. package/js/src/xt.js +1 -1
  82. package/package.json +4 -7
  83. package/examples/README.md +0 -316
  84. package/examples/js/README.md +0 -15
  85. package/examples/js/cli.js +0 -559
package/js/src/bitget.js CHANGED
@@ -176,6 +176,7 @@ export default class bitget extends Exchange {
176
176
  'convert': 'https://api.{hostname}',
177
177
  'copy': 'https://api.{hostname}',
178
178
  'earn': 'https://api.{hostname}',
179
+ 'uta': 'https://api.{hostname}',
179
180
  },
180
181
  'www': 'https://www.bitget.com',
181
182
  'doc': [
@@ -292,6 +293,24 @@ export default class bitget extends Exchange {
292
293
  'v2/earn/loan/public/hour-interest': 2,
293
294
  },
294
295
  },
296
+ 'uta': {
297
+ 'get': {
298
+ 'v3/market/instruments': 1,
299
+ 'v3/market/tickers': 1,
300
+ 'v3/market/orderbook': 1,
301
+ 'v3/market/fills': 1,
302
+ 'v3/market/open-interest': 1,
303
+ 'v3/market/candles': 1,
304
+ 'v3/market/history-candles': 1,
305
+ 'v3/market/current-fund-rate': 1,
306
+ 'v3/market/history-fund-rate': 1,
307
+ 'v3/market/risk-reserve': 1,
308
+ 'v3/market/discount-rate': 1,
309
+ 'v3/market/margin-loans': 1,
310
+ 'v3/market/position-tier': 1,
311
+ 'v3/market/oi-limit': 2,
312
+ },
313
+ },
295
314
  },
296
315
  'private': {
297
316
  'spot': {
@@ -785,6 +804,56 @@ export default class bitget extends Exchange {
785
804
  'v2/common/trade-rate': 2,
786
805
  },
787
806
  },
807
+ 'uta': {
808
+ 'get': {
809
+ 'v3/account/assets': 1,
810
+ 'v3/account/settings': 1,
811
+ 'v3/account/financial-records': 1,
812
+ 'v3/account/repayable-coins': 2,
813
+ 'v3/account/payment-coins': 2,
814
+ 'v3/account/convert-records': 1,
815
+ 'v3/account/transferable-coins': 2,
816
+ 'v3/account/sub-transfer-record': 4,
817
+ 'v3/ins-loan/transfered': 6.6667,
818
+ 'v3/ins-loan/symbols': 6.6667,
819
+ 'v3/ins-loan/risk-unit': 6.6667,
820
+ 'v3/ins-loan/repaid-history': 6.6667,
821
+ 'v3/ins-loan/product-infos': 6.6667,
822
+ 'v3/ins-loan/loan-order': 6.6667,
823
+ 'v3/ins-loan/ltv-convert': 6.6667,
824
+ 'v3/ins-loan/ensure-coins-convert': 6.6667,
825
+ 'v3/position/current-position': 1,
826
+ 'v3/position/history-position': 1,
827
+ 'v3/trade/order-info': 1,
828
+ 'v3/trade/unfilled-orders': 1,
829
+ 'v3/trade/history-orders': 1,
830
+ 'v3/trade/fills': 1,
831
+ 'v3/user/sub-list': 2,
832
+ 'v3/user/sub-api-list': 2,
833
+ },
834
+ 'post': {
835
+ 'v3/account/set-leverage': 2,
836
+ 'v3/account/set-hold-mode': 2,
837
+ 'v3/account/repay': 4,
838
+ 'v3/account/transfer': 4,
839
+ 'v3/account/sub-transfer': 4,
840
+ 'v3/account/max-open-available': 4,
841
+ 'v3/ins-loan/bind-uid': 6.6667,
842
+ 'v3/trade/place-order': 2,
843
+ 'v3/trade/modify-order': 2,
844
+ 'v3/trade/cancel-order': 2,
845
+ 'v3/trade/place-batch': 4,
846
+ 'v3/trade/batch-modify-order': 2,
847
+ 'v3/trade/cancel-batch': 4,
848
+ 'v3/trade/cancel-symbol-order': 4,
849
+ 'v3/trade/close-positions': 4,
850
+ 'v3/user/create-sub': 2,
851
+ 'v3/user/freeze-sub': 2,
852
+ 'v3/user/create-sub-api': 2,
853
+ 'v3/user/update-sub-api': 2,
854
+ 'v3/user/delete-sub-api': 2,
855
+ },
856
+ },
788
857
  },
789
858
  },
790
859
  'fees': {
@@ -1328,6 +1397,7 @@ export default class bitget extends Exchange {
1328
1397
  'TONCOIN': 'TON',
1329
1398
  },
1330
1399
  'options': {
1400
+ 'uta': false,
1331
1401
  'timeDifference': 0,
1332
1402
  'adjustForTimeDifference': false,
1333
1403
  'timeframes': {
@@ -1362,10 +1432,9 @@ export default class bitget extends Exchange {
1362
1432
  '1M': '1Mutc',
1363
1433
  },
1364
1434
  },
1365
- 'fetchMarkets': [
1366
- 'spot',
1367
- 'swap', // there is future markets but they use the same endpoints as swap
1368
- ],
1435
+ 'fetchMarkets': {
1436
+ 'types': ['spot', 'swap'], // there is future markets but they use the same endpoints as swap
1437
+ },
1369
1438
  'defaultType': 'spot',
1370
1439
  'defaultSubType': 'linear',
1371
1440
  'createMarketBuyOrderRequiresPrice': true,
@@ -1763,14 +1832,35 @@ export default class bitget extends Exchange {
1763
1832
  * @see https://www.bitget.com/api-doc/spot/market/Get-Symbols
1764
1833
  * @see https://www.bitget.com/api-doc/contract/market/Get-All-Symbols-Contracts
1765
1834
  * @see https://www.bitget.com/api-doc/margin/common/support-currencies
1835
+ * @see https://www.bitget.bike/api-doc/uta/public/Instruments
1766
1836
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1837
+ * @param {string} [params.uta] set to true to fetch markets for the unified trading account (uta), defaults to false
1767
1838
  * @returns {object[]} an array of objects representing market data
1768
1839
  */
1769
1840
  async fetchMarkets(params = {}) {
1770
1841
  if (this.options['adjustForTimeDifference']) {
1771
1842
  await this.loadTimeDifference();
1772
1843
  }
1773
- const types = this.safeValue(this.options, 'fetchMarkets', ['spot', 'swap']);
1844
+ let uta = undefined;
1845
+ [uta, params] = this.handleOptionAndParams(params, 'fetchMarkets', 'uta', false);
1846
+ if (uta) {
1847
+ return await this.fetchUtaMarkets(params);
1848
+ }
1849
+ else {
1850
+ return await this.fetchDefaultMarkets(params);
1851
+ }
1852
+ }
1853
+ async fetchDefaultMarkets(params) {
1854
+ let types = undefined;
1855
+ const fetchMarketsOptions = this.safeDict(this.options, 'fetchMarkets');
1856
+ const defaultMarkets = ['spot', 'swap'];
1857
+ if (fetchMarketsOptions !== undefined) {
1858
+ types = this.safeList(fetchMarketsOptions, 'types', defaultMarkets);
1859
+ }
1860
+ else {
1861
+ // for backward-compatibility
1862
+ types = this.safeList(this.options, 'fetchMarkets', defaultMarkets);
1863
+ }
1774
1864
  const promises = [];
1775
1865
  let fetchMargins = false;
1776
1866
  for (let i = 0; i < types.length; i++) {
@@ -1810,13 +1900,6 @@ export default class bitget extends Exchange {
1810
1900
  markets = this.arrayConcat(markets, data);
1811
1901
  }
1812
1902
  }
1813
- const result = [];
1814
- for (let i = 0; i < markets.length; i++) {
1815
- result.push(this.parseMarket(markets[i]));
1816
- }
1817
- return result;
1818
- }
1819
- parseMarket(market) {
1820
1903
  //
1821
1904
  // spot
1822
1905
  //
@@ -1874,155 +1957,411 @@ export default class bitget extends Exchange {
1874
1957
  // "maintainTime": ""
1875
1958
  // }
1876
1959
  //
1877
- const marketId = this.safeString(market, 'symbol');
1878
- const quoteId = this.safeString(market, 'quoteCoin');
1879
- const baseId = this.safeString(market, 'baseCoin');
1880
- const quote = this.safeCurrencyCode(quoteId);
1881
- const base = this.safeCurrencyCode(baseId);
1882
- const supportMarginCoins = this.safeValue(market, 'supportMarginCoins', []);
1883
- let settleId = undefined;
1884
- if (this.inArray(baseId, supportMarginCoins)) {
1885
- settleId = baseId;
1960
+ const result = [];
1961
+ for (let i = 0; i < markets.length; i++) {
1962
+ const market = markets[i];
1963
+ const marketId = this.safeString(market, 'symbol');
1964
+ const quoteId = this.safeString(market, 'quoteCoin');
1965
+ const baseId = this.safeString(market, 'baseCoin');
1966
+ const quote = this.safeCurrencyCode(quoteId);
1967
+ const base = this.safeCurrencyCode(baseId);
1968
+ const supportMarginCoins = this.safeValue(market, 'supportMarginCoins', []);
1969
+ let settleId = undefined;
1970
+ if (this.inArray(baseId, supportMarginCoins)) {
1971
+ settleId = baseId;
1972
+ }
1973
+ else if (this.inArray(quoteId, supportMarginCoins)) {
1974
+ settleId = quoteId;
1975
+ }
1976
+ else {
1977
+ settleId = this.safeString(supportMarginCoins, 0);
1978
+ }
1979
+ const settle = this.safeCurrencyCode(settleId);
1980
+ let symbol = base + '/' + quote;
1981
+ let type = undefined;
1982
+ let swap = false;
1983
+ let spot = false;
1984
+ let future = false;
1985
+ let contract = false;
1986
+ let pricePrecision = undefined;
1987
+ let amountPrecision = undefined;
1988
+ let linear = undefined;
1989
+ let inverse = undefined;
1990
+ let expiry = undefined;
1991
+ let expiryDatetime = undefined;
1992
+ const symbolType = this.safeString(market, 'symbolType');
1993
+ let marginModes = undefined;
1994
+ let isMarginTradingAllowed = false;
1995
+ if (symbolType === undefined) {
1996
+ type = 'spot';
1997
+ spot = true;
1998
+ pricePrecision = this.parseNumber(this.parsePrecision(this.safeString(market, 'pricePrecision')));
1999
+ amountPrecision = this.parseNumber(this.parsePrecision(this.safeString(market, 'quantityPrecision')));
2000
+ const hasCrossMargin = this.inArray(marketId, this.options['crossMarginPairsData']);
2001
+ const hasIsolatedMargin = this.inArray(marketId, this.options['isolatedMarginPairsData']);
2002
+ marginModes = {
2003
+ 'cross': hasCrossMargin,
2004
+ 'isolated': hasIsolatedMargin,
2005
+ };
2006
+ isMarginTradingAllowed = hasCrossMargin || hasCrossMargin;
2007
+ }
2008
+ else {
2009
+ if (symbolType === 'perpetual') {
2010
+ type = 'swap';
2011
+ swap = true;
2012
+ symbol = symbol + ':' + settle;
2013
+ }
2014
+ else if (symbolType === 'delivery') {
2015
+ expiry = this.safeInteger(market, 'deliveryTime');
2016
+ expiryDatetime = this.iso8601(expiry);
2017
+ const expiryParts = expiryDatetime.split('-');
2018
+ const yearPart = this.safeString(expiryParts, 0);
2019
+ const dayPart = this.safeString(expiryParts, 2);
2020
+ const year = yearPart.slice(2, 4);
2021
+ const month = this.safeString(expiryParts, 1);
2022
+ const day = dayPart.slice(0, 2);
2023
+ const expiryString = year + month + day;
2024
+ type = 'future';
2025
+ future = true;
2026
+ symbol = symbol + ':' + settle + '-' + expiryString;
2027
+ }
2028
+ contract = true;
2029
+ inverse = (base === settle);
2030
+ linear = !inverse;
2031
+ const priceDecimals = this.safeInteger(market, 'pricePlace');
2032
+ const amountDecimals = this.safeInteger(market, 'volumePlace');
2033
+ const priceStep = this.safeString(market, 'priceEndStep');
2034
+ const amountStep = this.safeString(market, 'sizeMultiplier');
2035
+ const precise = new Precise(priceStep);
2036
+ precise.decimals = Math.max(precise.decimals, priceDecimals);
2037
+ precise.reduce();
2038
+ const priceString = precise.toString();
2039
+ pricePrecision = this.parseNumber(priceString);
2040
+ const preciseAmount = new Precise(amountStep);
2041
+ preciseAmount.decimals = Math.max(preciseAmount.decimals, amountDecimals);
2042
+ preciseAmount.reduce();
2043
+ const amountString = preciseAmount.toString();
2044
+ amountPrecision = this.parseNumber(amountString);
2045
+ marginModes = {
2046
+ 'cross': true,
2047
+ 'isolated': true,
2048
+ };
2049
+ }
2050
+ const status = this.safeString2(market, 'status', 'symbolStatus');
2051
+ let active = undefined;
2052
+ if (status !== undefined) {
2053
+ active = ((status === 'online') || (status === 'normal'));
2054
+ }
2055
+ let minCost = undefined;
2056
+ if (quote === 'USDT') {
2057
+ minCost = this.safeNumber(market, 'minTradeUSDT');
2058
+ }
2059
+ const contractSize = contract ? 1 : undefined;
2060
+ result.push(this.safeMarketStructure({
2061
+ 'id': marketId,
2062
+ 'symbol': symbol,
2063
+ 'base': base,
2064
+ 'quote': quote,
2065
+ 'settle': settle,
2066
+ 'baseId': baseId,
2067
+ 'quoteId': quoteId,
2068
+ 'settleId': settleId,
2069
+ 'type': type,
2070
+ 'spot': spot,
2071
+ 'margin': spot && isMarginTradingAllowed,
2072
+ 'marginModes': marginModes,
2073
+ 'swap': swap,
2074
+ 'future': future,
2075
+ 'option': false,
2076
+ 'active': active,
2077
+ 'contract': contract,
2078
+ 'linear': linear,
2079
+ 'inverse': inverse,
2080
+ 'taker': this.safeNumber(market, 'takerFeeRate'),
2081
+ 'maker': this.safeNumber(market, 'makerFeeRate'),
2082
+ 'contractSize': contractSize,
2083
+ 'expiry': expiry,
2084
+ 'expiryDatetime': expiryDatetime,
2085
+ 'strike': undefined,
2086
+ 'optionType': undefined,
2087
+ 'precision': {
2088
+ 'amount': amountPrecision,
2089
+ 'price': pricePrecision,
2090
+ },
2091
+ 'limits': {
2092
+ 'leverage': {
2093
+ 'min': this.safeNumber(market, 'minLever'),
2094
+ 'max': this.safeNumber(market, 'maxLever'),
2095
+ },
2096
+ 'amount': {
2097
+ 'min': this.safeNumber2(market, 'minTradeNum', 'minTradeAmount'),
2098
+ 'max': this.safeNumber(market, 'maxTradeAmount'),
2099
+ },
2100
+ 'price': {
2101
+ 'min': undefined,
2102
+ 'max': undefined,
2103
+ },
2104
+ 'cost': {
2105
+ 'min': minCost,
2106
+ 'max': undefined,
2107
+ },
2108
+ },
2109
+ 'created': this.safeInteger(market, 'launchTime'),
2110
+ 'info': market,
2111
+ }));
1886
2112
  }
1887
- else if (this.inArray(quoteId, supportMarginCoins)) {
1888
- settleId = quoteId;
2113
+ return result;
2114
+ }
2115
+ async fetchUtaMarkets(params) {
2116
+ const subTypes = ['SPOT', 'USDT-FUTURES', 'COIN-FUTURES', 'USDC-FUTURES'];
2117
+ const promises = [];
2118
+ for (let i = 0; i < subTypes.length; i++) {
2119
+ const req = this.extend(params, {
2120
+ 'category': subTypes[i],
2121
+ });
2122
+ promises.push(this.publicUtaGetV3MarketInstruments(req));
1889
2123
  }
1890
- else {
1891
- settleId = this.safeString(supportMarginCoins, 0);
2124
+ const results = await Promise.all(promises);
2125
+ let markets = [];
2126
+ for (let i = 0; i < results.length; i++) {
2127
+ const res = this.safeDict(results, i);
2128
+ const data = this.safeList(res, 'data', []);
2129
+ markets = this.arrayConcat(markets, data);
1892
2130
  }
1893
- const settle = this.safeCurrencyCode(settleId);
1894
- let symbol = base + '/' + quote;
1895
- let type = undefined;
1896
- let swap = false;
1897
- let spot = false;
1898
- let future = false;
1899
- let contract = false;
1900
- let pricePrecision = undefined;
1901
- let amountPrecision = undefined;
1902
- let linear = undefined;
1903
- let inverse = undefined;
1904
- let expiry = undefined;
1905
- let expiryDatetime = undefined;
1906
- const symbolType = this.safeString(market, 'symbolType');
1907
- let marginModes = undefined;
1908
- let isMarginTradingAllowed = false;
1909
- if (symbolType === undefined) {
1910
- type = 'spot';
1911
- spot = true;
2131
+ //
2132
+ // spot uta
2133
+ //
2134
+ // {
2135
+ // "symbol": "BTCUSDT",
2136
+ // "category": "SPOT",
2137
+ // "baseCoin": "BTC",
2138
+ // "quoteCoin": "USDT",
2139
+ // "buyLimitPriceRatio": "0.05",
2140
+ // "sellLimitPriceRatio": "0.05",
2141
+ // "minOrderQty": "0.000001",
2142
+ // "maxOrderQty": "0",
2143
+ // "pricePrecision": "2",
2144
+ // "quantityPrecision": "6",
2145
+ // "quotePrecision": "8",
2146
+ // "minOrderAmount": "1",
2147
+ // "maxSymbolOrderNum": "400",
2148
+ // "maxProductOrderNum": "400",
2149
+ // "status": "online",
2150
+ // "maintainTime": ""
2151
+ // }
2152
+ //
2153
+ // margin uta
2154
+ //
2155
+ // {
2156
+ // "symbol": "BTCUSDC",
2157
+ // "category": "MARGIN",
2158
+ // "baseCoin": "BTC",
2159
+ // "quoteCoin": "USDC",
2160
+ // "buyLimitPriceRatio": "0.05",
2161
+ // "sellLimitPriceRatio": "0.05",
2162
+ // "minOrderQty": "0.00001",
2163
+ // "maxOrderQty": "0",
2164
+ // "pricePrecision": "2",
2165
+ // "quantityPrecision": "5",
2166
+ // "quotePrecision": "7",
2167
+ // "minOrderAmount": "1",
2168
+ // "maxSymbolOrderNum": "400",
2169
+ // "maxProductOrderNum": "400",
2170
+ // "status": "online",
2171
+ // "maintainTime": "",
2172
+ // "isIsolatedBaseBorrowable": "NO",
2173
+ // "isIsolatedQuotedBorrowable": "NO",
2174
+ // "warningRiskRatio": "0.8",
2175
+ // "liquidationRiskRatio": "1",
2176
+ // "maxCrossedLeverage": "3",
2177
+ // "maxIsolatedLeverage": "0",
2178
+ // "userMinBorrow": "0.00000001",
2179
+ // "areaSymbol": "no"
2180
+ // }
2181
+ //
2182
+ // swap and future uta
2183
+ //
2184
+ // {
2185
+ // "symbol": "BTCPERP",
2186
+ // "category": "USDC-FUTURES",
2187
+ // "baseCoin": "BTC",
2188
+ // "quoteCoin": "USDC",
2189
+ // "buyLimitPriceRatio": "0.02",
2190
+ // "sellLimitPriceRatio": "0.02",
2191
+ // "feeRateUpRatio": "0.005",
2192
+ // "makerFeeRate": "0.0002",
2193
+ // "takerFeeRate": "0.0006",
2194
+ // "openCostUpRatio": "0.01",
2195
+ // "minOrderQty": "0.0001",
2196
+ // "maxOrderQty": "",
2197
+ // "pricePrecision": "1",
2198
+ // "quantityPrecision": "4",
2199
+ // "quotePrecision": null,
2200
+ // "priceMultiplier": "0.5",
2201
+ // "quantityMultiplier": "0.0001",
2202
+ // "type": "perpetual",
2203
+ // "minOrderAmount": "5",
2204
+ // "maxSymbolOrderNum": "200",
2205
+ // "maxProductOrderNum": "1000",
2206
+ // "maxPositionNum": "150",
2207
+ // "status": "online",
2208
+ // "offTime": "-1",
2209
+ // "limitOpenTime": "-1",
2210
+ // "deliveryTime": "",
2211
+ // "deliveryStartTime": "",
2212
+ // "deliveryPeriod": "",
2213
+ // "launchTime": "",
2214
+ // "fundInterval": "8",
2215
+ // "minLeverage": "1",
2216
+ // "maxLeverage": "125",
2217
+ // "maintainTime": ""
2218
+ // }
2219
+ //
2220
+ const result = [];
2221
+ for (let i = 0; i < markets.length; i++) {
2222
+ const market = markets[i];
2223
+ const category = this.safeString(market, 'category');
2224
+ const marketId = this.safeString(market, 'symbol');
2225
+ const quoteId = this.safeString(market, 'quoteCoin');
2226
+ const baseId = this.safeString(market, 'baseCoin');
2227
+ const quote = this.safeCurrencyCode(quoteId);
2228
+ const base = this.safeCurrencyCode(baseId);
2229
+ let settleId = undefined;
2230
+ let settle = undefined;
2231
+ if (category === 'USDT-FUTURES') {
2232
+ settleId = 'USDT';
2233
+ }
2234
+ else if (category === 'USDC-FUTURES') {
2235
+ settleId = 'USDC';
2236
+ }
2237
+ else if (category === 'COIN-FUTURES') {
2238
+ settleId = base;
2239
+ }
2240
+ if (settleId !== undefined) {
2241
+ settle = this.safeCurrencyCode(settleId);
2242
+ }
2243
+ let symbol = base + '/' + quote;
2244
+ let type = undefined;
2245
+ let swap = false;
2246
+ let spot = false;
2247
+ let future = false;
2248
+ let contract = false;
2249
+ let pricePrecision = undefined;
2250
+ let amountPrecision = undefined;
2251
+ let linear = undefined;
2252
+ let inverse = undefined;
2253
+ let expiry = undefined;
2254
+ let expiryDatetime = undefined;
2255
+ const symbolType = this.safeString(market, 'type');
2256
+ let marginModes = undefined;
2257
+ let isMarginTradingAllowed = false;
2258
+ const isUtaMargin = (category === 'MARGIN');
2259
+ if (isUtaMargin || (category === 'SPOT')) {
2260
+ type = 'spot';
2261
+ spot = true;
2262
+ if (isUtaMargin) {
2263
+ const isolatedBase = this.safeString(market, 'isIsolatedBaseBorrowable');
2264
+ const isolatedQuote = this.safeString(market, 'isIsolatedQuotedBorrowable');
2265
+ const isolated = (isolatedBase === 'YES') || (isolatedQuote === 'YES');
2266
+ const maxCrossLeverage = this.safeString(market, 'maxCrossedLeverage');
2267
+ const cross = (maxCrossLeverage !== '0');
2268
+ marginModes = {
2269
+ 'cross': cross,
2270
+ 'isolated': isolated,
2271
+ };
2272
+ isMarginTradingAllowed = true;
2273
+ }
2274
+ }
2275
+ else {
2276
+ if (symbolType === 'perpetual') {
2277
+ type = 'swap';
2278
+ swap = true;
2279
+ symbol = symbol + ':' + settle;
2280
+ }
2281
+ else if (symbolType === 'delivery') {
2282
+ expiry = this.safeInteger(market, 'deliveryTime');
2283
+ expiryDatetime = this.iso8601(expiry);
2284
+ const expiryParts = expiryDatetime.split('-');
2285
+ const yearPart = this.safeString(expiryParts, 0);
2286
+ const dayPart = this.safeString(expiryParts, 2);
2287
+ const year = yearPart.slice(2, 4);
2288
+ const month = this.safeString(expiryParts, 1);
2289
+ const day = dayPart.slice(0, 2);
2290
+ const expiryString = year + month + day;
2291
+ type = 'future';
2292
+ future = true;
2293
+ symbol = symbol + ':' + settle + '-' + expiryString;
2294
+ }
2295
+ contract = true;
2296
+ inverse = (base === settle);
2297
+ linear = !inverse;
2298
+ marginModes = {
2299
+ 'cross': true,
2300
+ 'isolated': true,
2301
+ };
2302
+ }
1912
2303
  pricePrecision = this.parseNumber(this.parsePrecision(this.safeString(market, 'pricePrecision')));
1913
2304
  amountPrecision = this.parseNumber(this.parsePrecision(this.safeString(market, 'quantityPrecision')));
1914
- const hasCrossMargin = this.inArray(marketId, this.options['crossMarginPairsData']);
1915
- const hasIsolatedMargin = this.inArray(marketId, this.options['isolatedMarginPairsData']);
1916
- marginModes = {
1917
- 'cross': hasCrossMargin,
1918
- 'isolated': hasIsolatedMargin,
1919
- };
1920
- isMarginTradingAllowed = hasCrossMargin || hasCrossMargin;
1921
- }
1922
- else {
1923
- if (symbolType === 'perpetual') {
1924
- type = 'swap';
1925
- swap = true;
1926
- symbol = symbol + ':' + settle;
1927
- }
1928
- else if (symbolType === 'delivery') {
1929
- expiry = this.safeInteger(market, 'deliveryTime');
1930
- expiryDatetime = this.iso8601(expiry);
1931
- const expiryParts = expiryDatetime.split('-');
1932
- const yearPart = this.safeString(expiryParts, 0);
1933
- const dayPart = this.safeString(expiryParts, 2);
1934
- const year = yearPart.slice(2, 4);
1935
- const month = this.safeString(expiryParts, 1);
1936
- const day = dayPart.slice(0, 2);
1937
- const expiryString = year + month + day;
1938
- type = 'future';
1939
- future = true;
1940
- symbol = symbol + ':' + settle + '-' + expiryString;
1941
- }
1942
- contract = true;
1943
- inverse = (base === settle);
1944
- linear = !inverse;
1945
- const priceDecimals = this.safeInteger(market, 'pricePlace');
1946
- const amountDecimals = this.safeInteger(market, 'volumePlace');
1947
- const priceStep = this.safeString(market, 'priceEndStep');
1948
- const amountStep = this.safeString(market, 'sizeMultiplier');
1949
- const precise = new Precise(priceStep);
1950
- precise.decimals = Math.max(precise.decimals, priceDecimals);
1951
- precise.reduce();
1952
- const priceString = precise.toString();
1953
- pricePrecision = this.parseNumber(priceString);
1954
- const preciseAmount = new Precise(amountStep);
1955
- preciseAmount.decimals = Math.max(preciseAmount.decimals, amountDecimals);
1956
- preciseAmount.reduce();
1957
- const amountString = preciseAmount.toString();
1958
- amountPrecision = this.parseNumber(amountString);
1959
- marginModes = {
1960
- 'cross': true,
1961
- 'isolated': true,
1962
- };
1963
- }
1964
- const status = this.safeString2(market, 'status', 'symbolStatus');
1965
- let active = undefined;
1966
- if (status !== undefined) {
1967
- active = ((status === 'online') || (status === 'normal'));
1968
- }
1969
- let minCost = undefined;
1970
- if (quote === 'USDT') {
1971
- minCost = this.safeNumber(market, 'minTradeUSDT');
1972
- }
1973
- const contractSize = contract ? 1 : undefined;
1974
- return {
1975
- 'id': marketId,
1976
- 'symbol': symbol,
1977
- 'base': base,
1978
- 'quote': quote,
1979
- 'settle': settle,
1980
- 'baseId': baseId,
1981
- 'quoteId': quoteId,
1982
- 'settleId': settleId,
1983
- 'type': type,
1984
- 'spot': spot,
1985
- 'margin': spot && isMarginTradingAllowed,
1986
- 'marginModes': marginModes,
1987
- 'swap': swap,
1988
- 'future': future,
1989
- 'option': false,
1990
- 'active': active,
1991
- 'contract': contract,
1992
- 'linear': linear,
1993
- 'inverse': inverse,
1994
- 'taker': this.safeNumber(market, 'takerFeeRate'),
1995
- 'maker': this.safeNumber(market, 'makerFeeRate'),
1996
- 'contractSize': contractSize,
1997
- 'expiry': expiry,
1998
- 'expiryDatetime': expiryDatetime,
1999
- 'strike': undefined,
2000
- 'optionType': undefined,
2001
- 'precision': {
2002
- 'amount': amountPrecision,
2003
- 'price': pricePrecision,
2004
- },
2005
- 'limits': {
2006
- 'leverage': {
2007
- 'min': this.safeNumber(market, 'minLever'),
2008
- 'max': this.safeNumber(market, 'maxLever'),
2009
- },
2010
- 'amount': {
2011
- 'min': this.safeNumber2(market, 'minTradeNum', 'minTradeAmount'),
2012
- 'max': this.safeNumber(market, 'maxTradeAmount'),
2013
- },
2014
- 'price': {
2015
- 'min': undefined,
2016
- 'max': undefined,
2305
+ const status = this.safeString(market, 'status');
2306
+ let active = undefined;
2307
+ if (status !== undefined) {
2308
+ active = ((status === 'online') || (status === 'normal'));
2309
+ }
2310
+ const contractSize = contract ? 1 : undefined;
2311
+ result.push(this.safeMarketStructure({
2312
+ 'id': marketId,
2313
+ 'symbol': symbol,
2314
+ 'base': base,
2315
+ 'quote': quote,
2316
+ 'settle': settle,
2317
+ 'baseId': baseId,
2318
+ 'quoteId': quoteId,
2319
+ 'settleId': settleId,
2320
+ 'type': type,
2321
+ 'spot': spot,
2322
+ 'margin': spot && isMarginTradingAllowed,
2323
+ 'marginModes': marginModes,
2324
+ 'swap': swap,
2325
+ 'future': future,
2326
+ 'option': false,
2327
+ 'active': active,
2328
+ 'contract': contract,
2329
+ 'linear': linear,
2330
+ 'inverse': inverse,
2331
+ 'taker': this.safeNumber(market, 'takerFeeRate'),
2332
+ 'maker': this.safeNumber(market, 'makerFeeRate'),
2333
+ 'contractSize': contractSize,
2334
+ 'expiry': expiry,
2335
+ 'expiryDatetime': expiryDatetime,
2336
+ 'strike': undefined,
2337
+ 'optionType': undefined,
2338
+ 'precision': {
2339
+ 'amount': amountPrecision,
2340
+ 'price': pricePrecision,
2017
2341
  },
2018
- 'cost': {
2019
- 'min': minCost,
2020
- 'max': undefined,
2342
+ 'limits': {
2343
+ 'leverage': {
2344
+ 'min': this.safeNumber(market, 'minLeverage'),
2345
+ 'max': this.safeNumber(market, 'maxLeverage'),
2346
+ },
2347
+ 'amount': {
2348
+ 'min': this.safeNumber(market, 'minOrderQty'),
2349
+ 'max': this.safeNumber(market, 'maxOrderQty'),
2350
+ },
2351
+ 'price': {
2352
+ 'min': undefined,
2353
+ 'max': undefined,
2354
+ },
2355
+ 'cost': {
2356
+ 'min': undefined,
2357
+ 'max': undefined,
2358
+ },
2021
2359
  },
2022
- },
2023
- 'created': this.safeInteger(market, 'launchTime'),
2024
- 'info': market,
2025
- };
2360
+ 'created': this.safeInteger(market, 'launchTime'),
2361
+ 'info': market,
2362
+ }));
2363
+ }
2364
+ return result;
2026
2365
  }
2027
2366
  /**
2028
2367
  * @method