ccxt 4.2.30 → 4.2.31

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.
@@ -26,11 +26,13 @@ class bitfinex2 extends bitfinex2$1 {
26
26
  'CORS': undefined,
27
27
  'spot': true,
28
28
  'margin': undefined,
29
- 'swap': undefined,
29
+ 'swap': true,
30
30
  'future': undefined,
31
31
  'option': undefined,
32
+ 'addMargin': false,
32
33
  'cancelAllOrders': true,
33
34
  'cancelOrder': true,
35
+ 'cancelOrders': true,
34
36
  'createDepositAddress': true,
35
37
  'createLimitOrder': true,
36
38
  'createMarketOrder': true,
@@ -39,23 +41,27 @@ class bitfinex2 extends bitfinex2$1 {
39
41
  'createStopLimitOrder': true,
40
42
  'createStopMarketOrder': true,
41
43
  'createStopOrder': true,
42
- 'createTriggerOrder': true,
43
44
  'createTrailingAmountOrder': true,
44
45
  'createTrailingPercentOrder': false,
45
- 'editOrder': false,
46
+ 'createTriggerOrder': true,
47
+ 'editOrder': true,
46
48
  'fetchBalance': true,
47
49
  'fetchClosedOrder': true,
48
50
  'fetchClosedOrders': true,
49
51
  'fetchCurrencies': true,
50
52
  'fetchDepositAddress': true,
51
53
  'fetchDepositsWithdrawals': true,
54
+ 'fetchFundingHistory': false,
52
55
  'fetchFundingRate': true,
53
56
  'fetchFundingRateHistory': true,
54
57
  'fetchFundingRates': true,
55
58
  'fetchIndexOHLCV': false,
56
59
  'fetchLedger': true,
60
+ 'fetchLeverage': false,
61
+ 'fetchLeverageTiers': false,
57
62
  'fetchLiquidations': true,
58
63
  'fetchMarginMode': false,
64
+ 'fetchMarketLeverageTiers': false,
59
65
  'fetchMarkOHLCV': false,
60
66
  'fetchMyTrades': true,
61
67
  'fetchOHLCV': true,
@@ -65,7 +71,10 @@ class bitfinex2 extends bitfinex2$1 {
65
71
  'fetchOpenOrders': true,
66
72
  'fetchOrder': true,
67
73
  'fetchOrderTrades': true,
74
+ 'fetchPosition': false,
68
75
  'fetchPositionMode': false,
76
+ 'fetchPositions': true,
77
+ 'fetchPremiumIndexOHLCV': false,
69
78
  'fetchStatus': true,
70
79
  'fetchTickers': true,
71
80
  'fetchTime': false,
@@ -73,7 +82,11 @@ class bitfinex2 extends bitfinex2$1 {
73
82
  'fetchTradingFees': true,
74
83
  'fetchTransactionFees': undefined,
75
84
  'fetchTransactions': 'emulated',
85
+ 'reduceMargin': false,
86
+ 'setLeverage': false,
76
87
  'setMargin': true,
88
+ 'setMarginMode': false,
89
+ 'setPositionMode': false,
77
90
  'withdraw': true,
78
91
  },
79
92
  'timeframes': {
@@ -341,6 +354,7 @@ class bitfinex2 extends bitfinex2$1 {
341
354
  'margin': 'margin',
342
355
  'derivatives': 'margin',
343
356
  'future': 'margin',
357
+ 'swap': 'margin',
344
358
  },
345
359
  'withdraw': {
346
360
  'includeFee': false,
@@ -997,7 +1011,7 @@ class bitfinex2 extends bitfinex2$1 {
997
1011
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
998
1012
  * @see https://docs.bitfinex.com/reference/rest-public-book
999
1013
  * @param {string} symbol unified symbol of the market to fetch the order book for
1000
- * @param {int} [limit] the maximum amount of order book entries to return
1014
+ * @param {int} [limit] the maximum amount of order book entries to return, bitfinex only allows 1, 25, or 100
1001
1015
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1002
1016
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1003
1017
  */
@@ -1009,7 +1023,7 @@ class bitfinex2 extends bitfinex2$1 {
1009
1023
  'precision': precision,
1010
1024
  };
1011
1025
  if (limit !== undefined) {
1012
- request['len'] = limit; // 25 or 100
1026
+ request['len'] = limit;
1013
1027
  }
1014
1028
  const fullRequest = this.extend(request, params);
1015
1029
  const orderbook = await this.publicGetBookSymbolPrecision(fullRequest);
@@ -1281,9 +1295,9 @@ class bitfinex2 extends bitfinex2$1 {
1281
1295
  * @see https://docs.bitfinex.com/reference/rest-public-trades
1282
1296
  * @param {string} symbol unified symbol of the market to fetch trades for
1283
1297
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
1284
- * @param {int} [limit] the maximum amount of trades to fetch
1298
+ * @param {int} [limit] the maximum amount of trades to fetch, default 120, max 10000
1285
1299
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1286
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1300
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1287
1301
  * @param {int} [params.until] the latest time in ms to fetch entries for
1288
1302
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1289
1303
  */
@@ -1330,11 +1344,11 @@ class bitfinex2 extends bitfinex2$1 {
1330
1344
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1331
1345
  * @param {string} timeframe the length of time each candle represents
1332
1346
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
1333
- * @param {int} [limit] the maximum amount of candles to fetch
1347
+ * @param {int} [limit] the maximum amount of candles to fetch, default 100 max 10000
1334
1348
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1335
1349
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1336
1350
  * @param {int} [params.until] timestamp in ms of the latest candle to fetch
1337
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1351
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1338
1352
  */
1339
1353
  await this.loadMarkets();
1340
1354
  let paginate = false;
@@ -1344,7 +1358,7 @@ class bitfinex2 extends bitfinex2$1 {
1344
1358
  }
1345
1359
  const market = this.market(symbol);
1346
1360
  if (limit === undefined) {
1347
- limit = 10000; // default 100, max 5000
1361
+ limit = 10000;
1348
1362
  }
1349
1363
  let request = {
1350
1364
  'symbol': market['id'],
@@ -1492,30 +1506,20 @@ class bitfinex2 extends bitfinex2$1 {
1492
1506
  'trades': undefined,
1493
1507
  }, market);
1494
1508
  }
1495
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1509
+ createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1496
1510
  /**
1497
1511
  * @method
1498
- * @name bitfinex2#createOrder
1499
- * @description create an order on the exchange
1500
- * @see https://docs.bitfinex.com/reference/rest-auth-submit-order
1501
- * @param {string} symbol unified CCXT market symbol
1502
- * @param {string} type 'limit' or 'market'
1512
+ * @ignore
1513
+ * @name bitfinex2#createOrderRequest
1514
+ * @description helper function to build an order request
1515
+ * @param {string} symbol unified symbol of the market to create an order in
1516
+ * @param {string} type 'market' or 'limit'
1503
1517
  * @param {string} side 'buy' or 'sell'
1504
- * @param {float} amount the amount of currency to trade
1505
- * @param {float} [price] price of the order
1518
+ * @param {float} amount how much you want to trade in units of the base currency
1519
+ * @param {float} [price] the price of the order, in units of the quote currency, ignored in market orders
1506
1520
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1507
- * @param {float} [params.stopPrice] the price that triggers a trigger order
1508
- * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
1509
- * @param {boolean} [params.postOnly] set to true if you want to make a post only order
1510
- * @param {boolean} [params.reduceOnly] indicates that the order is to reduce the size of a position
1511
- * @param {int} [params.flags] additional order parameters: 4096 (Post Only), 1024 (Reduce Only), 16384 (OCO), 64 (Hidden), 512 (Close), 524288 (No Var Rates)
1512
- * @param {int} [params.lev] leverage for a derivative order, supported by derivative symbol orders only. The value should be between 1 and 100 inclusive.
1513
- * @param {string} [params.price_aux_limit] order price for stop limit orders
1514
- * @param {string} [params.price_oco_stop] OCO stop price
1515
- * @param {string} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
1516
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1521
+ * @returns {object} request to be sent to the exchange
1517
1522
  */
1518
- await this.loadMarkets();
1519
1523
  const market = this.market(symbol);
1520
1524
  let amountString = this.amountToPrecision(symbol, amount);
1521
1525
  amountString = (side === 'buy') ? amountString : Precise["default"].stringNeg(amountString);
@@ -1529,7 +1533,6 @@ class bitfinex2 extends bitfinex2$1 {
1529
1533
  const postOnlyParam = this.safeBool(params, 'postOnly', false);
1530
1534
  const reduceOnly = this.safeBool(params, 'reduceOnly', false);
1531
1535
  const clientOrderId = this.safeValue2(params, 'cid', 'clientOrderId');
1532
- params = this.omit(params, ['triggerPrice', 'stopPrice', 'timeInForce', 'postOnly', 'reduceOnly', 'trailingAmount', 'clientOrderId']);
1533
1536
  let orderType = type.toUpperCase();
1534
1537
  if (trailingAmount !== undefined) {
1535
1538
  orderType = 'TRAILING STOP';
@@ -1585,7 +1588,36 @@ class bitfinex2 extends bitfinex2$1 {
1585
1588
  if (clientOrderId !== undefined) {
1586
1589
  request['cid'] = clientOrderId;
1587
1590
  }
1588
- const response = await this.privatePostAuthWOrderSubmit(this.extend(request, params));
1591
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'timeInForce', 'postOnly', 'reduceOnly', 'trailingAmount', 'clientOrderId']);
1592
+ return this.extend(request, params);
1593
+ }
1594
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1595
+ /**
1596
+ * @method
1597
+ * @name bitfinex2#createOrder
1598
+ * @description create an order on the exchange
1599
+ * @see https://docs.bitfinex.com/reference/rest-auth-submit-order
1600
+ * @param {string} symbol unified CCXT market symbol
1601
+ * @param {string} type 'limit' or 'market'
1602
+ * @param {string} side 'buy' or 'sell'
1603
+ * @param {float} amount the amount of currency to trade
1604
+ * @param {float} [price] price of the order
1605
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1606
+ * @param {float} [params.stopPrice] the price that triggers a trigger order
1607
+ * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
1608
+ * @param {boolean} [params.postOnly] set to true if you want to make a post only order
1609
+ * @param {boolean} [params.reduceOnly] indicates that the order is to reduce the size of a position
1610
+ * @param {int} [params.flags] additional order parameters: 4096 (Post Only), 1024 (Reduce Only), 16384 (OCO), 64 (Hidden), 512 (Close), 524288 (No Var Rates)
1611
+ * @param {int} [params.lev] leverage for a derivative order, supported by derivative symbol orders only. The value should be between 1 and 100 inclusive.
1612
+ * @param {string} [params.price_aux_limit] order price for stop limit orders
1613
+ * @param {string} [params.price_oco_stop] OCO stop price
1614
+ * @param {string} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
1615
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1616
+ */
1617
+ await this.loadMarkets();
1618
+ const market = this.market(symbol);
1619
+ const request = this.createOrderRequest(symbol, type, side, amount, price, params);
1620
+ const response = await this.privatePostAuthWOrderSubmit(request);
1589
1621
  //
1590
1622
  // [
1591
1623
  // 1653325121, // Timestamp in milliseconds
@@ -1643,6 +1675,67 @@ class bitfinex2 extends bitfinex2$1 {
1643
1675
  const order = this.safeList(orders, 0);
1644
1676
  return this.parseOrder(order, market);
1645
1677
  }
1678
+ async createOrders(orders, params = {}) {
1679
+ /**
1680
+ * @method
1681
+ * @name bitfinex2#createOrders
1682
+ * @description create a list of trade orders
1683
+ * @see https://docs.bitfinex.com/reference/rest-auth-order-multi
1684
+ * @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
1685
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1686
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1687
+ */
1688
+ await this.loadMarkets();
1689
+ const ordersRequests = [];
1690
+ for (let i = 0; i < orders.length; i++) {
1691
+ const rawOrder = orders[i];
1692
+ const symbol = this.safeString(rawOrder, 'symbol');
1693
+ const type = this.safeString(rawOrder, 'type');
1694
+ const side = this.safeString(rawOrder, 'side');
1695
+ const amount = this.safeNumber(rawOrder, 'amount');
1696
+ const price = this.safeNumber(rawOrder, 'price');
1697
+ const orderParams = this.safeDict(rawOrder, 'params', {});
1698
+ const orderRequest = this.createOrderRequest(symbol, type, side, amount, price, orderParams);
1699
+ ordersRequests.push(['on', orderRequest]);
1700
+ }
1701
+ const request = {
1702
+ 'ops': ordersRequests,
1703
+ };
1704
+ const response = await this.privatePostAuthWOrderMulti(request);
1705
+ //
1706
+ // [
1707
+ // 1706762515553,
1708
+ // "ox_multi-req",
1709
+ // null,
1710
+ // null,
1711
+ // [
1712
+ // [
1713
+ // 1706762515,
1714
+ // "on-req",
1715
+ // null,
1716
+ // null,
1717
+ // [
1718
+ // [139567428547,null,1706762515551,"tBTCUST",1706762515551,1706762515551,0.0001,0.0001,"EXCHANGE LIMIT",null,null,null,0,"ACTIVE",null,null,35000,0,0,0,null,null,null,0,0,null,null,null,"API>BFX",null,null,{}]
1719
+ // ],
1720
+ // null,
1721
+ // "SUCCESS",
1722
+ // "Submitting 1 orders."
1723
+ // ],
1724
+ // ],
1725
+ // null,
1726
+ // "SUCCESS",
1727
+ // "Submitting 2 order operations."
1728
+ // ]
1729
+ //
1730
+ const results = [];
1731
+ const data = this.safeList(response, 4, []);
1732
+ for (let i = 0; i < data.length; i++) {
1733
+ const entry = data[i];
1734
+ const individualOrder = entry[4];
1735
+ results.push(individualOrder[0]);
1736
+ }
1737
+ return this.parseOrders(results);
1738
+ }
1646
1739
  async cancelAllOrders(symbol = undefined, params = {}) {
1647
1740
  /**
1648
1741
  * @method
@@ -1653,6 +1746,7 @@ class bitfinex2 extends bitfinex2$1 {
1653
1746
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1654
1747
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1655
1748
  */
1749
+ await this.loadMarkets();
1656
1750
  const request = {
1657
1751
  'all': 1,
1658
1752
  };
@@ -1671,6 +1765,7 @@ class bitfinex2 extends bitfinex2$1 {
1671
1765
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1672
1766
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1673
1767
  */
1768
+ await this.loadMarkets();
1674
1769
  const cid = this.safeValue2(params, 'cid', 'clientOrderId'); // client order id
1675
1770
  let request = undefined;
1676
1771
  if (cid !== undefined) {
@@ -1693,6 +1788,82 @@ class bitfinex2 extends bitfinex2$1 {
1693
1788
  const order = this.safeValue(response, 4);
1694
1789
  return this.parseOrder(order);
1695
1790
  }
1791
+ async cancelOrders(ids, symbol = undefined, params = {}) {
1792
+ /**
1793
+ * @method
1794
+ * @name bitfinex2#cancelOrders
1795
+ * @description cancel multiple orders at the same time
1796
+ * @see https://docs.bitfinex.com/reference/rest-auth-cancel-orders-multiple
1797
+ * @param {string[]} ids order ids
1798
+ * @param {string} symbol unified market symbol, default is undefined
1799
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1800
+ * @returns {object} an array of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1801
+ */
1802
+ await this.loadMarkets();
1803
+ for (let i = 0; i < ids.length; i++) {
1804
+ ids[i] = this.parseToNumeric(ids[i]);
1805
+ }
1806
+ const request = {
1807
+ 'id': ids,
1808
+ };
1809
+ let market = undefined;
1810
+ if (symbol !== undefined) {
1811
+ market = this.market(symbol);
1812
+ }
1813
+ const response = await this.privatePostAuthWOrderCancelMulti(this.extend(request, params));
1814
+ //
1815
+ // [
1816
+ // 1706740198811,
1817
+ // "oc_multi-req",
1818
+ // null,
1819
+ // null,
1820
+ // [
1821
+ // [
1822
+ // 139530205057,
1823
+ // null,
1824
+ // 1706740132275,
1825
+ // "tBTCF0:USTF0",
1826
+ // 1706740132276,
1827
+ // 1706740132276,
1828
+ // 0.0001,
1829
+ // 0.0001,
1830
+ // "LIMIT",
1831
+ // null,
1832
+ // null,
1833
+ // null,
1834
+ // 0,
1835
+ // "ACTIVE",
1836
+ // null,
1837
+ // null,
1838
+ // 39000,
1839
+ // 0,
1840
+ // 0,
1841
+ // 0,
1842
+ // null,
1843
+ // null,
1844
+ // null,
1845
+ // 0,
1846
+ // 0,
1847
+ // null,
1848
+ // null,
1849
+ // null,
1850
+ // "API>BFX",
1851
+ // null,
1852
+ // null,
1853
+ // {
1854
+ // "lev": 10,
1855
+ // "$F33": 10
1856
+ // }
1857
+ // ],
1858
+ // ],
1859
+ // null,
1860
+ // "SUCCESS",
1861
+ // "Submitting 2 order cancellations."
1862
+ // ]
1863
+ //
1864
+ const orders = this.safeList(response, 4, []);
1865
+ return this.parseOrders(orders, market);
1866
+ }
1696
1867
  async fetchOpenOrder(id, symbol = undefined, params = {}) {
1697
1868
  /**
1698
1869
  * @method
@@ -2702,14 +2873,13 @@ class bitfinex2 extends bitfinex2$1 {
2702
2873
  * @see https://docs.bitfinex.com/reference/rest-auth-ledgers
2703
2874
  * @param {string} code unified currency code, default is undefined
2704
2875
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
2705
- * @param {int} [limit] max number of ledger entrys to return, default is undefined
2876
+ * @param {int} [limit] max number of ledger entrys to return, default is undefined max is 2500
2706
2877
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2707
2878
  * @param {int} [params.until] timestamp in ms of the latest ledger entry
2708
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2879
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2709
2880
  * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
2710
2881
  */
2711
2882
  await this.loadMarkets();
2712
- await this.loadMarkets();
2713
2883
  let paginate = false;
2714
2884
  [paginate, params] = this.handleOptionAndParams(params, 'fetchLedger', 'paginate');
2715
2885
  if (paginate) {
@@ -2721,7 +2891,7 @@ class bitfinex2 extends bitfinex2$1 {
2721
2891
  request['start'] = since;
2722
2892
  }
2723
2893
  if (limit !== undefined) {
2724
- request['limit'] = limit; // max 2500
2894
+ request['limit'] = limit;
2725
2895
  }
2726
2896
  [request, params] = this.handleUntilOption('end', request, params);
2727
2897
  let response = undefined;
@@ -2753,7 +2923,7 @@ class bitfinex2 extends bitfinex2$1 {
2753
2923
  async fetchFundingRate(symbol, params = {}) {
2754
2924
  /**
2755
2925
  * @method
2756
- * @name bitfine#fetchFundingRate
2926
+ * @name bitfinex2#fetchFundingRate
2757
2927
  * @description fetch the current funding rate
2758
2928
  * @see https://docs.bitfinex.com/reference/rest-public-derivatives-status
2759
2929
  * @param {string} symbol unified market symbol
@@ -2765,7 +2935,7 @@ class bitfinex2 extends bitfinex2$1 {
2765
2935
  async fetchFundingRates(symbols = undefined, params = {}) {
2766
2936
  /**
2767
2937
  * @method
2768
- * @name bitfine#fetchFundingRate
2938
+ * @name bitfinex2#fetchFundingRate
2769
2939
  * @description fetch the current funding rate
2770
2940
  * @see https://docs.bitfinex.com/reference/rest-public-derivatives-status
2771
2941
  * @param {string[]} symbols list of unified market symbols
@@ -2816,13 +2986,15 @@ class bitfinex2 extends bitfinex2$1 {
2816
2986
  async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2817
2987
  /**
2818
2988
  * @method
2819
- * @name bitfine#fetchFundingRateHistory
2989
+ * @name bitfinex2#fetchFundingRateHistory
2820
2990
  * @description fetches historical funding rate prices
2821
2991
  * @see https://docs.bitfinex.com/reference/rest-public-derivatives-status-history
2822
2992
  * @param {string} symbol unified market symbol
2993
+ * @param {int} [since] timestamp in ms of the earliest funding rate entry
2994
+ * @param {int} [limit] max number of funding rate entrys to return
2823
2995
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2824
2996
  * @param {int} [params.until] timestamp in ms of the latest funding rate
2825
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2997
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2826
2998
  * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
2827
2999
  */
2828
3000
  if (symbol === undefined) {
@@ -2879,7 +3051,15 @@ class bitfinex2 extends bitfinex2$1 {
2879
3051
  const rate = this.parseFundingRateHistory(fr, market);
2880
3052
  rates.push(rate);
2881
3053
  }
2882
- return this.filterBySymbolSinceLimit(rates, symbol, since, limit);
3054
+ const reversedArray = [];
3055
+ const rawRates = this.filterBySymbolSinceLimit(rates, symbol, since, limit);
3056
+ const rawRatesLength = rawRates.length;
3057
+ const ratesLength = Math.max(rawRatesLength - 1, 0);
3058
+ for (let i = ratesLength; i >= 0; i--) {
3059
+ const valueAtIndex = rawRates[i];
3060
+ reversedArray.push(valueAtIndex);
3061
+ }
3062
+ return reversedArray;
2883
3063
  }
2884
3064
  parseFundingRate(contract, market = undefined) {
2885
3065
  //
@@ -3029,7 +3209,8 @@ class bitfinex2 extends bitfinex2$1 {
3029
3209
  // ]
3030
3210
  // ]
3031
3211
  //
3032
- return this.parseOpenInterest(response[0], market);
3212
+ const oi = this.safeList(response, 0);
3213
+ return this.parseOpenInterest(oi, market);
3033
3214
  }
3034
3215
  async fetchOpenInterestHistory(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
3035
3216
  /**
@@ -3300,6 +3481,199 @@ class bitfinex2 extends bitfinex2$1 {
3300
3481
  'status': marginStatus,
3301
3482
  };
3302
3483
  }
3484
+ async fetchOrder(id, symbol = undefined, params = {}) {
3485
+ /**
3486
+ * @method
3487
+ * @name bitfinex2#fetchOrder
3488
+ * @description fetches information on an order made by the user
3489
+ * @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
3490
+ * @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol
3491
+ * @param {string} id the order id
3492
+ * @param {string} [symbol] unified symbol of the market the order was made in
3493
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3494
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3495
+ */
3496
+ await this.loadMarkets();
3497
+ const request = {
3498
+ 'id': [this.parseToNumeric(id)],
3499
+ };
3500
+ let market = undefined;
3501
+ let response = undefined;
3502
+ if (symbol === undefined) {
3503
+ response = await this.privatePostAuthROrders(this.extend(request, params));
3504
+ }
3505
+ else {
3506
+ market = this.market(symbol);
3507
+ request['symbol'] = market['id'];
3508
+ response = await this.privatePostAuthROrdersSymbol(this.extend(request, params));
3509
+ }
3510
+ //
3511
+ // [
3512
+ // [
3513
+ // 139658969116,
3514
+ // null,
3515
+ // 1706843908637,
3516
+ // "tBTCUST",
3517
+ // 1706843908637,
3518
+ // 1706843908638,
3519
+ // 0.0001,
3520
+ // 0.0001,
3521
+ // "EXCHANGE LIMIT",
3522
+ // null,
3523
+ // null,
3524
+ // null,
3525
+ // 0,
3526
+ // "ACTIVE",
3527
+ // null,
3528
+ // null,
3529
+ // 35000,
3530
+ // 0,
3531
+ // 0,
3532
+ // 0,
3533
+ // null,
3534
+ // null,
3535
+ // null,
3536
+ // 0,
3537
+ // 0,
3538
+ // null,
3539
+ // null,
3540
+ // null,
3541
+ // "API>BFX",
3542
+ // null,
3543
+ // null,
3544
+ // {}
3545
+ // ]
3546
+ // ]
3547
+ //
3548
+ const order = this.safeList(response, 0);
3549
+ return this.parseOrder(order, market);
3550
+ }
3551
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
3552
+ /**
3553
+ * @method
3554
+ * @name bitfinex2#editOrder
3555
+ * @description edit a trade order
3556
+ * @see https://docs.bitfinex.com/reference/rest-auth-update-order
3557
+ * @param {string} id edit order id
3558
+ * @param {string} symbol unified symbol of the market to edit an order in
3559
+ * @param {string} type 'market' or 'limit'
3560
+ * @param {string} side 'buy' or 'sell'
3561
+ * @param {float} amount how much you want to trade in units of the base currency
3562
+ * @param {float} [price] the price that the order is to be fullfilled, in units of the quote currency, ignored in market orders
3563
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3564
+ * @param {float} [params.stopPrice] the price that triggers a trigger order
3565
+ * @param {boolean} [params.postOnly] set to true if you want to make a post only order
3566
+ * @param {boolean} [params.reduceOnly] indicates that the order is to reduce the size of a position
3567
+ * @param {int} [params.flags] additional order parameters: 4096 (Post Only), 1024 (Reduce Only), 16384 (OCO), 64 (Hidden), 512 (Close), 524288 (No Var Rates)
3568
+ * @param {int} [params.leverage] leverage for a derivative order, supported by derivative symbol orders only, the value should be between 1 and 100 inclusive
3569
+ * @param {int} [params.clientOrderId] a unique client order id for the order
3570
+ * @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
3571
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3572
+ */
3573
+ await this.loadMarkets();
3574
+ const market = this.market(symbol);
3575
+ const request = {
3576
+ 'id': this.parseToNumeric(id),
3577
+ };
3578
+ if (amount !== undefined) {
3579
+ let amountString = this.amountToPrecision(symbol, amount);
3580
+ amountString = (side === 'buy') ? amountString : Precise["default"].stringNeg(amountString);
3581
+ request['amount'] = amountString;
3582
+ }
3583
+ const stopPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
3584
+ const trailingAmount = this.safeString(params, 'trailingAmount');
3585
+ const timeInForce = this.safeString(params, 'timeInForce');
3586
+ const postOnlyParam = this.safeBool(params, 'postOnly', false);
3587
+ const reduceOnly = this.safeBool(params, 'reduceOnly', false);
3588
+ const clientOrderId = this.safeInteger2(params, 'cid', 'clientOrderId');
3589
+ if (trailingAmount !== undefined) {
3590
+ request['price_trailing'] = trailingAmount;
3591
+ }
3592
+ else if (stopPrice !== undefined) {
3593
+ // request['price'] is taken as stopPrice for stop orders
3594
+ request['price'] = this.priceToPrecision(symbol, stopPrice);
3595
+ if (type === 'limit') {
3596
+ request['price_aux_limit'] = this.priceToPrecision(symbol, price);
3597
+ }
3598
+ }
3599
+ const postOnly = (postOnlyParam || (timeInForce === 'PO'));
3600
+ if ((type !== 'market') && (stopPrice === undefined)) {
3601
+ request['price'] = this.priceToPrecision(symbol, price);
3602
+ }
3603
+ // flag values may be summed to combine flags
3604
+ let flags = 0;
3605
+ if (postOnly) {
3606
+ flags = this.sum(flags, 4096);
3607
+ }
3608
+ if (reduceOnly) {
3609
+ flags = this.sum(flags, 1024);
3610
+ }
3611
+ if (flags !== 0) {
3612
+ request['flags'] = flags;
3613
+ }
3614
+ if (clientOrderId !== undefined) {
3615
+ request['cid'] = clientOrderId;
3616
+ }
3617
+ const leverage = this.safeInteger2(params, 'leverage', 'lev');
3618
+ if (leverage !== undefined) {
3619
+ request['lev'] = leverage;
3620
+ }
3621
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'timeInForce', 'postOnly', 'reduceOnly', 'trailingAmount', 'clientOrderId', 'leverage']);
3622
+ const response = await this.privatePostAuthWOrderUpdate(this.extend(request, params));
3623
+ //
3624
+ // [
3625
+ // 1706845376402,
3626
+ // "ou-req",
3627
+ // null,
3628
+ // null,
3629
+ // [
3630
+ // 139658969116,
3631
+ // null,
3632
+ // 1706843908637,
3633
+ // "tBTCUST",
3634
+ // 1706843908637,
3635
+ // 1706843908638,
3636
+ // 0.0002,
3637
+ // 0.0002,
3638
+ // "EXCHANGE LIMIT",
3639
+ // null,
3640
+ // null,
3641
+ // null,
3642
+ // 0,
3643
+ // "ACTIVE",
3644
+ // null,
3645
+ // null,
3646
+ // 35000,
3647
+ // 0,
3648
+ // 0,
3649
+ // 0,
3650
+ // null,
3651
+ // null,
3652
+ // null,
3653
+ // 0,
3654
+ // 0,
3655
+ // null,
3656
+ // null,
3657
+ // null,
3658
+ // "API>BFX",
3659
+ // null,
3660
+ // null,
3661
+ // {}
3662
+ // ],
3663
+ // null,
3664
+ // "SUCCESS",
3665
+ // "Submitting update to exchange limit buy order for 0.0002 BTC."
3666
+ // ]
3667
+ //
3668
+ const status = this.safeString(response, 6);
3669
+ if (status !== 'SUCCESS') {
3670
+ const errorCode = response[5];
3671
+ const errorText = response[7];
3672
+ throw new errors.ExchangeError(this.id + ' ' + response[6] + ': ' + errorText + ' (#' + errorCode + ')');
3673
+ }
3674
+ const order = this.safeList(response, 4, []);
3675
+ return this.parseOrder(order, market);
3676
+ }
3303
3677
  }
3304
3678
 
3305
3679
  module.exports = bitfinex2;