ccxt 4.2.94 → 4.2.96
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/README.md +3 -3
- package/build.sh +1 -1
- package/dist/ccxt.browser.js +964 -406
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/base/errors.js +25 -64
- package/dist/cjs/src/base/functions/crypto.js +15 -2
- package/dist/cjs/src/base/functions/rsa.js +2 -2
- package/dist/cjs/src/base/ws/OrderBookSide.js +5 -0
- package/dist/cjs/src/bitstamp.js +6 -0
- package/dist/cjs/src/coinbase.js +615 -102
- package/dist/cjs/src/coinex.js +61 -55
- package/dist/cjs/src/gemini.js +29 -10
- package/dist/cjs/src/htx.js +127 -125
- package/dist/cjs/src/okx.js +40 -40
- package/dist/cjs/src/pro/coinbase.js +37 -4
- package/js/ccxt.d.ts +3 -3
- package/js/ccxt.js +3 -3
- package/js/src/abstract/bitstamp.d.ts +6 -0
- package/js/src/abstract/coinbase.d.ts +1 -0
- package/js/src/base/errorHierarchy.d.ts +1 -1
- package/js/src/base/errorHierarchy.js +1 -1
- package/js/src/base/errors.d.ts +26 -26
- package/js/src/base/errors.js +26 -66
- package/js/src/base/functions/crypto.d.ts +1 -1
- package/js/src/base/functions/crypto.js +15 -2
- package/js/src/base/functions/rsa.js +2 -2
- package/js/src/base/types.d.ts +1 -0
- package/js/src/base/ws/OrderBook.d.ts +8 -0
- package/js/src/base/ws/OrderBook.js +1 -6
- package/js/src/base/ws/OrderBookSide.d.ts +9 -3
- package/js/src/base/ws/OrderBookSide.js +6 -1
- package/js/src/bitstamp.js +6 -0
- package/js/src/coinbase.d.ts +8 -1
- package/js/src/coinbase.js +616 -103
- package/js/src/coinex.js +61 -55
- package/js/src/gemini.js +29 -10
- package/js/src/htx.d.ts +1 -0
- package/js/src/htx.js +128 -126
- package/js/src/okx.js +40 -40
- package/js/src/pro/coinbase.js +37 -4
- package/package.json +1 -1
- package/skip-tests.json +2 -0
package/dist/cjs/src/coinex.js
CHANGED
|
@@ -1088,8 +1088,8 @@ class coinex extends coinex$1 {
|
|
|
1088
1088
|
* @method
|
|
1089
1089
|
* @name coinex#fetchOrderBook
|
|
1090
1090
|
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
1091
|
-
* @see https://
|
|
1092
|
-
* @see https://
|
|
1091
|
+
* @see https://docs.coinex.com/api/v2/spot/market/http/list-market-depth
|
|
1092
|
+
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-depth
|
|
1093
1093
|
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
1094
1094
|
* @param {int} [limit] the maximum amount of order book entries to return
|
|
1095
1095
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
@@ -1101,65 +1101,71 @@ class coinex extends coinex$1 {
|
|
|
1101
1101
|
limit = 20; // default
|
|
1102
1102
|
}
|
|
1103
1103
|
const request = {
|
|
1104
|
-
'market':
|
|
1105
|
-
'
|
|
1106
|
-
'
|
|
1104
|
+
'market': market['id'],
|
|
1105
|
+
'limit': limit,
|
|
1106
|
+
'interval': '0',
|
|
1107
1107
|
};
|
|
1108
1108
|
let response = undefined;
|
|
1109
1109
|
if (market['swap']) {
|
|
1110
|
-
response = await this.
|
|
1110
|
+
response = await this.v2PublicGetFuturesDepth(this.extend(request, params));
|
|
1111
|
+
//
|
|
1112
|
+
// {
|
|
1113
|
+
// "code": 0,
|
|
1114
|
+
// "data": {
|
|
1115
|
+
// "depth": {
|
|
1116
|
+
// "asks": [
|
|
1117
|
+
// ["70851.94", "0.2119"],
|
|
1118
|
+
// ["70851.95", "0.0004"],
|
|
1119
|
+
// ["70851.96", "0.0004"]
|
|
1120
|
+
// ],
|
|
1121
|
+
// "bids": [
|
|
1122
|
+
// ["70851.93", "1.0314"],
|
|
1123
|
+
// ["70850.93", "0.0021"],
|
|
1124
|
+
// ["70850.42", "0.0306"]
|
|
1125
|
+
// ],
|
|
1126
|
+
// "checksum": 2956436260,
|
|
1127
|
+
// "last": "70851.94",
|
|
1128
|
+
// "updated_at": 1712824003252
|
|
1129
|
+
// },
|
|
1130
|
+
// "is_full": true,
|
|
1131
|
+
// "market": "BTCUSDT"
|
|
1132
|
+
// },
|
|
1133
|
+
// "message": "OK"
|
|
1134
|
+
// }
|
|
1135
|
+
//
|
|
1111
1136
|
}
|
|
1112
1137
|
else {
|
|
1113
|
-
response = await this.
|
|
1138
|
+
response = await this.v2PublicGetSpotDepth(this.extend(request, params));
|
|
1139
|
+
//
|
|
1140
|
+
// {
|
|
1141
|
+
// "code": 0,
|
|
1142
|
+
// "data": {
|
|
1143
|
+
// "depth": {
|
|
1144
|
+
// "asks": [
|
|
1145
|
+
// ["70875.31", "0.28670282"],
|
|
1146
|
+
// ["70875.32", "0.31008114"],
|
|
1147
|
+
// ["70875.42", "0.05876653"]
|
|
1148
|
+
// ],
|
|
1149
|
+
// "bids": [
|
|
1150
|
+
// ["70855.3", "0.00632222"],
|
|
1151
|
+
// ["70855.29", "0.36216834"],
|
|
1152
|
+
// ["70855.17", "0.10166802"]
|
|
1153
|
+
// ],
|
|
1154
|
+
// "checksum": 2313816665,
|
|
1155
|
+
// "last": "70857.19",
|
|
1156
|
+
// "updated_at": 1712823790987
|
|
1157
|
+
// },
|
|
1158
|
+
// "is_full": true,
|
|
1159
|
+
// "market": "BTCUSDT"
|
|
1160
|
+
// },
|
|
1161
|
+
// "message": "OK"
|
|
1162
|
+
// }
|
|
1163
|
+
//
|
|
1114
1164
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
// "code": 0,
|
|
1120
|
-
// "data": {
|
|
1121
|
-
// "asks": [
|
|
1122
|
-
// ["41056.33", "0.31727613"],
|
|
1123
|
-
// ["41056.34", "1.05657294"],
|
|
1124
|
-
// ["41056.35", "0.02346648"]
|
|
1125
|
-
// ],
|
|
1126
|
-
// "bids": [
|
|
1127
|
-
// ["41050.61", "0.40618608"],
|
|
1128
|
-
// ["41046.98", "0.13800000"],
|
|
1129
|
-
// ["41046.56", "0.22579234"]
|
|
1130
|
-
// ],
|
|
1131
|
-
// "last": "41050.61",
|
|
1132
|
-
// "time": 1650573220346
|
|
1133
|
-
// },
|
|
1134
|
-
// "message": "OK"
|
|
1135
|
-
// }
|
|
1136
|
-
//
|
|
1137
|
-
// Swap
|
|
1138
|
-
//
|
|
1139
|
-
// {
|
|
1140
|
-
// "code": 0,
|
|
1141
|
-
// "data": {
|
|
1142
|
-
// "asks": [
|
|
1143
|
-
// ["40620.90", "0.0384"],
|
|
1144
|
-
// ["40625.50", "0.0219"],
|
|
1145
|
-
// ["40625.90", "0.3506"]
|
|
1146
|
-
// ],
|
|
1147
|
-
// "bids": [
|
|
1148
|
-
// ["40620.89", "19.6861"],
|
|
1149
|
-
// ["40620.80", "0.0012"],
|
|
1150
|
-
// ["40619.87", "0.0365"]
|
|
1151
|
-
// ],
|
|
1152
|
-
// "last": "40620.89",
|
|
1153
|
-
// "time": 1650587672406,
|
|
1154
|
-
// "sign_price": "40619.32",
|
|
1155
|
-
// "index_price": "40609.93"
|
|
1156
|
-
// },
|
|
1157
|
-
// "message": "OK"
|
|
1158
|
-
// }
|
|
1159
|
-
//
|
|
1160
|
-
const result = this.safeValue(response, 'data', {});
|
|
1161
|
-
const timestamp = this.safeInteger(result, 'time');
|
|
1162
|
-
return this.parseOrderBook(result, symbol, timestamp);
|
|
1165
|
+
const data = this.safeDict(response, 'data', {});
|
|
1166
|
+
const depth = this.safeDict(data, 'depth', {});
|
|
1167
|
+
const timestamp = this.safeInteger(depth, 'updated_at');
|
|
1168
|
+
return this.parseOrderBook(depth, symbol, timestamp);
|
|
1163
1169
|
}
|
|
1164
1170
|
parseTrade(trade, market = undefined) {
|
|
1165
1171
|
//
|
package/dist/cjs/src/gemini.js
CHANGED
|
@@ -285,7 +285,13 @@ class gemini extends gemini$1 {
|
|
|
285
285
|
'ATOM': 'cosmos',
|
|
286
286
|
'DOT': 'polkadot',
|
|
287
287
|
},
|
|
288
|
-
'nonce': 'milliseconds',
|
|
288
|
+
'nonce': 'milliseconds',
|
|
289
|
+
'conflictingMarkets': {
|
|
290
|
+
'paxgusd': {
|
|
291
|
+
'base': 'PAXG',
|
|
292
|
+
'quote': 'USD',
|
|
293
|
+
},
|
|
294
|
+
},
|
|
289
295
|
},
|
|
290
296
|
});
|
|
291
297
|
}
|
|
@@ -679,16 +685,29 @@ class gemini extends gemini$1 {
|
|
|
679
685
|
const marketIdUpper = marketId.toUpperCase();
|
|
680
686
|
const isPerp = (marketIdUpper.indexOf('PERP') >= 0);
|
|
681
687
|
const marketIdWithoutPerp = marketIdUpper.replace('PERP', '');
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
688
|
+
const conflictingMarkets = this.safeDict(this.options, 'conflictingMarkets', {});
|
|
689
|
+
const lowerCaseId = marketIdWithoutPerp.toLowerCase();
|
|
690
|
+
if (lowerCaseId in conflictingMarkets) {
|
|
691
|
+
const conflictingMarket = conflictingMarkets[lowerCaseId];
|
|
692
|
+
baseId = conflictingMarket['base'];
|
|
693
|
+
quoteId = conflictingMarket['quote'];
|
|
694
|
+
if (isPerp) {
|
|
695
|
+
settleId = conflictingMarket['quote'];
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
const quoteCurrencies = this.handleOption('fetchMarketsFromAPI', 'quoteCurrencies', []);
|
|
700
|
+
for (let i = 0; i < quoteCurrencies.length; i++) {
|
|
701
|
+
const quoteCurrency = quoteCurrencies[i];
|
|
702
|
+
if (marketIdWithoutPerp.endsWith(quoteCurrency)) {
|
|
703
|
+
const quoteLength = this.parseToInt(-1 * quoteCurrency.length);
|
|
704
|
+
baseId = marketIdWithoutPerp.slice(0, quoteLength);
|
|
705
|
+
quoteId = quoteCurrency;
|
|
706
|
+
if (isPerp) {
|
|
707
|
+
settleId = quoteCurrency; // always same
|
|
708
|
+
}
|
|
709
|
+
break;
|
|
690
710
|
}
|
|
691
|
-
break;
|
|
692
711
|
}
|
|
693
712
|
}
|
|
694
713
|
}
|
package/dist/cjs/src/htx.js
CHANGED
|
@@ -940,14 +940,8 @@ class htx extends htx$1 {
|
|
|
940
940
|
'fetchMarkets': {
|
|
941
941
|
'types': {
|
|
942
942
|
'spot': true,
|
|
943
|
-
'
|
|
944
|
-
|
|
945
|
-
'inverse': true,
|
|
946
|
-
},
|
|
947
|
-
'swap': {
|
|
948
|
-
'linear': true,
|
|
949
|
-
'inverse': true,
|
|
950
|
-
},
|
|
943
|
+
'linear': true,
|
|
944
|
+
'inverse': true,
|
|
951
945
|
},
|
|
952
946
|
},
|
|
953
947
|
'fetchOHLCV': {
|
|
@@ -1614,25 +1608,23 @@ class htx extends htx$1 {
|
|
|
1614
1608
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1615
1609
|
* @returns {object[]} an array of objects representing market data
|
|
1616
1610
|
*/
|
|
1617
|
-
|
|
1618
|
-
|
|
1611
|
+
let types = undefined;
|
|
1612
|
+
[types, params] = this.handleOptionAndParams(params, 'fetchMarkets', 'types', {});
|
|
1619
1613
|
let allMarkets = [];
|
|
1620
1614
|
let promises = [];
|
|
1621
1615
|
const keys = Object.keys(types);
|
|
1622
1616
|
for (let i = 0; i < keys.length; i++) {
|
|
1623
|
-
const
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
promises.push(this.fetchMarketsByTypeAndSubType(type, subType, params));
|
|
1635
|
-
}
|
|
1617
|
+
const key = keys[i];
|
|
1618
|
+
if (this.safeBool(types, key)) {
|
|
1619
|
+
if (key === 'spot') {
|
|
1620
|
+
promises.push(this.fetchMarketsByTypeAndSubType('spot', undefined, params));
|
|
1621
|
+
}
|
|
1622
|
+
else if (key === 'linear') {
|
|
1623
|
+
promises.push(this.fetchMarketsByTypeAndSubType(undefined, 'linear', params));
|
|
1624
|
+
}
|
|
1625
|
+
else if (key === 'inverse') {
|
|
1626
|
+
promises.push(this.fetchMarketsByTypeAndSubType('swap', 'inverse', params));
|
|
1627
|
+
promises.push(this.fetchMarketsByTypeAndSubType('future', 'inverse', params));
|
|
1636
1628
|
}
|
|
1637
1629
|
}
|
|
1638
1630
|
}
|
|
@@ -1643,35 +1635,25 @@ class htx extends htx$1 {
|
|
|
1643
1635
|
return allMarkets;
|
|
1644
1636
|
}
|
|
1645
1637
|
async fetchMarketsByTypeAndSubType(type, subType, params = {}) {
|
|
1646
|
-
const
|
|
1647
|
-
const spot = (type === 'spot');
|
|
1648
|
-
const contract = (type !== 'spot');
|
|
1649
|
-
const future = (type === 'future');
|
|
1650
|
-
const swap = (type === 'swap');
|
|
1651
|
-
let linear = undefined;
|
|
1652
|
-
let inverse = undefined;
|
|
1638
|
+
const isSpot = (type === 'spot');
|
|
1653
1639
|
const request = {};
|
|
1654
1640
|
let response = undefined;
|
|
1655
|
-
if (
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
if (future) {
|
|
1660
|
-
request['business_type'] = 'futures';
|
|
1661
|
-
}
|
|
1662
|
-
response = await this.contractPublicGetLinearSwapApiV1SwapContractInfo(this.extend(request, query));
|
|
1641
|
+
if (!isSpot) {
|
|
1642
|
+
if (subType === 'linear') {
|
|
1643
|
+
request['business_type'] = 'all'; // override default to fetch all linear markets
|
|
1644
|
+
response = await this.contractPublicGetLinearSwapApiV1SwapContractInfo(this.extend(request, params));
|
|
1663
1645
|
}
|
|
1664
|
-
else if (inverse) {
|
|
1665
|
-
if (future) {
|
|
1666
|
-
response = await this.contractPublicGetApiV1ContractContractInfo(this.extend(request,
|
|
1646
|
+
else if (subType === 'inverse') {
|
|
1647
|
+
if (type === 'future') {
|
|
1648
|
+
response = await this.contractPublicGetApiV1ContractContractInfo(this.extend(request, params));
|
|
1667
1649
|
}
|
|
1668
|
-
else if (swap) {
|
|
1669
|
-
response = await this.contractPublicGetSwapApiV1SwapContractInfo(this.extend(request,
|
|
1650
|
+
else if (type === 'swap') {
|
|
1651
|
+
response = await this.contractPublicGetSwapApiV1SwapContractInfo(this.extend(request, params));
|
|
1670
1652
|
}
|
|
1671
1653
|
}
|
|
1672
1654
|
}
|
|
1673
1655
|
else {
|
|
1674
|
-
response = await this.spotPublicGetV1CommonSymbols(this.extend(request,
|
|
1656
|
+
response = await this.spotPublicGetV1CommonSymbols(this.extend(request, params));
|
|
1675
1657
|
}
|
|
1676
1658
|
//
|
|
1677
1659
|
// spot
|
|
@@ -1711,75 +1693,58 @@ class htx extends htx$1 {
|
|
|
1711
1693
|
// ]
|
|
1712
1694
|
// }
|
|
1713
1695
|
//
|
|
1714
|
-
// inverse future
|
|
1696
|
+
// inverse (swap & future)
|
|
1715
1697
|
//
|
|
1716
1698
|
// {
|
|
1717
1699
|
// "status":"ok",
|
|
1718
1700
|
// "data":[
|
|
1719
1701
|
// {
|
|
1720
1702
|
// "symbol":"BTC",
|
|
1721
|
-
// "contract_code":"BTC211126",
|
|
1722
|
-
// "contract_type":"this_week",
|
|
1723
|
-
// "contract_size":100
|
|
1724
|
-
// "price_tick":0.
|
|
1725
|
-
// "delivery_date":"20211126",
|
|
1726
|
-
// "delivery_time":"1637913600000",
|
|
1703
|
+
// "contract_code":"BTC211126", /// BTC-USD in swap
|
|
1704
|
+
// "contract_type":"this_week", // only in future
|
|
1705
|
+
// "contract_size":100,
|
|
1706
|
+
// "price_tick":0.1,
|
|
1707
|
+
// "delivery_date":"20211126", // only in future
|
|
1708
|
+
// "delivery_time":"1637913600000", // empty in swap
|
|
1727
1709
|
// "create_date":"20211112",
|
|
1728
1710
|
// "contract_status":1,
|
|
1729
|
-
// "settlement_time":"1637481600000"
|
|
1711
|
+
// "settlement_time":"1637481600000" // only in future
|
|
1712
|
+
// "settlement_date":"16xxxxxxxxxxx" // only in swap
|
|
1730
1713
|
// },
|
|
1714
|
+
// ...
|
|
1731
1715
|
// ],
|
|
1732
1716
|
// "ts":1637474595140
|
|
1733
1717
|
// }
|
|
1734
1718
|
//
|
|
1735
|
-
// linear
|
|
1719
|
+
// linear (swap & future)
|
|
1736
1720
|
//
|
|
1737
1721
|
// {
|
|
1738
1722
|
// "status":"ok",
|
|
1739
1723
|
// "data":[
|
|
1740
1724
|
// {
|
|
1741
1725
|
// "symbol":"BTC",
|
|
1742
|
-
// "contract_code":"BTC-USDT-211231",
|
|
1743
|
-
// "contract_size":0.
|
|
1744
|
-
// "price_tick":0.
|
|
1745
|
-
// "delivery_date":"20211231",
|
|
1746
|
-
// "delivery_time":"1640937600000",
|
|
1726
|
+
// "contract_code":"BTC-USDT-211231", // or "BTC-USDT" in swap
|
|
1727
|
+
// "contract_size":0.001,
|
|
1728
|
+
// "price_tick":0.1,
|
|
1729
|
+
// "delivery_date":"20211231", // empty in swap
|
|
1730
|
+
// "delivery_time":"1640937600000", // empty in swap
|
|
1747
1731
|
// "create_date":"20211228",
|
|
1748
1732
|
// "contract_status":1,
|
|
1749
1733
|
// "settlement_date":"1640764800000",
|
|
1750
|
-
// "support_margin_mode":"cross",
|
|
1751
|
-
// "business_type":"futures",
|
|
1734
|
+
// "support_margin_mode":"cross", // "all" or "cross"
|
|
1735
|
+
// "business_type":"futures", // "swap" or "futures"
|
|
1752
1736
|
// "pair":"BTC-USDT",
|
|
1753
|
-
// "contract_type":"this_week" // next_week, quarter
|
|
1754
|
-
//
|
|
1737
|
+
// "contract_type":"this_week", // "swap", "this_week", "next_week", "quarter"
|
|
1738
|
+
// "trade_partition":"USDT",
|
|
1739
|
+
// }
|
|
1755
1740
|
// ],
|
|
1756
1741
|
// "ts":1640736207263
|
|
1757
1742
|
// }
|
|
1758
1743
|
//
|
|
1759
|
-
|
|
1760
|
-
//
|
|
1761
|
-
// {
|
|
1762
|
-
// "status":"ok",
|
|
1763
|
-
// "data":[
|
|
1764
|
-
// {
|
|
1765
|
-
// "symbol":"BTC",
|
|
1766
|
-
// "contract_code":"BTC-USDT",
|
|
1767
|
-
// "contract_size":0.001000000000000000,
|
|
1768
|
-
// "price_tick":0.100000000000000000,
|
|
1769
|
-
// "delivery_time":"",
|
|
1770
|
-
// "create_date":"20201021",
|
|
1771
|
-
// "contract_status":1,
|
|
1772
|
-
// "settlement_date":"1637481600000",
|
|
1773
|
-
// "support_margin_mode":"all", // isolated
|
|
1774
|
-
// },
|
|
1775
|
-
// ],
|
|
1776
|
-
// "ts":1637474774467
|
|
1777
|
-
// }
|
|
1778
|
-
//
|
|
1779
|
-
const markets = this.safeValue(response, 'data', []);
|
|
1744
|
+
const markets = this.safeList(response, 'data', []);
|
|
1780
1745
|
const numMarkets = markets.length;
|
|
1781
1746
|
if (numMarkets < 1) {
|
|
1782
|
-
throw new errors.
|
|
1747
|
+
throw new errors.OperationFailed(this.id + ' fetchMarkets() returned an empty response: ' + this.json(response));
|
|
1783
1748
|
}
|
|
1784
1749
|
const result = [];
|
|
1785
1750
|
for (let i = 0; i < markets.length; i++) {
|
|
@@ -1789,16 +1754,31 @@ class htx extends htx$1 {
|
|
|
1789
1754
|
let settleId = undefined;
|
|
1790
1755
|
let id = undefined;
|
|
1791
1756
|
let lowercaseId = undefined;
|
|
1757
|
+
const contract = ('contract_code' in market);
|
|
1758
|
+
const spot = !contract;
|
|
1759
|
+
let swap = false;
|
|
1760
|
+
let future = false;
|
|
1761
|
+
let linear = undefined;
|
|
1762
|
+
let inverse = undefined;
|
|
1763
|
+
// check if parsed market is contract
|
|
1792
1764
|
if (contract) {
|
|
1793
1765
|
id = this.safeString(market, 'contract_code');
|
|
1794
1766
|
lowercaseId = id.toLowerCase();
|
|
1767
|
+
const delivery_date = this.safeString(market, 'delivery_date');
|
|
1768
|
+
const business_type = this.safeString(market, 'business_type');
|
|
1769
|
+
future = delivery_date !== undefined;
|
|
1770
|
+
swap = !future;
|
|
1771
|
+
linear = business_type !== undefined;
|
|
1772
|
+
inverse = !linear;
|
|
1795
1773
|
if (swap) {
|
|
1774
|
+
type = 'swap';
|
|
1796
1775
|
const parts = id.split('-');
|
|
1797
1776
|
baseId = this.safeStringLower(market, 'symbol');
|
|
1798
1777
|
quoteId = this.safeStringLower(parts, 1);
|
|
1799
1778
|
settleId = inverse ? baseId : quoteId;
|
|
1800
1779
|
}
|
|
1801
1780
|
else if (future) {
|
|
1781
|
+
type = 'future';
|
|
1802
1782
|
baseId = this.safeStringLower(market, 'symbol');
|
|
1803
1783
|
if (inverse) {
|
|
1804
1784
|
quoteId = 'USD';
|
|
@@ -1813,6 +1793,7 @@ class htx extends htx$1 {
|
|
|
1813
1793
|
}
|
|
1814
1794
|
}
|
|
1815
1795
|
else {
|
|
1796
|
+
type = 'spot';
|
|
1816
1797
|
baseId = this.safeString(market, 'base-currency');
|
|
1817
1798
|
quoteId = this.safeString(market, 'quote-currency');
|
|
1818
1799
|
id = baseId + quoteId;
|
|
@@ -1947,6 +1928,45 @@ class htx extends htx$1 {
|
|
|
1947
1928
|
}
|
|
1948
1929
|
return result;
|
|
1949
1930
|
}
|
|
1931
|
+
tryGetSymbolFromFutureMarkets(symbolOrMarketId) {
|
|
1932
|
+
if (symbolOrMarketId in this.markets) {
|
|
1933
|
+
return symbolOrMarketId;
|
|
1934
|
+
}
|
|
1935
|
+
// only on "future" market type (inverse & linear), market-id differs between "fetchMarkets" and "fetchTicker"
|
|
1936
|
+
// so we have to create a mapping
|
|
1937
|
+
// - market-id from fetchMarkts: `BTC-USDT-240419` (linear future) or `BTC240412` (inverse future)
|
|
1938
|
+
// - market-id from fetchTciker[s]: `BTC-USDT-CW` (linear future) or `BTC_CW` (inverse future)
|
|
1939
|
+
if (!('futureMarketIdsForSymbols' in this.options)) {
|
|
1940
|
+
this.options['futureMarketIdsForSymbols'] = {};
|
|
1941
|
+
}
|
|
1942
|
+
const futureMarketIdsForSymbols = this.safeDict(this.options, 'futureMarketIdsForSymbols', {});
|
|
1943
|
+
if (symbolOrMarketId in futureMarketIdsForSymbols) {
|
|
1944
|
+
return futureMarketIdsForSymbols[symbolOrMarketId];
|
|
1945
|
+
}
|
|
1946
|
+
const futureMarkets = this.filterBy(this.markets, 'future', true);
|
|
1947
|
+
const futuresCharsMaps = {
|
|
1948
|
+
'this_week': 'CW',
|
|
1949
|
+
'next_week': 'NW',
|
|
1950
|
+
'quarter': 'CQ',
|
|
1951
|
+
'next_quarter': 'NQ',
|
|
1952
|
+
};
|
|
1953
|
+
for (let i = 0; i < futureMarkets.length; i++) {
|
|
1954
|
+
const market = futureMarkets[i];
|
|
1955
|
+
const info = this.safeValue(market, 'info', {});
|
|
1956
|
+
const contractType = this.safeString(info, 'contract_type');
|
|
1957
|
+
const contractSuffix = futuresCharsMaps[contractType];
|
|
1958
|
+
// see comment on formats a bit above
|
|
1959
|
+
const constructedId = market['linear'] ? market['base'] + '-' + market['quote'] + '-' + contractSuffix : market['base'] + '_' + contractSuffix;
|
|
1960
|
+
if (constructedId === symbolOrMarketId) {
|
|
1961
|
+
const symbol = market['symbol'];
|
|
1962
|
+
this.options['futureMarketIdsForSymbols'][symbolOrMarketId] = symbol;
|
|
1963
|
+
return symbol;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
// if not found, just save it to avoid unnecessary future iterations
|
|
1967
|
+
this.options['futureMarketIdsForSymbols'][symbolOrMarketId] = symbolOrMarketId;
|
|
1968
|
+
return symbolOrMarketId;
|
|
1969
|
+
}
|
|
1950
1970
|
parseTicker(ticker, market = undefined) {
|
|
1951
1971
|
//
|
|
1952
1972
|
// fetchTicker
|
|
@@ -1994,7 +2014,8 @@ class htx extends htx$1 {
|
|
|
1994
2014
|
// }
|
|
1995
2015
|
//
|
|
1996
2016
|
const marketId = this.safeString2(ticker, 'symbol', 'contract_code');
|
|
1997
|
-
|
|
2017
|
+
let symbol = this.safeSymbol(marketId, market);
|
|
2018
|
+
symbol = this.tryGetSymbolFromFutureMarkets(symbol);
|
|
1998
2019
|
const timestamp = this.safeInteger2(ticker, 'ts', 'quoteTime');
|
|
1999
2020
|
let bid = undefined;
|
|
2000
2021
|
let bidVolume = undefined;
|
|
@@ -2137,7 +2158,7 @@ class htx extends htx$1 {
|
|
|
2137
2158
|
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-a-batch-of-market-data-overview
|
|
2138
2159
|
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-a-batch-of-market-data-overview
|
|
2139
2160
|
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-a-batch-of-market-data-overview-v2
|
|
2140
|
-
* @param {string[]
|
|
2161
|
+
* @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
|
2141
2162
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2142
2163
|
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
2143
2164
|
*/
|
|
@@ -2148,22 +2169,30 @@ class htx extends htx$1 {
|
|
|
2148
2169
|
if (first !== undefined) {
|
|
2149
2170
|
market = this.market(first);
|
|
2150
2171
|
}
|
|
2172
|
+
const isSubTypeRequested = ('subType' in params) || ('business_type' in params);
|
|
2151
2173
|
let type = undefined;
|
|
2152
2174
|
let subType = undefined;
|
|
2153
2175
|
[type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
|
|
2154
2176
|
[subType, params] = this.handleSubTypeAndParams('fetchTickers', market, params);
|
|
2155
2177
|
const request = {};
|
|
2178
|
+
const isSpot = (type === 'spot');
|
|
2156
2179
|
const future = (type === 'future');
|
|
2157
2180
|
const swap = (type === 'swap');
|
|
2158
2181
|
const linear = (subType === 'linear');
|
|
2159
2182
|
const inverse = (subType === 'inverse');
|
|
2160
|
-
params = this.omit(params, ['type', 'subType']);
|
|
2161
2183
|
let response = undefined;
|
|
2162
|
-
if (
|
|
2184
|
+
if (!isSpot || isSubTypeRequested) {
|
|
2163
2185
|
if (linear) {
|
|
2186
|
+
// independently of type, supports calling all linear symbols i.e. fetchTickers(undefined, {subType:'linear'})
|
|
2164
2187
|
if (future) {
|
|
2165
2188
|
request['business_type'] = 'futures';
|
|
2166
2189
|
}
|
|
2190
|
+
else if (swap) {
|
|
2191
|
+
request['business_type'] = 'swap';
|
|
2192
|
+
}
|
|
2193
|
+
else {
|
|
2194
|
+
request['business_type'] = 'all';
|
|
2195
|
+
}
|
|
2167
2196
|
response = await this.contractPublicGetLinearSwapExMarketDetailBatchMerged(this.extend(request, params));
|
|
2168
2197
|
}
|
|
2169
2198
|
else if (inverse) {
|
|
@@ -2173,6 +2202,12 @@ class htx extends htx$1 {
|
|
|
2173
2202
|
else if (swap) {
|
|
2174
2203
|
response = await this.contractPublicGetSwapExMarketDetailBatchMerged(this.extend(request, params));
|
|
2175
2204
|
}
|
|
2205
|
+
else {
|
|
2206
|
+
throw new errors.NotSupported(this.id + ' fetchTickers() you have to set params["type"] to either "swap" or "future" for inverse contracts');
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
else {
|
|
2210
|
+
throw new errors.NotSupported(this.id + ' fetchTickers() you have to set params["subType"] to either "linear" or "inverse" for contracts');
|
|
2176
2211
|
}
|
|
2177
2212
|
}
|
|
2178
2213
|
else {
|
|
@@ -2228,42 +2263,9 @@ class htx extends htx$1 {
|
|
|
2228
2263
|
// "ts":1637504679376
|
|
2229
2264
|
// }
|
|
2230
2265
|
//
|
|
2231
|
-
const
|
|
2232
|
-
const
|
|
2233
|
-
|
|
2234
|
-
for (let i = 0; i < tickers.length; i++) {
|
|
2235
|
-
const ticker = this.parseTicker(tickers[i]);
|
|
2236
|
-
// the market ids for linear futures are non-standard and differ from all the other endpoints
|
|
2237
|
-
// we are doing a linear-matching here
|
|
2238
|
-
if (future && linear) {
|
|
2239
|
-
for (let j = 0; j < this.symbols.length; j++) {
|
|
2240
|
-
const symbolInner = this.symbols[j];
|
|
2241
|
-
const marketInner = this.market(symbolInner);
|
|
2242
|
-
const contractType = this.safeString(marketInner['info'], 'contract_type');
|
|
2243
|
-
if ((contractType === 'this_week') && (ticker['symbol'] === (marketInner['baseId'] + '-' + marketInner['quoteId'] + '-CW'))) {
|
|
2244
|
-
ticker['symbol'] = marketInner['symbol'];
|
|
2245
|
-
break;
|
|
2246
|
-
}
|
|
2247
|
-
else if ((contractType === 'next_week') && (ticker['symbol'] === (marketInner['baseId'] + '-' + marketInner['quoteId'] + '-NW'))) {
|
|
2248
|
-
ticker['symbol'] = marketInner['symbol'];
|
|
2249
|
-
break;
|
|
2250
|
-
}
|
|
2251
|
-
else if ((contractType === 'this_quarter') && (ticker['symbol'] === (marketInner['baseId'] + '-' + marketInner['quoteId'] + '-CQ'))) {
|
|
2252
|
-
ticker['symbol'] = marketInner['symbol'];
|
|
2253
|
-
break;
|
|
2254
|
-
}
|
|
2255
|
-
else if ((contractType === 'next_quarter') && (ticker['symbol'] === (marketInner['baseId'] + '-' + marketInner['quoteId'] + '-NQ'))) {
|
|
2256
|
-
ticker['symbol'] = marketInner['symbol'];
|
|
2257
|
-
break;
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
const symbol = ticker['symbol'];
|
|
2262
|
-
ticker['timestamp'] = timestamp;
|
|
2263
|
-
ticker['datetime'] = this.iso8601(timestamp);
|
|
2264
|
-
result[symbol] = ticker;
|
|
2265
|
-
}
|
|
2266
|
-
return this.filterByArrayTickers(result, 'symbol', symbols);
|
|
2266
|
+
const rawTickers = this.safeList2(response, 'data', 'ticks', []);
|
|
2267
|
+
const tickers = this.parseTickers(rawTickers, symbols, params);
|
|
2268
|
+
return this.filterByArrayTickers(tickers, 'symbol', symbols);
|
|
2267
2269
|
}
|
|
2268
2270
|
async fetchLastPrices(symbols = undefined, params = {}) {
|
|
2269
2271
|
/**
|
|
@@ -2273,7 +2275,7 @@ class htx extends htx$1 {
|
|
|
2273
2275
|
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb81024-77b5-11ed-9966-0242ac110003 linear swap & linear future
|
|
2274
2276
|
* @see https://www.htx.com/en-us/opend/newApiPages/?id=28c2e8fc-77ae-11ed-9966-0242ac110003 inverse future
|
|
2275
2277
|
* @see https://www.htx.com/en-us/opend/newApiPages/?id=5d517ef5-77b6-11ed-9966-0242ac110003 inverse swap
|
|
2276
|
-
* @param {string[]
|
|
2278
|
+
* @param {string[]} [symbols] unified symbols of the markets to fetch the last prices
|
|
2277
2279
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2278
2280
|
* @returns {object} a dictionary of lastprices structures
|
|
2279
2281
|
*/
|