ccxt 4.1.76 → 4.1.78

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 (64) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.js +574 -185
  3. package/dist/ccxt.browser.min.js +5 -5
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/bingx.js +4 -1
  6. package/dist/cjs/src/bitget.js +71 -0
  7. package/dist/cjs/src/bitmart.js +9 -13
  8. package/dist/cjs/src/bitmex.js +6 -0
  9. package/dist/cjs/src/bitrue.js +27 -1
  10. package/dist/cjs/src/bitstamp.js +3 -2
  11. package/dist/cjs/src/bybit.js +2 -0
  12. package/dist/cjs/src/coinbase.js +47 -9
  13. package/dist/cjs/src/coinex.js +7 -11
  14. package/dist/cjs/src/gate.js +5 -0
  15. package/dist/cjs/src/hitbtc.js +326 -123
  16. package/dist/cjs/src/idex.js +10 -1
  17. package/dist/cjs/src/mexc.js +33 -5
  18. package/dist/cjs/src/okx.js +6 -10
  19. package/dist/cjs/src/pro/binance.js +10 -2
  20. package/dist/cjs/src/pro/binanceus.js +1 -0
  21. package/dist/cjs/src/pro/gate.js +1 -1
  22. package/dist/cjs/src/upbit.js +5 -5
  23. package/js/ccxt.d.ts +1 -1
  24. package/js/ccxt.js +1 -1
  25. package/js/src/abstract/bybit.d.ts +2 -0
  26. package/js/src/abstract/gate.d.ts +3 -0
  27. package/js/src/abstract/gateio.d.ts +3 -0
  28. package/js/src/abstract/okx.d.ts +2 -0
  29. package/js/src/base/Exchange.d.ts +1 -1
  30. package/js/src/bingx.js +4 -1
  31. package/js/src/bitget.d.ts +5 -4
  32. package/js/src/bitget.js +71 -0
  33. package/js/src/bitmart.js +9 -13
  34. package/js/src/bitmex.d.ts +1 -1
  35. package/js/src/bitmex.js +6 -0
  36. package/js/src/bitrue.d.ts +1 -0
  37. package/js/src/bitrue.js +27 -1
  38. package/js/src/bitstamp.js +3 -2
  39. package/js/src/bybit.js +2 -0
  40. package/js/src/coinbase.d.ts +1 -0
  41. package/js/src/coinbase.js +47 -9
  42. package/js/src/coinex.js +7 -11
  43. package/js/src/gate.js +5 -0
  44. package/js/src/hitbtc.js +326 -123
  45. package/js/src/idex.js +10 -1
  46. package/js/src/mexc.d.ts +1 -0
  47. package/js/src/mexc.js +33 -5
  48. package/js/src/okx.js +6 -10
  49. package/js/src/pro/binance.js +10 -2
  50. package/js/src/pro/binanceus.js +1 -0
  51. package/js/src/pro/gate.js +1 -1
  52. package/js/src/upbit.js +5 -5
  53. package/package.json +1 -1
  54. package/skip-tests.json +2 -1
  55. package/js/src/huobipro.d.ts +0 -4
  56. package/js/src/huobipro.js +0 -20
  57. package/js/src/mexc3.d.ts +0 -4
  58. package/js/src/mexc3.js +0 -17
  59. package/js/src/okex.d.ts +0 -4
  60. package/js/src/okex.js +0 -17
  61. package/js/src/okex5.d.ts +0 -4
  62. package/js/src/okex5.js +0 -17
  63. package/js/src/tidex.d.ts +0 -36
  64. package/js/src/tidex.js +0 -1068
