ccxt 4.1.37 → 4.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/ccxt.js CHANGED
@@ -180,7 +180,7 @@ var woo$1 = require('./src/pro/woo.js');
180
180
 
181
181
  //-----------------------------------------------------------------------------
182
182
  // this is updated by vss.js when building
183
- const version = '4.1.37';
183
+ const version = '4.1.39';
184
184
  Exchange["default"].ccxtVersion = version;
185
185
  const exchanges = {
186
186
  'ace': ace,
@@ -26,26 +26,45 @@ class bitforex extends bitforex$1 {
26
26
  'swap': false,
27
27
  'future': false,
28
28
  'option': false,
29
+ 'addMargin': false,
30
+ 'borrowMargin': false,
29
31
  'cancelOrder': true,
30
32
  'createOrder': true,
33
+ 'createReduceOnlyOrder': false,
31
34
  'createStopLimitOrder': false,
32
35
  'createStopMarketOrder': false,
33
36
  'createStopOrder': false,
34
37
  'fetchBalance': true,
38
+ 'fetchBorrowInterest': false,
35
39
  'fetchBorrowRate': false,
36
40
  'fetchBorrowRateHistories': false,
37
41
  'fetchBorrowRateHistory': false,
38
42
  'fetchBorrowRates': false,
39
43
  'fetchBorrowRatesPerSymbol': false,
40
44
  'fetchClosedOrders': true,
45
+ 'fetchFundingHistory': false,
46
+ 'fetchFundingRate': false,
47
+ 'fetchFundingRateHistory': false,
48
+ 'fetchFundingRates': false,
49
+ 'fetchIndexOHLCV': false,
50
+ 'fetchIsolatedPositions': false,
51
+ 'fetchLeverage': false,
52
+ 'fetchLeverageTiers': false,
41
53
  'fetchMarginMode': false,
54
+ 'fetchMarketLeverageTiers': false,
42
55
  'fetchMarkets': true,
56
+ 'fetchMarkOHLCV': false,
43
57
  'fetchMyTrades': true,
44
58
  'fetchOHLCV': true,
59
+ 'fetchOpenInterestHistory': false,
45
60
  'fetchOpenOrders': true,
46
61
  'fetchOrder': true,
47
62
  'fetchOrderBook': true,
63
+ 'fetchPosition': false,
48
64
  'fetchPositionMode': false,
65
+ 'fetchPositions': false,
66
+ 'fetchPositionsRisk': false,
67
+ 'fetchPremiumIndexOHLCV': false,
49
68
  'fetchTicker': true,
50
69
  'fetchTickers': false,
51
70
  'fetchTrades': true,
@@ -54,6 +73,12 @@ class bitforex extends bitforex$1 {
54
73
  'fetchTransfers': false,
55
74
  'fetchWithdrawal': false,
56
75
  'fetchWithdrawals': false,
76
+ 'reduceMargin': false,
77
+ 'repayMargin': false,
78
+ 'setLeverage': false,
79
+ 'setMargin': false,
80
+ 'setMarginMode': false,
81
+ 'setPositionMode': false,
57
82
  'transfer': false,
58
83
  'withdraw': false,
59
84
  },
@@ -427,6 +427,7 @@ class bybit extends bybit$1 {
427
427
  'v5/user/query-api': 5,
428
428
  'v5/user/get-member-type': 5,
429
429
  'v5/user/aff-customer-info': 5,
430
+ 'v5/user/del-submember': 5,
430
431
  // spot leverage token
431
432
  'v5/spot-lever-token/order-record': 1,
432
433
  // spot margin trade
@@ -31,6 +31,7 @@ class digifinex extends digifinex$1 {
31
31
  'cancelOrder': true,
32
32
  'cancelOrders': true,
33
33
  'createOrder': true,
34
+ 'createOrders': true,
34
35
  'createPostOnlyOrder': true,
35
36
  'createReduceOnlyOrder': true,
36
37
  'createStopLimitOrder': false,
@@ -288,6 +289,7 @@ class digifinex extends digifinex$1 {
288
289
  'options': {
289
290
  'defaultType': 'spot',
290
291
  'types': ['spot', 'margin', 'otc'],
292
+ 'createMarketBuyOrderRequiresPrice': true,
291
293
  'accountsByType': {
292
294
  'spot': '1',
293
295
  'margin': '2',
@@ -1551,28 +1553,173 @@ class digifinex extends digifinex$1 {
1551
1553
  * @param {string} symbol unified symbol of the market to create an order in
1552
1554
  * @param {string} type 'market' or 'limit'
1553
1555
  * @param {string} side 'buy' or 'sell'
1554
- * @param {float} amount how much of currency you want to trade in units of base currency
1556
+ * @param {float} amount how much you want to trade in units of the base currency, spot market orders use the quote currency, swap requires the number of contracts
1555
1557
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1556
1558
  * @param {object} [params] extra parameters specific to the digifinex api endpoint
1557
1559
  * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
1558
1560
  * @param {bool} [params.postOnly] true or false
1559
1561
  * @param {bool} [params.reduceOnly] true or false
1562
+ * @param {string} [params.marginMode] 'cross' or 'isolated', for spot margin trading
1560
1563
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1561
1564
  */
1562
1565
  await this.loadMarkets();
1563
1566
  const market = this.market(symbol);
1564
- symbol = market['symbol'];
1567
+ const marginResult = this.handleMarginModeAndParams('createOrder', params);
1568
+ const marginMode = marginResult[0];
1569
+ const request = this.createOrderRequest(symbol, type, side, amount, price, params);
1570
+ let response = undefined;
1571
+ if (market['swap']) {
1572
+ response = await this.privateSwapPostTradeOrderPlace(request);
1573
+ }
1574
+ else {
1575
+ if (marginMode !== undefined) {
1576
+ response = await this.privateSpotPostMarginOrderNew(request);
1577
+ }
1578
+ else {
1579
+ response = await this.privateSpotPostSpotOrderNew(request);
1580
+ }
1581
+ }
1582
+ //
1583
+ // spot and margin
1584
+ //
1585
+ // {
1586
+ // "code": 0,
1587
+ // "order_id": "198361cecdc65f9c8c9bb2fa68faec40"
1588
+ // }
1589
+ //
1590
+ // swap
1591
+ //
1592
+ // {
1593
+ // "code": 0,
1594
+ // "data": "1590873693003714560"
1595
+ // }
1596
+ //
1597
+ const order = this.parseOrder(response, market);
1598
+ order['symbol'] = market['symbol'];
1599
+ order['type'] = type;
1600
+ order['side'] = side;
1601
+ order['amount'] = amount;
1602
+ order['price'] = price;
1603
+ return order;
1604
+ }
1605
+ async createOrders(orders, params = {}) {
1606
+ /**
1607
+ * @method
1608
+ * @name digifinex#createOrders
1609
+ * @description create a list of trade orders (all orders should be of the same symbol)
1610
+ * @see https://docs.digifinex.com/en-ww/spot/v3/rest.html#create-multiple-order
1611
+ * @see https://docs.digifinex.com/en-ww/swap/v2/rest.html#batchorder
1612
+ * @param {array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
1613
+ * @param {object} [params] extra parameters specific to the digifinex api endpoint
1614
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1615
+ */
1616
+ await this.loadMarkets();
1617
+ const ordersRequests = [];
1618
+ let symbol = undefined;
1619
+ let marginMode = undefined;
1620
+ for (let i = 0; i < orders.length; i++) {
1621
+ const rawOrder = orders[i];
1622
+ const marketId = this.safeString(rawOrder, 'symbol');
1623
+ if (symbol === undefined) {
1624
+ symbol = marketId;
1625
+ }
1626
+ else {
1627
+ if (symbol !== marketId) {
1628
+ throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same symbol');
1629
+ }
1630
+ }
1631
+ const type = this.safeString(rawOrder, 'type');
1632
+ const side = this.safeString(rawOrder, 'side');
1633
+ const amount = this.safeValue(rawOrder, 'amount');
1634
+ const price = this.safeValue(rawOrder, 'price');
1635
+ const orderParams = this.safeValue(rawOrder, 'params', {});
1636
+ const marginResult = this.handleMarginModeAndParams('createOrders', params);
1637
+ const currentMarginMode = marginResult[0];
1638
+ if (currentMarginMode !== undefined) {
1639
+ if (marginMode === undefined) {
1640
+ marginMode = currentMarginMode;
1641
+ }
1642
+ else {
1643
+ if (marginMode !== currentMarginMode) {
1644
+ throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same margin mode (isolated or cross)');
1645
+ }
1646
+ }
1647
+ }
1648
+ const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
1649
+ ordersRequests.push(orderRequest);
1650
+ }
1651
+ const market = this.market(symbol);
1652
+ const request = {};
1653
+ let response = undefined;
1654
+ if (market['swap']) {
1655
+ response = await this.privateSwapPostTradeBatchOrder(ordersRequests);
1656
+ }
1657
+ else {
1658
+ request['market'] = (marginMode !== undefined) ? 'margin' : 'spot';
1659
+ request['symbol'] = market['id'];
1660
+ request['list'] = this.json(ordersRequests);
1661
+ response = await this.privateSpotPostMarketOrderBatchNew(request);
1662
+ }
1663
+ //
1664
+ // spot
1665
+ //
1666
+ // {
1667
+ // "code": 0,
1668
+ // "order_ids": [
1669
+ // "064290fbe2d26e7b28d7e6c0a5cf70a5",
1670
+ // "24c8f9b73d81e4d9d8d7e3280281c258"
1671
+ // ]
1672
+ // }
1673
+ //
1674
+ // swap
1675
+ //
1676
+ // {
1677
+ // "code": 0,
1678
+ // "data": [
1679
+ // "1720297963537829888",
1680
+ // "1720297963537829889"
1681
+ // ]
1682
+ // }
1683
+ //
1684
+ let data = [];
1685
+ if (market['swap']) {
1686
+ data = this.safeValue(response, 'data', []);
1687
+ }
1688
+ else {
1689
+ data = this.safeValue(response, 'order_ids', []);
1690
+ }
1691
+ const result = [];
1692
+ for (let i = 0; i < orders.length; i++) {
1693
+ const rawOrder = orders[i];
1694
+ const individualOrder = {};
1695
+ individualOrder['order_id'] = data[i];
1696
+ individualOrder['instrument_id'] = market['id'];
1697
+ individualOrder['amount'] = this.safeNumber(rawOrder, 'amount');
1698
+ individualOrder['price'] = this.safeNumber(rawOrder, 'price');
1699
+ result.push(individualOrder);
1700
+ }
1701
+ return this.parseOrders(result, market);
1702
+ }
1703
+ createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1704
+ /**
1705
+ * @method
1706
+ * @ignore
1707
+ * @name digifinex#createOrderRequest
1708
+ * @description helper function to build request
1709
+ * @param {string} symbol unified symbol of the market to create an order in
1710
+ * @param {string} type 'market' or 'limit'
1711
+ * @param {string} side 'buy' or 'sell'
1712
+ * @param {float} amount how much you want to trade in units of the base currency, spot market orders use the quote currency, swap requires the number of contracts
1713
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1714
+ * @param {object} [params] extra parameters specific to the digifinex api endpoint
1715
+ * @returns {object} request to be sent to the exchange
1716
+ */
1717
+ const market = this.market(symbol);
1565
1718
  let marketType = undefined;
1566
1719
  let marginMode = undefined;
1567
- [marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
1568
- let method = this.getSupportedMapping(marketType, {
1569
- 'spot': 'privateSpotPostSpotOrderNew',
1570
- 'margin': 'privateSpotPostMarginOrderNew',
1571
- 'swap': 'privateSwapPostTradeOrderPlace',
1572
- });
1573
- [marginMode, params] = this.handleMarginModeAndParams('createOrder', params);
1720
+ [marketType, params] = this.handleMarketTypeAndParams('createOrderRequest', market, params);
1721
+ [marginMode, params] = this.handleMarginModeAndParams('createOrderRequest', params);
1574
1722
  if (marginMode !== undefined) {
1575
- method = 'privateSpotPostMarginOrderNew';
1576
1723
  marketType = 'margin';
1577
1724
  }
1578
1725
  const request = {};
@@ -1629,40 +1776,34 @@ class digifinex extends digifinex$1 {
1629
1776
  }
1630
1777
  request['type'] = side + suffix;
1631
1778
  // limit orders require the amount in the base currency, market orders require the amount in the quote currency
1632
- request['amount'] = this.amountToPrecision(symbol, amount);
1779
+ let quantity = undefined;
1780
+ const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1781
+ if (createMarketBuyOrderRequiresPrice && isMarketOrder && (side === 'buy')) {
1782
+ if (price === undefined) {
1783
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires a price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1784
+ }
1785
+ else {
1786
+ const amountString = this.numberToString(amount);
1787
+ const priceString = this.numberToString(price);
1788
+ const cost = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
1789
+ quantity = this.priceToPrecision(symbol, cost);
1790
+ }
1791
+ }
1792
+ else {
1793
+ quantity = this.amountToPrecision(symbol, amount);
1794
+ }
1795
+ request['amount'] = quantity;
1633
1796
  }
1634
1797
  if (postOnly) {
1635
1798
  if (postOnlyParsed) {
1636
- request['postOnly'] = postOnlyParsed;
1799
+ request['post_only'] = postOnlyParsed;
1637
1800
  }
1638
1801
  else {
1639
- request['postOnly'] = postOnly;
1802
+ request['post_only'] = postOnly;
1640
1803
  }
1641
1804
  }
1642
- const query = this.omit(params, ['postOnly', 'post_only']);
1643
- const response = await this[method](this.extend(request, query));
1644
- //
1645
- // spot and margin
1646
- //
1647
- // {
1648
- // "code": 0,
1649
- // "order_id": "198361cecdc65f9c8c9bb2fa68faec40"
1650
- // }
1651
- //
1652
- // swap
1653
- //
1654
- // {
1655
- // "code": 0,
1656
- // "data": "1590873693003714560"
1657
- // }
1658
- //
1659
- const order = this.parseOrder(response, market);
1660
- order['symbol'] = symbol;
1661
- order['type'] = type;
1662
- order['side'] = side;
1663
- order['amount'] = amount;
1664
- order['price'] = price;
1665
- return order;
1805
+ params = this.omit(params, ['postOnly']);
1806
+ return this.extend(request, params);
1666
1807
  }
1667
1808
  async cancelOrder(id, symbol = undefined, params = {}) {
1668
1809
  /**
@@ -1799,6 +1940,15 @@ class digifinex extends digifinex$1 {
1799
1940
  // "data": "1590873693003714560"
1800
1941
  // }
1801
1942
  //
1943
+ // spot and swap: createOrders
1944
+ //
1945
+ // {
1946
+ // "order_id": "d64d92a5e0a120f792f385485bc3d95b",
1947
+ // "instrument_id": "BTC_USDT",
1948
+ // "amount": 0.0001,
1949
+ // "price": 27000
1950
+ // }
1951
+ //
1802
1952
  // spot: fetchOrder, fetchOpenOrders, fetchOrders
1803
1953
  //
1804
1954
  // {
@@ -1844,24 +1994,26 @@ class digifinex extends digifinex$1 {
1844
1994
  let type = undefined;
1845
1995
  let side = this.safeString(order, 'type');
1846
1996
  const marketId = this.safeString2(order, 'symbol', 'instrument_id');
1847
- const symbol = this.safeSymbol(marketId, market, '_');
1997
+ const symbol = this.safeSymbol(marketId, market);
1848
1998
  market = this.market(symbol);
1849
1999
  if (market['type'] === 'swap') {
1850
2000
  const orderType = this.safeInteger(order, 'order_type');
1851
- if ((orderType === 9) || (orderType === 10) || (orderType === 11) || (orderType === 12) || (orderType === 15)) {
1852
- timeInForce = 'FOK';
1853
- }
1854
- else if ((orderType === 1) || (orderType === 2) || (orderType === 3) || (orderType === 4) || (orderType === 13)) {
1855
- timeInForce = 'IOC';
1856
- }
1857
- else if ((orderType === 6) || (orderType === 7) || (orderType === 8) || (orderType === 14)) {
1858
- timeInForce = 'GTC';
1859
- }
1860
- if ((orderType === 0) || (orderType === 1) || (orderType === 4) || (orderType === 5) || (orderType === 9) || (orderType === 10)) {
1861
- type = 'limit';
1862
- }
1863
- else {
1864
- type = 'market';
2001
+ if (orderType !== undefined) {
2002
+ if ((orderType === 9) || (orderType === 10) || (orderType === 11) || (orderType === 12) || (orderType === 15)) {
2003
+ timeInForce = 'FOK';
2004
+ }
2005
+ else if ((orderType === 1) || (orderType === 2) || (orderType === 3) || (orderType === 4) || (orderType === 13)) {
2006
+ timeInForce = 'IOC';
2007
+ }
2008
+ else if ((orderType === 6) || (orderType === 7) || (orderType === 8) || (orderType === 14)) {
2009
+ timeInForce = 'GTC';
2010
+ }
2011
+ if ((orderType === 0) || (orderType === 1) || (orderType === 4) || (orderType === 5) || (orderType === 9) || (orderType === 10)) {
2012
+ type = 'limit';
2013
+ }
2014
+ else {
2015
+ type = 'market';
2016
+ }
1865
2017
  }
1866
2018
  if (side === '1') {
1867
2019
  side = 'open long';
@@ -4820,6 +4820,7 @@ class huobi extends huobi$1 {
4820
4820
  * @param {string} [params.offset] *contract only* 'open', 'close', or 'both', required in hedge mode
4821
4821
  * @param {bool} [params.postOnly] *contract only* true or false
4822
4822
  * @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
4823
+ * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
4823
4824
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
4824
4825
  */
4825
4826
  await this.loadMarkets();
@@ -4892,6 +4893,13 @@ class huobi extends huobi$1 {
4892
4893
  if (postOnly) {
4893
4894
  orderType = 'limit-maker';
4894
4895
  }
4896
+ const timeInForce = this.safeString(params, 'timeInForce', 'GTC');
4897
+ if (timeInForce === 'FOK') {
4898
+ orderType = orderType + '-fok';
4899
+ }
4900
+ else if (timeInForce === 'IOC') {
4901
+ orderType = 'ioc';
4902
+ }
4895
4903
  request['type'] = side + '-' + orderType;
4896
4904
  const clientOrderId = this.safeString2(params, 'clientOrderId', 'client-order-id'); // must be 64 chars max and unique within 24 hours
4897
4905
  if (clientOrderId === undefined) {
@@ -4939,7 +4947,7 @@ class huobi extends huobi$1 {
4939
4947
  if (orderType in limitOrderTypes) {
4940
4948
  request['price'] = this.priceToPrecision(symbol, price);
4941
4949
  }
4942
- params = this.omit(params, ['stopPrice', 'stop-price', 'clientOrderId', 'client-order-id', 'operator']);
4950
+ params = this.omit(params, ['stopPrice', 'stop-price', 'clientOrderId', 'client-order-id', 'operator', 'timeInForce']);
4943
4951
  const response = await this.spotPrivatePostV1OrderOrdersPlace(this.extend(request, params));
4944
4952
  //
4945
4953
  // spot
@@ -4984,6 +4992,7 @@ class huobi extends huobi$1 {
4984
4992
  * @param {float} amount how much of currency you want to trade in units of base currency
4985
4993
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
4986
4994
  * @param {object} params extra parameters specific to the huobi api endpoint
4995
+ * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
4987
4996
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
4988
4997
  */
4989
4998
  const market = this.market(symbol);
@@ -4997,6 +5006,13 @@ class huobi extends huobi$1 {
4997
5006
  if (postOnly) {
4998
5007
  type = 'post_only';
4999
5008
  }
5009
+ const timeInForce = this.safeString(params, 'timeInForce', 'GTC');
5010
+ if (timeInForce === 'FOK') {
5011
+ type = 'fok';
5012
+ }
5013
+ else if (timeInForce === 'IOC') {
5014
+ type = 'ioc';
5015
+ }
5000
5016
  const triggerPrice = this.safeNumber2(params, 'stopPrice', 'trigger_price');
5001
5017
  const stopLossTriggerPrice = this.safeNumber2(params, 'stopLossPrice', 'sl_trigger_price');
5002
5018
  const takeProfitTriggerPrice = this.safeNumber2(params, 'takeProfitPrice', 'tp_trigger_price');
@@ -5049,7 +5065,7 @@ class huobi extends huobi$1 {
5049
5065
  request['lever_rate'] = leverRate;
5050
5066
  request['order_price_type'] = type;
5051
5067
  }
5052
- params = this.omit(params, ['reduceOnly', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'triggerType', 'leverRate']);
5068
+ params = this.omit(params, ['reduceOnly', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'triggerType', 'leverRate', 'timeInForce']);
5053
5069
  const broker = this.safeValue(this.options, 'broker', {});
5054
5070
  const brokerId = this.safeString(broker, 'id');
5055
5071
  request['channel_code'] = brokerId;
@@ -93,6 +93,7 @@ class krakenfutures extends krakenfutures$1 {
93
93
  'api': {
94
94
  'public': {
95
95
  'get': [
96
+ 'feeschedules',
96
97
  'instruments',
97
98
  'orderbook',
98
99
  'tickers',
@@ -102,6 +103,7 @@ class krakenfutures extends krakenfutures$1 {
102
103
  },
103
104
  'private': {
104
105
  'get': [
106
+ 'feeschedules/volumes',
105
107
  'openpositions',
106
108
  'notifications',
107
109
  'accounts',
@@ -142,11 +144,6 @@ class krakenfutures extends krakenfutures$1 {
142
144
  'market/{symbol}/executions',
143
145
  ],
144
146
  },
145
- 'feeschedules': {
146
- 'get': [
147
- 'volumes',
148
- ],
149
- },
150
147
  },
151
148
  'fees': {
152
149
  'trading': {
@@ -2698,16 +2698,16 @@ class mexc extends mexc$1 {
2698
2698
  await this.loadMarkets();
2699
2699
  const request = {};
2700
2700
  let market = undefined;
2701
+ let marketType = undefined;
2701
2702
  if (symbol !== undefined) {
2702
2703
  market = this.market(symbol);
2703
- request['symbol'] = market['id'];
2704
2704
  }
2705
- let marketType = undefined;
2706
2705
  [marketType, params] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
2707
2706
  if (marketType === 'spot') {
2708
2707
  if (symbol === undefined) {
2709
2708
  throw new errors.ArgumentsRequired(this.id + ' fetchOpenOrders() requires a symbol argument for spot market');
2710
2709
  }
2710
+ request['symbol'] = market['id'];
2711
2711
  let method = 'spotPrivateGetOpenOrders';
2712
2712
  const [marginMode, query] = this.handleMarginModeAndParams('fetchOpenOrders', params);
2713
2713
  if (marginMode !== undefined) {
@@ -2804,7 +2804,6 @@ class mexc extends mexc$1 {
2804
2804
  let market = undefined;
2805
2805
  if (symbol !== undefined) {
2806
2806
  market = this.market(symbol);
2807
- request['symbol'] = market['id'];
2808
2807
  }
2809
2808
  const [marketType] = this.handleMarketTypeAndParams('fetchOrdersByState', market, params);
2810
2809
  if (marketType === 'spot') {
@@ -1980,6 +1980,9 @@ class phemex extends phemex$1 {
1980
1980
  'Filled': 'closed',
1981
1981
  'Canceled': 'canceled',
1982
1982
  '1': 'open',
1983
+ '2': 'canceled',
1984
+ '3': 'closed',
1985
+ '4': 'canceled',
1983
1986
  '5': 'open',
1984
1987
  '6': 'open',
1985
1988
  '7': 'closed',
@@ -5,6 +5,9 @@ var Precise = require('../base/Precise.js');
5
5
  var errors = require('../base/errors.js');
6
6
  var Cache = require('../base/ws/Cache.js');
7
7
  var sha256 = require('../static_dependencies/noble-hashes/sha256.js');
8
+ var rsa = require('../base/functions/rsa.js');
9
+ var crypto = require('../base/functions/crypto.js');
10
+ var ed25519 = require('../static_dependencies/noble-curves/ed25519.js');
8
11
 
9
12
  // ----------------------------------------------------------------------------
10
13
  // -----------------------------------------------------------------------------
@@ -1213,7 +1216,20 @@ class binance extends binance$1 {
1213
1216
  params['recvWindow'] = recvWindow;
1214
1217
  }
1215
1218
  extendedParams = this.keysort(extendedParams);
1216
- extendedParams['signature'] = this.hmac(this.encode(this.urlencode(extendedParams)), this.encode(this.secret), sha256.sha256);
1219
+ const query = this.urlencode(extendedParams);
1220
+ let signature = undefined;
1221
+ if (this.secret.indexOf('PRIVATE KEY') > -1) {
1222
+ if (this.secret.length > 120) {
1223
+ signature = rsa.rsa(query, this.secret, sha256.sha256);
1224
+ }
1225
+ else {
1226
+ signature = crypto.eddsa(this.encode(query), this.secret, ed25519.ed25519);
1227
+ }
1228
+ }
1229
+ else {
1230
+ signature = this.hmac(this.encode(query), this.encode(this.secret), sha256.sha256);
1231
+ }
1232
+ extendedParams['signature'] = signature;
1217
1233
  return extendedParams;
1218
1234
  }
1219
1235
  async authenticate(params = {}) {
@@ -2532,6 +2548,15 @@ class binance extends binance$1 {
2532
2548
  }
2533
2549
  }
2534
2550
  handleWsError(client, message) {
2551
+ //
2552
+ // {
2553
+ // "error": {
2554
+ // "code": 2,
2555
+ // "msg": "Invalid request: invalid stream"
2556
+ // },
2557
+ // "id": 1
2558
+ // }
2559
+ //
2535
2560
  const id = this.safeString(message, 'id');
2536
2561
  let rejected = false;
2537
2562
  const error = this.safeValue(message, 'error', {});
@@ -2542,7 +2567,17 @@ class binance extends binance$1 {
2542
2567
  }
2543
2568
  catch (e) {
2544
2569
  rejected = true;
2570
+ // private endpoint uses id as messageHash
2545
2571
  client.reject(e, id);
2572
+ // public endpoint stores messageHash in subscriptios
2573
+ const subscriptionKeys = Object.keys(client.subscriptions);
2574
+ for (let i = 0; i < subscriptionKeys.length; i++) {
2575
+ const subscriptionHash = subscriptionKeys[i];
2576
+ const subscriptionId = this.safeString(client.subscriptions[subscriptionHash], 'id');
2577
+ if (id === subscriptionId) {
2578
+ client.reject(e, subscriptionHash);
2579
+ }
2580
+ }
2546
2581
  }
2547
2582
  if (!rejected) {
2548
2583
  client.reject(message, id);
@@ -2555,7 +2590,8 @@ class binance extends binance$1 {
2555
2590
  handleMessage(client, message) {
2556
2591
  // handle WebSocketAPI
2557
2592
  const status = this.safeString(message, 'status');
2558
- if (status !== undefined && status !== '200') {
2593
+ const error = this.safeValue(message, 'error');
2594
+ if ((error !== undefined) || (status !== undefined && status !== '200')) {
2559
2595
  return this.handleWsError(client, message);
2560
2596
  }
2561
2597
  const id = this.safeString(message, 'id');