package/js/src/hitbtc.js CHANGED
@@ -645,6 +645,7 @@ export default class hitbtc extends Exchange {
645
645
  * @method
646
646
  * @name hitbtc#fetchMarkets
647
647
  * @description retrieves data on all markets for hitbtc
648
+ * @see https://api.hitbtc.com/#symbols
648
649
  * @param {object} [params] extra parameters specific to the exchange API endpoint
649
650
  * @returns {object[]} an array of objects representing market data
650
651
  */
@@ -788,6 +789,7 @@ export default class hitbtc extends Exchange {
788
789
  * @method
789
790
  * @name hitbtc#fetchCurrencies
790
791
  * @description fetches all available currencies on an exchange
792
+ * @see https://api.hitbtc.com/#currencies
791
793
  * @param {object} [params] extra parameters specific to the exchange API endpoint
792
794
  * @returns {object} an associative dictionary of currencies
793
795
  */
@@ -908,6 +910,7 @@ export default class hitbtc extends Exchange {
908
910
  * @method
909
911
  * @name hitbtc#createDepositAddress
910
912
  * @description create a currency deposit address
913
+ * @see https://api.hitbtc.com/#generate-deposit-crypto-address
911
914
  * @param {string} code unified currency code of the currency for the deposit address
912
915
  * @param {object} [params] extra parameters specific to the exchange API endpoint
913
916
  * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
@@ -944,6 +947,7 @@ export default class hitbtc extends Exchange {
944
947
  * @method
945
948
  * @name hitbtc#fetchDepositAddress
946
949
  * @description fetch the deposit address for a currency associated with this account
950
+ * @see https://api.hitbtc.com/#get-deposit-crypto-address
947
951
  * @param {string} code unified currency code
948
952
  * @param {object} [params] extra parameters specific to the exchange API endpoint
949
953
  * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
@@ -998,6 +1002,9 @@ export default class hitbtc extends Exchange {
998
1002
  * @method
999
1003
  * @name hitbtc#fetchBalance
1000
1004
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
1005
+ * @see https://api.hitbtc.com/#wallet-balance
1006
+ * @see https://api.hitbtc.com/#get-spot-trading-balance
1007
+ * @see https://api.hitbtc.com/#get-trading-balance
1001
1008
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1002
1009
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1003
1010
  */
@@ -1200,6 +1207,9 @@ export default class hitbtc extends Exchange {
1200
1207
  * @method
1201
1208
  * @name hitbtc#fetchMyTrades
1202
1209
  * @description fetch all trades made by the user
1210
+ * @see https://api.hitbtc.com/#spot-trades-history
1211
+ * @see https://api.hitbtc.com/#futures-trades-history
1212
+ * @see https://api.hitbtc.com/#margin-trades-history
1203
1213
  * @param {string} symbol unified market symbol
1204
1214
  * @param {int} [since] the earliest time in ms to fetch trades for
1205
1215
  * @param {int} [limit] the maximum number of trades structures to retrieve
@@ -1222,17 +1232,28 @@ export default class hitbtc extends Exchange {
1222
1232
  request['from'] = since;
1223
1233
  }
1224
1234
  let marketType = undefined;
1235
+ let marginMode = undefined;
1236
+ let response = undefined;
1225
1237
  [marketType, params] = this.handleMarketTypeAndParams('fetchMyTrades', market, params);
1226
- let method = this.getSupportedMapping(marketType, {
1227
- 'spot': 'privateGetSpotHistoryTrade',
1228
- 'swap': 'privateGetFuturesHistoryTrade',
1229
- 'margin': 'privateGetMarginHistoryTrade',
1230
- });
1231
- const [marginMode, query] = this.handleMarginModeAndParams('fetchMyTrades', params);
1238
+ [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1239
+ params = this.omit(params, ['marginMode', 'margin']);
1232
1240
  if (marginMode !== undefined) {
1233
- method = 'privateGetMarginHistoryTrade';
1241
+ response = await this.privateGetMarginHistoryTrade(this.extend(request, params));
1242
+ }
1243
+ else {
1244
+ if (marketType === 'spot') {
1245
+ response = await this.privateGetSpotHistoryTrade(this.extend(request, params));
1246
+ }
1247
+ else if (marketType === 'swap') {
1248
+ response = await this.privateGetFuturesHistoryTrade(this.extend(request, params));
1249
+ }
1250
+ else if (marketType === 'margin') {
1251
+ response = await this.privateGetMarginHistoryTrade(this.extend(request, params));
1252
+ }
1253
+ else {
1254
+ throw new NotSupported(this.id + ' fetchMyTrades() not support this market type');
1255
+ }
1234
1256
  }
1235
- const response = await this[method](this.extend(request, query));
1236
1257
  return this.parseTrades(response, market, since, limit);
1237
1258
  }
1238
1259
  parseTrade(trade, market = undefined) {
@@ -1486,6 +1507,7 @@ export default class hitbtc extends Exchange {
1486
1507
  * @method
1487
1508
  * @name hitbtc#fetchDepositsWithdrawals
1488
1509
  * @description fetch history of deposits and withdrawals
1510
+ * @see https://api.hitbtc.com/#get-transactions-history
1489
1511
  * @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
1490
1512
  * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
1491
1513
  * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
@@ -1499,6 +1521,7 @@ export default class hitbtc extends Exchange {
1499
1521
  * @method
1500
1522
  * @name hitbtc#fetchDeposits
1501
1523
  * @description fetch all deposits made to an account
1524
+ * @see https://api.hitbtc.com/#get-transactions-history
1502
1525
  * @param {string} code unified currency code
1503
1526
  * @param {int} [since] the earliest time in ms to fetch deposits for
1504
1527
  * @param {int} [limit] the maximum number of deposits structures to retrieve
@@ -1512,6 +1535,7 @@ export default class hitbtc extends Exchange {
1512
1535
  * @method
1513
1536
  * @name hitbtc#fetchWithdrawals
1514
1537
  * @description fetch all withdrawals made from an account
1538
+ * @see https://api.hitbtc.com/#get-transactions-history
1515
1539
  * @param {string} code unified currency code
1516
1540
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
1517
1541
  * @param {int} [limit] the maximum number of withdrawals structures to retrieve
@@ -1599,6 +1623,8 @@ export default class hitbtc extends Exchange {
1599
1623
  * @method
1600
1624
  * @name hitbtc#fetchTradingFee
1601
1625
  * @description fetch the trading fees for a market
1626
+ * @see https://api.hitbtc.com/#get-trading-commission
1627
+ * @see https://api.hitbtc.com/#get-trading-commission-2
1602
1628
  * @param {string} symbol unified market symbol
1603
1629
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1604
1630
  * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
@@ -1608,11 +1634,16 @@ export default class hitbtc extends Exchange {
1608
1634
  const request = {
1609
1635
  'symbol': market['id'],
1610
1636
  };
1611
- const method = this.getSupportedMapping(market['type'], {
1612
- 'spot': 'privateGetSpotFeeSymbol',
1613
- 'swap': 'privateGetFuturesFeeSymbol',
1614
- });
1615
- const response = await this[method](this.extend(request, params));
1637
+ let response = undefined;
1638
+ if (market['type'] === 'spot') {
1639
+ response = await this.privateGetSpotFeeSymbol(this.extend(request, params));
1640
+ }
1641
+ else if (market['type'] === 'swap') {
1642
+ response = await this.privateGetFuturesFeeSymbol(this.extend(request, params));
1643
+ }
1644
+ else {
1645
+ throw new NotSupported(this.id + ' fetchTradingFee() not support this market type');
1646
+ }
1616
1647
  //
1617
1648
  // {
1618
1649
  // "take_rate":"0.0009",
@@ -1626,16 +1657,23 @@ export default class hitbtc extends Exchange {
1626
1657
  * @method
1627
1658
  * @name hitbtc#fetchTradingFees
1628
1659
  * @description fetch the trading fees for multiple markets
1660
+ * @see https://api.hitbtc.com/#get-all-trading-commissions
1661
+ * @see https://api.hitbtc.com/#get-all-trading-commissions-2
1629
1662
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1630
1663
  * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
1631
1664
  */
1632
1665
  await this.loadMarkets();
1633
1666
  const [marketType, query] = this.handleMarketTypeAndParams('fetchTradingFees', undefined, params);
1634
- const method = this.getSupportedMapping(marketType, {
1635
- 'spot': 'privateGetSpotFee',
1636
- 'swap': 'privateGetFuturesFee',
1637
- });
1638
- const response = await this[method](query);
1667
+ let response = undefined;
1668
+ if (marketType === 'spot') {
1669
+ response = await this.privateGetSpotFee(query);
1670
+ }
1671
+ else if (marketType === 'swap') {
1672
+ response = await this.privateGetFuturesFee(query);
1673
+ }
1674
+ else {
1675
+ throw new NotSupported(this.id + ' fetchTradingFees() not support this market type');
1676
+ }
1639
1677
  //
1640
1678
  // [
1641
1679
  // {
@@ -1771,6 +1809,9 @@ export default class hitbtc extends Exchange {
1771
1809
  * @method
1772
1810
  * @name hitbtc#fetchClosedOrders
1773
1811
  * @description fetches information on multiple closed orders made by the user
1812
+ * @see https://api.hitbtc.com/#spot-orders-history
1813
+ * @see https://api.hitbtc.com/#futures-orders-history
1814
+ * @see https://api.hitbtc.com/#margin-orders-history
1774
1815
  * @param {string} symbol unified market symbol of the market orders were made in
1775
1816
  * @param {int} [since] the earliest time in ms to fetch orders for
1776
1817
  * @param {int} [limit] the maximum number of orde structures to retrieve
@@ -1793,17 +1834,28 @@ export default class hitbtc extends Exchange {
1793
1834
  request['limit'] = limit;
1794
1835
  }
1795
1836
  let marketType = undefined;
1837
+ let marginMode = undefined;
1796
1838
  [marketType, params] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
1797
- let method = this.getSupportedMapping(marketType, {
1798
- 'spot': 'privateGetSpotHistoryOrder',
1799
- 'swap': 'privateGetFuturesHistoryOrder',
1800
- 'margin': 'privateGetMarginHistoryOrder',
1801
- });
1802
- const [marginMode, query] = this.handleMarginModeAndParams('fetchClosedOrders', params);
1839
+ [marginMode, params] = this.handleMarginModeAndParams('fetchClosedOrders', params);
1840
+ params = this.omit(params, ['marginMode', 'margin']);
1841
+ let response = undefined;
1803
1842
  if (marginMode !== undefined) {
1804
- method = 'privateGetMarginHistoryOrder';
1843
+ response = await this.privateGetMarginHistoryOrder(this.extend(request, params));
1844
+ }
1845
+ else {
1846
+ if (marketType === 'spot') {
1847
+ response = await this.privateGetSpotHistoryOrder(this.extend(request, params));
1848
+ }
1849
+ else if (marketType === 'swap') {
1850
+ response = await this.privateGetFuturesHistoryOrder(this.extend(request, params));
1851
+ }
1852
+ else if (marketType === 'margin') {
1853
+ response = await this.privateGetMarginHistoryOrder(this.extend(request, params));
1854
+ }
1855
+ else {
1856
+ throw new NotSupported(this.id + ' fetchClosedOrders() not support this market type');
1857
+ }
1805
1858
  }
1806
- const response = await this[method](this.extend(request, query));
1807
1859
  const parsed = this.parseOrders(response, market, since, limit);
1808
1860
  return this.filterByArray(parsed, 'status', ['closed', 'canceled'], false);
1809
1861
  }
@@ -1812,6 +1864,9 @@ export default class hitbtc extends Exchange {
1812
1864
  * @method
1813
1865
  * @name hitbtc#fetchOrder
1814
1866
  * @description fetches information on an order made by the user
1867
+ * @see https://api.hitbtc.com/#spot-orders-history
1868
+ * @see https://api.hitbtc.com/#futures-orders-history
1869
+ * @see https://api.hitbtc.com/#margin-orders-history
1815
1870
  * @param {string} symbol unified symbol of the market the order was made in
1816
1871
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1817
1872
  * @param {string} [params.marginMode] 'cross' or 'isolated' only 'isolated' is supported
@@ -1823,21 +1878,32 @@ export default class hitbtc extends Exchange {
1823
1878
  if (symbol !== undefined) {
1824
1879
  market = this.market(symbol);
1825
1880
  }
1881
+ const request = {
1882
+ 'client_order_id': id,
1883
+ };
1826
1884
  let marketType = undefined;
1885
+ let marginMode = undefined;
1827
1886
  [marketType, params] = this.handleMarketTypeAndParams('fetchOrder', market, params);
1828
- let method = this.getSupportedMapping(marketType, {
1829
- 'spot': 'privateGetSpotHistoryOrder',
1830
- 'swap': 'privateGetFuturesHistoryOrder',
1831
- 'margin': 'privateGetMarginHistoryOrder',
1832
- });
1833
- const [marginMode, query] = this.handleMarginModeAndParams('fetchOrder', params);
1887
+ [marginMode, params] = this.handleMarginModeAndParams('fetchOrder', params);
1888
+ params = this.omit(params, ['marginMode', 'margin']);
1889
+ let response = undefined;
1834
1890
  if (marginMode !== undefined) {
1835
- method = 'privateGetMarginHistoryOrder';
1891
+ response = await this.privateGetMarginHistoryOrder(this.extend(request, params));
1892
+ }
1893
+ else {
1894
+ if (marketType === 'spot') {
1895
+ response = await this.privateGetSpotHistoryOrder(this.extend(request, params));
1896
+ }
1897
+ else if (marketType === 'swap') {
1898
+ response = await this.privateGetFuturesHistoryOrder(this.extend(request, params));
1899
+ }
1900
+ else if (marketType === 'margin') {
1901
+ response = await this.privateGetMarginHistoryOrder(this.extend(request, params));
1902
+ }
1903
+ else {
1904
+ throw new NotSupported(this.id + ' fetchOrder() not support this market type');
1905
+ }
1836
1906
  }
1837
- const request = {
1838
- 'client_order_id': id,
1839
- };
1840
- const response = await this[method](this.extend(request, query));
1841
1907
  //
1842
1908
  // [
1843
1909
  // {
@@ -1865,6 +1931,9 @@ export default class hitbtc extends Exchange {
1865
1931
  * @method
1866
1932
  * @name hitbtc#fetchOrderTrades
1867
1933
  * @description fetch all the trades made from a single order
1934
+ * @see https://api.hitbtc.com/#spot-trades-history
1935
+ * @see https://api.hitbtc.com/#futures-trades-history
1936
+ * @see https://api.hitbtc.com/#margin-trades-history
1868
1937
  * @param {string} id order id
1869
1938
  * @param {string} symbol unified market symbol
1870
1939
  * @param {int} [since] the earliest time in ms to fetch trades for
@@ -1883,17 +1952,28 @@ export default class hitbtc extends Exchange {
1883
1952
  'order_id': id, // exchange assigned order id as oppose to the client order id
1884
1953
  };
1885
1954
  let marketType = undefined;
1955
+ let marginMode = undefined;
1886
1956
  [marketType, params] = this.handleMarketTypeAndParams('fetchOrderTrades', market, params);
1887
- let method = this.getSupportedMapping(marketType, {
1888
- 'spot': 'privateGetSpotHistoryTrade',
1889
- 'swap': 'privateGetFuturesHistoryTrade',
1890
- 'margin': 'privateGetMarginHistoryTrade',
1891
- });
1892
- const [marginMode, query] = this.handleMarginModeAndParams('fetchOrderTrades', params);
1957
+ [marginMode, params] = this.handleMarginModeAndParams('fetchOrderTrades', params);
1958
+ params = this.omit(params, ['marginMode', 'margin']);
1959
+ let response = undefined;
1893
1960
  if (marginMode !== undefined) {
1894
- method = 'privateGetMarginHistoryTrade';
1961
+ response = await this.privateGetMarginHistoryTrade(this.extend(request, params));
1962
+ }
1963
+ else {
1964
+ if (marketType === 'spot') {
1965
+ response = await this.privateGetSpotHistoryTrade(this.extend(request, params));
1966
+ }
1967
+ else if (marketType === 'swap') {
1968
+ response = await this.privateGetFuturesHistoryTrade(this.extend(request, params));
1969
+ }
1970
+ else if (marketType === 'margin') {
1971
+ response = await this.privateGetMarginHistoryTrade(this.extend(request, params));
1972
+ }
1973
+ else {
1974
+ throw new NotSupported(this.id + ' fetchOrderTrades() not support this market type');
1975
+ }
1895
1976
  }
1896
- const response = await this[method](this.extend(request, query));
1897
1977
  //
1898
1978
  // Spot
1899
1979
  //
@@ -1939,6 +2019,9 @@ export default class hitbtc extends Exchange {
1939
2019
  * @method
1940
2020
  * @name hitbtc#fetchOpenOrders
1941
2021
  * @description fetch all unfilled currently open orders
2022
+ * @see https://api.hitbtc.com/#get-all-active-spot-orders
2023
+ * @see https://api.hitbtc.com/#get-active-futures-orders
2024
+ * @see https://api.hitbtc.com/#get-active-margin-orders
1942
2025
  * @param {string} symbol unified market symbol
1943
2026
  * @param {int} [since] the earliest time in ms to fetch open orders for
1944
2027
  * @param {int} [limit] the maximum number of open orders structures to retrieve
@@ -1955,17 +2038,28 @@ export default class hitbtc extends Exchange {
1955
2038
  request['symbol'] = market['id'];
1956
2039
  }
1957
2040
  let marketType = undefined;
2041
+ let marginMode = undefined;
1958
2042
  [marketType, params] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
1959
- let method = this.getSupportedMapping(marketType, {
1960
- 'spot': 'privateGetSpotOrder',
1961
- 'swap': 'privateGetFuturesOrder',
1962
- 'margin': 'privateGetMarginOrder',
1963
- });
1964
- const [marginMode, query] = this.handleMarginModeAndParams('fetchOpenOrders', params);
2043
+ [marginMode, params] = this.handleMarginModeAndParams('fetchOpenOrders', params);
2044
+ params = this.omit(params, ['marginMode', 'margin']);
2045
+ let response = undefined;
1965
2046
  if (marginMode !== undefined) {
1966
- method = 'privateGetMarginOrder';
2047
+ response = await this.privateGetMarginOrder(this.extend(request, params));
2048
+ }
2049
+ else {
2050
+ if (marketType === 'spot') {
2051
+ response = await this.privateGetSpotOrder(this.extend(request, params));
2052
+ }
2053
+ else if (marketType === 'swap') {
2054
+ response = await this.privateGetFuturesOrder(this.extend(request, params));
2055
+ }
2056
+ else if (marketType === 'margin') {
2057
+ response = await this.privateGetMarginOrder(this.extend(request, params));
2058
+ }
2059
+ else {
2060
+ throw new NotSupported(this.id + ' fetchOpenOrders() not support this market type');
2061
+ }
1967
2062
  }
1968
- const response = await this[method](this.extend(request, query));
1969
2063
  //
1970
2064
  // [
1971
2065
  // {
@@ -1992,6 +2086,9 @@ export default class hitbtc extends Exchange {
1992
2086
  * @method
1993
2087
  * @name hitbtc#fetchOpenOrder
1994
2088
  * @description fetch an open order by it's id
2089
+ * @see https://api.hitbtc.com/#get-active-spot-order
2090
+ * @see https://api.hitbtc.com/#get-active-futures-order
2091
+ * @see https://api.hitbtc.com/#get-active-margin-order
1995
2092
  * @param {string} id order id
1996
2093
  * @param {string} symbol unified market symbol, default is undefined
1997
2094
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2004,21 +2101,32 @@ export default class hitbtc extends Exchange {
2004
2101
  if (symbol !== undefined) {
2005
2102
  market = this.market(symbol);
2006
2103
  }
2104
+ const request = {
2105
+ 'client_order_id': id,
2106
+ };
2007
2107
  let marketType = undefined;
2108
+ let marginMode = undefined;
2008
2109
  [marketType, params] = this.handleMarketTypeAndParams('fetchOpenOrder', market, params);
2009
- let method = this.getSupportedMapping(marketType, {
2010
- 'spot': 'privateGetSpotOrderClientOrderId',
2011
- 'swap': 'privateGetFuturesOrderClientOrderId',
2012
- 'margin': 'privateGetMarginOrderClientOrderId',
2013
- });
2014
- const [marginMode, query] = this.handleMarginModeAndParams('fetchOpenOrder', params);
2110
+ [marginMode, params] = this.handleMarginModeAndParams('fetchOpenOrder', params);
2111
+ params = this.omit(params, ['marginMode', 'margin']);
2112
+ let response = undefined;
2015
2113
  if (marginMode !== undefined) {
2016
- method = 'privateGetMarginOrderClientOrderId';
2114
+ response = await this.privateGetMarginOrderClientOrderId(this.extend(request, params));
2115
+ }
2116
+ else {
2117
+ if (marketType === 'spot') {
2118
+ response = await this.privateGetSpotOrderClientOrderId(this.extend(request, params));
2119
+ }
2120
+ else if (marketType === 'swap') {
2121
+ response = await this.privateGetFuturesOrderClientOrderId(this.extend(request, params));
2122
+ }
2123
+ else if (marketType === 'margin') {
2124
+ response = await this.privateGetMarginOrderClientOrderId(this.extend(request, params));
2125
+ }
2126
+ else {
2127
+ throw new NotSupported(this.id + ' fetchOpenOrder() not support this market type');
2128
+ }
2017
2129
  }
2018
- const request = {
2019
- 'client_order_id': id,
2020
- };
2021
- const response = await this[method](this.extend(request, query));
2022
2130
  return this.parseOrder(response, market);
2023
2131
  }
2024
2132
  async cancelAllOrders(symbol = undefined, params = {}) {
@@ -2026,6 +2134,9 @@ export default class hitbtc extends Exchange {
2026
2134
  * @method
2027
2135
  * @name hitbtc#cancelAllOrders
2028
2136
  * @description cancel all open orders
2137
+ * @see https://api.hitbtc.com/#cancel-all-spot-orders
2138
+ * @see https://api.hitbtc.com/#cancel-futures-orders
2139
+ * @see https://api.hitbtc.com/#cancel-all-margin-orders
2029
2140
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
2030
2141
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2031
2142
  * @param {string} [params.marginMode] 'cross' or 'isolated' only 'isolated' is supported
@@ -2040,17 +2151,28 @@ export default class hitbtc extends Exchange {
2040
2151
  request['symbol'] = market['id'];
2041
2152
  }
2042
2153
  let marketType = undefined;
2154
+ let marginMode = undefined;
2043
2155
  [marketType, params] = this.handleMarketTypeAndParams('cancelAllOrders', market, params);
2044
- let method = this.getSupportedMapping(marketType, {
2045
- 'spot': 'privateDeleteSpotOrder',
2046
- 'swap': 'privateDeleteFuturesOrder',
2047
- 'margin': 'privateDeleteMarginOrder',
2048
- });
2049
- const [marginMode, query] = this.handleMarginModeAndParams('cancelAllOrders', params);
2156
+ [marginMode, params] = this.handleMarginModeAndParams('cancelAllOrders', params);
2157
+ params = this.omit(params, ['marginMode', 'margin']);
2158
+ let response = undefined;
2050
2159
  if (marginMode !== undefined) {
2051
- method = 'privateDeleteMarginOrder';
2160
+ response = await this.privateDeleteMarginOrder(this.extend(request, params));
2161
+ }
2162
+ else {
2163
+ if (marketType === 'spot') {
2164
+ response = await this.privateDeleteSpotOrder(this.extend(request, params));
2165
+ }
2166
+ else if (marketType === 'swap') {
2167
+ response = await this.privateDeleteFuturesOrder(this.extend(request, params));
2168
+ }
2169
+ else if (marketType === 'margin') {
2170
+ response = await this.privateDeleteMarginOrder(this.extend(request, params));
2171
+ }
2172
+ else {
2173
+ throw new NotSupported(this.id + ' cancelAllOrders() not support this market type');
2174
+ }
2052
2175
  }
2053
- const response = await this[method](this.extend(request, query));
2054
2176
  return this.parseOrders(response, market);
2055
2177
  }
2056
2178
  async cancelOrder(id, symbol = undefined, params = {}) {
@@ -2058,6 +2180,9 @@ export default class hitbtc extends Exchange {
2058
2180
  * @method
2059
2181
  * @name hitbtc#cancelOrder
2060
2182
  * @description cancels an open order
2183
+ * @see https://api.hitbtc.com/#cancel-spot-order
2184
+ * @see https://api.hitbtc.com/#cancel-futures-order
2185
+ * @see https://api.hitbtc.com/#cancel-margin-order
2061
2186
  * @param {string} id order id
2062
2187
  * @param {string} symbol unified symbol of the market the order was made in
2063
2188
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2074,17 +2199,28 @@ export default class hitbtc extends Exchange {
2074
2199
  market = this.market(symbol);
2075
2200
  }
2076
2201
  let marketType = undefined;
2202
+ let marginMode = undefined;
2077
2203
  [marketType, params] = this.handleMarketTypeAndParams('cancelOrder', market, params);
2078
- let method = this.getSupportedMapping(marketType, {
2079
- 'spot': 'privateDeleteSpotOrderClientOrderId',
2080
- 'swap': 'privateDeleteFuturesOrderClientOrderId',
2081
- 'margin': 'privateDeleteMarginOrderClientOrderId',
2082
- });
2083
- const [marginMode, query] = this.handleMarginModeAndParams('cancelOrder', params);
2204
+ [marginMode, params] = this.handleMarginModeAndParams('cancelOrder', params);
2205
+ params = this.omit(params, ['marginMode', 'margin']);
2206
+ let response = undefined;
2084
2207
  if (marginMode !== undefined) {
2085
- method = 'privateDeleteMarginOrderClientOrderId';
2208
+ response = await this.privateDeleteMarginOrderClientOrderId(this.extend(request, params));
2209
+ }
2210
+ else {
2211
+ if (marketType === 'spot') {
2212
+ response = await this.privateDeleteSpotOrderClientOrderId(this.extend(request, params));
2213
+ }
2214
+ else if (marketType === 'swap') {
2215
+ response = await this.privateDeleteFuturesOrderClientOrderId(this.extend(request, params));
2216
+ }
2217
+ else if (marketType === 'margin') {
2218
+ response = await this.privateDeleteMarginOrderClientOrderId(this.extend(request, params));
2219
+ }
2220
+ else {
2221
+ throw new NotSupported(this.id + ' cancelOrder() not support this market type');
2222
+ }
2086
2223
  }
2087
- const response = await this[method](this.extend(request, query));
2088
2224
  return this.parseOrder(response, market);
2089
2225
  }
2090
2226
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
@@ -2104,17 +2240,28 @@ export default class hitbtc extends Exchange {
2104
2240
  market = this.market(symbol);
2105
2241
  }
2106
2242
  let marketType = undefined;
2243
+ let marginMode = undefined;
2107
2244
  [marketType, params] = this.handleMarketTypeAndParams('editOrder', market, params);
2108
- let method = this.getSupportedMapping(marketType, {
2109
- 'spot': 'privatePatchSpotOrderClientOrderId',
2110
- 'swap': 'privatePatchFuturesOrderClientOrderId',
2111
- 'margin': 'privatePatchMarginOrderClientOrderId',
2112
- });
2113
- const [marginMode, query] = this.handleMarginModeAndParams('editOrder', params);
2245
+ [marginMode, params] = this.handleMarginModeAndParams('editOrder', params);
2246
+ params = this.omit(params, ['marginMode', 'margin']);
2247
+ let response = undefined;
2114
2248
  if (marginMode !== undefined) {
2115
- method = 'privatePatchMarginOrderClientOrderId';
2249
+ response = await this.privatePatchMarginOrderClientOrderId(this.extend(request, params));
2250
+ }
2251
+ else {
2252
+ if (marketType === 'spot') {
2253
+ response = await this.privatePatchSpotOrderClientOrderId(this.extend(request, params));
2254
+ }
2255
+ else if (marketType === 'swap') {
2256
+ response = await this.privatePatchFuturesOrderClientOrderId(this.extend(request, params));
2257
+ }
2258
+ else if (marketType === 'margin') {
2259
+ response = await this.privatePatchMarginOrderClientOrderId(this.extend(request, params));
2260
+ }
2261
+ else {
2262
+ throw new NotSupported(this.id + ' editOrder() not support this market type');
2263
+ }
2116
2264
  }
2117
- const response = await this[method](this.extend(request, query));
2118
2265
  return this.parseOrder(response, market);
2119
2266
  }
2120
2267
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
@@ -2443,6 +2590,7 @@ export default class hitbtc extends Exchange {
2443
2590
  * @method
2444
2591
  * @name hitbtc#transfer
2445
2592
  * @description transfer currency internally between wallets on the same account
2593
+ * @see https://api.hitbtc.com/#transfer-between-wallet-and-exchange
2446
2594
  * @param {string} code unified currency code
2447
2595
  * @param {float} amount amount to transfer
2448
2596
  * @param {string} fromAccount account to transfer from
@@ -2530,6 +2678,7 @@ export default class hitbtc extends Exchange {
2530
2678
  * @method
2531
2679
  * @name hitbtc#withdraw
2532
2680
  * @description make a withdrawal
2681
+ * @see https://api.hitbtc.com/#withdraw-crypto
2533
2682
  * @param {string} code unified currency code
2534
2683
  * @param {float} amount the amount to withdraw
2535
2684
  * @param {string} address the address to withdraw to
@@ -2711,6 +2860,8 @@ export default class hitbtc extends Exchange {
2711
2860
  * @method
2712
2861
  * @name hitbtc#fetchPositions
2713
2862
  * @description fetch all open positions
2863
+ * @see https://api.hitbtc.com/#get-futures-margin-accounts
2864
+ * @see https://api.hitbtc.com/#get-all-margin-accounts
2714
2865
  * @param {string[]|undefined} symbols not used by hitbtc fetchPositions ()
2715
2866
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2716
2867
  * @param {string} [params.marginMode] 'cross' or 'isolated' only 'isolated' is supported, defaults to spot-margin endpoint if this is set
@@ -2720,16 +2871,25 @@ export default class hitbtc extends Exchange {
2720
2871
  await this.loadMarkets();
2721
2872
  const request = {};
2722
2873
  let marketType = undefined;
2874
+ let marginMode = undefined;
2723
2875
  [marketType, params] = this.handleMarketTypeAndParams('fetchPositions', undefined, params);
2724
- let method = this.getSupportedMapping(marketType, {
2725
- 'swap': 'privateGetFuturesAccount',
2726
- 'margin': 'privateGetMarginAccount',
2727
- });
2728
- const [marginMode, query] = this.handleMarginModeAndParams('fetchPositions', params);
2876
+ [marginMode, params] = this.handleMarginModeAndParams('fetchPositions', params);
2877
+ params = this.omit(params, ['marginMode', 'margin']);
2878
+ let response = undefined;
2729
2879
  if (marginMode !== undefined) {
2730
- method = 'privateGetMarginAccount';
2880
+ response = await this.privateGetMarginAccount(this.extend(request, params));
2881
+ }
2882
+ else {
2883
+ if (marketType === 'swap') {
2884
+ response = await this.privateGetFuturesAccount(this.extend(request, params));
2885
+ }
2886
+ else if (marketType === 'margin') {
2887
+ response = await this.privateGetMarginAccount(this.extend(request, params));
2888
+ }
2889
+ else {
2890
+ throw new NotSupported(this.id + ' fetchPositions() not support this market type');
2891
+ }
2731
2892
  }
2732
- const response = await this[method](this.extend(request, query));
2733
2893
  //
2734
2894
  // [
2735
2895
  // {
@@ -2773,6 +2933,8 @@ export default class hitbtc extends Exchange {
2773
2933
  * @method
2774
2934
  * @name hitbtc#fetchPosition
2775
2935
  * @description fetch data on a single open contract trade position
2936
+ * @see https://api.hitbtc.com/#get-futures-margin-account
2937
+ * @see https://api.hitbtc.com/#get-isolated-margin-account
2776
2938
  * @param {string} symbol unified market symbol of the market the position is held in, default is undefined
2777
2939
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2778
2940
  * @param {string} [params.marginMode] 'cross' or 'isolated' only 'isolated' is supported, defaults to spot-margin endpoint if this is set
@@ -2780,21 +2942,30 @@ export default class hitbtc extends Exchange {
2780
2942
  * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2781
2943
  */
2782
2944
  await this.loadMarkets();
2783
- let marketType = undefined;
2784
- [marketType, params] = this.handleMarketTypeAndParams('fetchPosition', undefined, params);
2785
- let method = this.getSupportedMapping(marketType, {
2786
- 'swap': 'privateGetFuturesAccountIsolatedSymbol',
2787
- 'margin': 'privateGetMarginAccountIsolatedSymbol',
2788
- });
2789
- const [marginMode, query] = this.handleMarginModeAndParams('fetchPosition', params);
2790
- if (marginMode !== undefined) {
2791
- method = 'privateGetMarginAccountIsolatedSymbol';
2792
- }
2793
2945
  const market = this.market(symbol);
2794
2946
  const request = {
2795
2947
  'symbol': market['id'],
2796
2948
  };
2797
- const response = await this[method](this.extend(request, query));
2949
+ let marketType = undefined;
2950
+ let marginMode = undefined;
2951
+ [marketType, params] = this.handleMarketTypeAndParams('fetchPosition', undefined, params);
2952
+ [marginMode, params] = this.handleMarginModeAndParams('fetchPosition', params);
2953
+ params = this.omit(params, ['marginMode', 'margin']);
2954
+ let response = undefined;
2955
+ if (marginMode !== undefined) {
2956
+ response = await this.privateGetMarginAccountIsolatedSymbol(this.extend(request, params));
2957
+ }
2958
+ else {
2959
+ if (marketType === 'swap') {
2960
+ response = await this.privateGetFuturesAccountIsolatedSymbol(this.extend(request, params));
2961
+ }
2962
+ else if (marketType === 'margin') {
2963
+ response = await this.privateGetMarginAccountIsolatedSymbol(this.extend(request, params));
2964
+ }
2965
+ else {
2966
+ throw new NotSupported(this.id + ' fetchPosition() not support this market type');
2967
+ }
2968
+ }
2798
2969
  //
2799
2970
  // [
2800
2971
  // {
@@ -3061,7 +3232,12 @@ export default class hitbtc extends Exchange {
3061
3232
  throw new ArgumentsRequired(this.id + ' modifyMarginHelper() requires a leverage parameter for swap markets');
3062
3233
  }
3063
3234
  }
3064
- amount = this.amountToPrecision(symbol, amount);
3235
+ if (amount !== 0) {
3236
+ amount = this.amountToPrecision(symbol, amount);
3237
+ }
3238
+ else {
3239
+ amount = '0';
3240
+ }
3065
3241
  const request = {
3066
3242
  'symbol': market['id'],
3067
3243
  'margin_balance': amount, // swap and margin
@@ -3072,16 +3248,25 @@ export default class hitbtc extends Exchange {
3072
3248
  request['leverage'] = leverage;
3073
3249
  }
3074
3250
  let marketType = undefined;
3075
- [marketType, params] = this.handleMarketTypeAndParams('modifyMarginHelper', undefined, params);
3076
- let method = this.getSupportedMapping(marketType, {
3077
- 'swap': 'privatePutFuturesAccountIsolatedSymbol',
3078
- 'margin': 'privatePutMarginAccountIsolatedSymbol',
3079
- });
3080
- const [marginMode, query] = this.handleMarginModeAndParams('modifyMarginHelper', params);
3251
+ let marginMode = undefined;
3252
+ [marketType, params] = this.handleMarketTypeAndParams('modifyMarginHelper', market, params);
3253
+ [marginMode, params] = this.handleMarginModeAndParams('modifyMarginHelper', params);
3254
+ params = this.omit(params, ['marginMode', 'margin']);
3255
+ let response = undefined;
3081
3256
  if (marginMode !== undefined) {
3082
- method = 'privatePutMarginAccountIsolatedSymbol';
3257
+ response = await this.privatePutMarginAccountIsolatedSymbol(this.extend(request, params));
3258
+ }
3259
+ else {
3260
+ if (marketType === 'swap') {
3261
+ response = await this.privatePutFuturesAccountIsolatedSymbol(this.extend(request, params));
3262
+ }
3263
+ else if (marketType === 'margin') {
3264
+ response = await this.privatePutMarginAccountIsolatedSymbol(this.extend(request, params));
3265
+ }
3266
+ else {
3267
+ throw new NotSupported(this.id + ' modifyMarginHelper() not support this market type');
3268
+ }
3083
3269
  }
3084
- const response = await this[method](this.extend(request, query));
3085
3270
  //
3086
3271
  // {
3087
3272
  // "symbol": "BTCUSDT_PERP",
@@ -3122,6 +3307,8 @@ export default class hitbtc extends Exchange {
3122
3307
  * @method
3123
3308
  * @name hitbtc#reduceMargin
3124
3309
  * @description remove margin from a position
3310
+ * @see https://api.hitbtc.com/#create-update-margin-account-2
3311
+ * @see https://api.hitbtc.com/#create-update-margin-account
3125
3312
  * @param {string} symbol unified market symbol
3126
3313
  * @param {float} amount the amount of margin to remove
3127
3314
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -3139,6 +3326,8 @@ export default class hitbtc extends Exchange {
3139
3326
  * @method
3140
3327
  * @name hitbtc#addMargin
3141
3328
  * @description add margin
3329
+ * @see https://api.hitbtc.com/#create-update-margin-account-2
3330
+ * @see https://api.hitbtc.com/#create-update-margin-account
3142
3331
  * @param {string} symbol unified market symbol
3143
3332
  * @param {float} amount amount of margin to add
3144
3333
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -3153,6 +3342,8 @@ export default class hitbtc extends Exchange {
3153
3342
  * @method
3154
3343
  * @name hitbtc#fetchLeverage
3155
3344
  * @description fetch the set leverage for a market
3345
+ * @see https://api.hitbtc.com/#get-futures-margin-account
3346
+ * @see https://api.hitbtc.com/#get-isolated-margin-account
3156
3347
  * @param {string} symbol unified market symbol
3157
3348
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3158
3349
  * @param {string} [params.marginMode] 'cross' or 'isolated' only 'isolated' is supported, defaults to the spot-margin endpoint if this is set
@@ -3164,16 +3355,27 @@ export default class hitbtc extends Exchange {
3164
3355
  const request = {
3165
3356
  'symbol': market['id'],
3166
3357
  };
3167
- let method = this.getSupportedMapping(market['type'], {
3168
- 'spot': 'privateGetMarginAccountIsolatedSymbol',
3169
- 'margin': 'privateGetMarginAccountIsolatedSymbol',
3170
- 'swap': 'privateGetFuturesAccountIsolatedSymbol',
3171
- });
3172
- const [marginMode, query] = this.handleMarginModeAndParams('modifyMarginHelper', params);
3358
+ let marginMode = undefined;
3359
+ [marginMode, params] = this.handleMarginModeAndParams('fetchLeverage', params);
3360
+ params = this.omit(params, ['marginMode', 'margin']);
3361
+ let response = undefined;
3173
3362
  if (marginMode !== undefined) {
3174
- method = 'privateGetMarginAccountIsolatedSymbol';
3363
+ response = await this.privateGetMarginAccountIsolatedSymbol(this.extend(request, params));
3364
+ }
3365
+ else {
3366
+ if (market['type'] === 'spot') {
3367
+ response = await this.privateGetMarginAccountIsolatedSymbol(this.extend(request, params));
3368
+ }
3369
+ else if (market['type'] === 'swap') {
3370
+ response = await this.privateGetFuturesAccountIsolatedSymbol(this.extend(request, params));
3371
+ }
3372
+ else if (market['type'] === 'margin') {
3373
+ response = await this.privateGetMarginAccountIsolatedSymbol(this.extend(request, params));
3374
+ }
3375
+ else {
3376
+ throw new NotSupported(this.id + ' fetchLeverage() not support this market type');
3377
+ }
3175
3378
  }
3176
- const response = await this[method](this.extend(request, query));
3177
3379
  //
3178
3380
  // {
3179
3381
  // "symbol": "BTCUSDT",
@@ -3211,6 +3413,7 @@ export default class hitbtc extends Exchange {
3211
3413
  * @method
3212
3414
  * @name hitbtc#setLeverage
3213
3415
  * @description set the level of leverage for a market
3416
+ * @see https://api.hitbtc.com/#create-update-margin-account-2
3214
3417
  * @param {float} leverage the rate of leverage
3215
3418
  * @param {string} symbol unified market symbol
3216
3419
  * @param {object} [params] extra parameters specific to the exchange API endpoint