ccxt 4.1.2 → 4.1.4

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
@@ -179,7 +179,7 @@ var woo$1 = require('./src/pro/woo.js');
179
179
 
180
180
  //-----------------------------------------------------------------------------
181
181
  // this is updated by vss.js when building
182
- const version = '4.1.2';
182
+ const version = '4.1.4';
183
183
  Exchange["default"].ccxtVersion = version;
184
184
  const exchanges = {
185
185
  'ace': ace,
@@ -1680,6 +1680,9 @@ class Exchange {
1680
1680
  if (!tradesAreParsed) {
1681
1681
  trades = this.parseTrades(rawTrades, market);
1682
1682
  }
1683
+ else {
1684
+ trades = rawTrades;
1685
+ }
1683
1686
  this.number = oldNumber;
1684
1687
  let tradesLength = 0;
1685
1688
  const isArray = Array.isArray(trades);
@@ -1525,6 +1525,8 @@ class bingx extends bingx$1 {
1525
1525
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1526
1526
  * @param {object} [params] extra parameters specific to the bingx api endpoint
1527
1527
  * @param {bool} [params.postOnly] true to place a post only order
1528
+ * @param {string} [params.timeInForce] spot supports 'PO' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
1529
+ * @param {bool} [params.reduceOnly] *swap only* true or false whether the order is reduce only
1528
1530
  * @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
1529
1531
  * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
1530
1532
  * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
@@ -1532,8 +1534,10 @@ class bingx extends bingx$1 {
1532
1534
  */
1533
1535
  await this.loadMarkets();
1534
1536
  const market = this.market(symbol);
1537
+ let postOnly = undefined;
1535
1538
  let response = undefined;
1536
- const [marketType, query] = this.handleMarketTypeAndParams('createOrder', market, params);
1539
+ let marketType = undefined;
1540
+ [marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
1537
1541
  type = type.toUpperCase();
1538
1542
  const request = {
1539
1543
  'symbol': market['id'],
@@ -1541,51 +1545,16 @@ class bingx extends bingx$1 {
1541
1545
  'side': side.toUpperCase(),
1542
1546
  };
1543
1547
  const isMarketOrder = type === 'MARKET';
1544
- const isSpotMarket = marketType === 'spot';
1545
- let stopPriceRaw = undefined;
1546
- let stopPrice = undefined;
1547
- let stopLossPrice = undefined;
1548
- let takeProfitPrice = undefined;
1549
- if (!isSpotMarket) {
1550
- stopPriceRaw = this.safeValue2(params, 'stopPrice', 'triggerPrice');
1551
- if (stopPriceRaw !== undefined) {
1552
- stopPrice = this.priceToPrecision(symbol, stopPriceRaw);
1553
- }
1554
- stopLossPrice = this.safeValue(params, 'stopLossPrice');
1555
- takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
1556
- }
1557
- if ((stopLossPrice !== undefined) && (takeProfitPrice !== undefined)) {
1558
- throw new errors.InvalidOrder('Order is either a takeProfit order or a stopLoss order');
1559
- }
1560
- if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT')) {
1561
- request['price'] = this.priceToPrecision(symbol, price);
1562
- if ((stopPrice !== undefined)) {
1563
- request['type'] = 'TRIGGER_LIMIT';
1564
- request['stopPrice'] = stopPrice;
1565
- }
1566
- if (type === 'TRIGGER_LIMIT') {
1567
- if (stopPrice === undefined) {
1568
- throw new errors.InvalidOrder('TRIGGER_LIMIT requires a triggerPrice / stopPrice');
1569
- }
1570
- request['stopPrice'] = stopPrice;
1571
- }
1572
- }
1573
- if (isMarketOrder || (type === 'TRIGGER_MARKET')) {
1574
- if ((stopPrice !== undefined)) {
1575
- request['type'] = 'TRIGGER_MARKET';
1576
- request['stopPrice'] = stopPrice;
1548
+ const isSpot = marketType === 'spot';
1549
+ const timeInForce = this.safeStringUpper(params, 'timeInForce');
1550
+ if (timeInForce === 'IOC') {
1551
+ request['timeInForce'] = 'IOC';
1552
+ }
1553
+ if (isSpot) {
1554
+ [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'POC', params);
1555
+ if (postOnly || (timeInForce === 'POC')) {
1556
+ request['timeInForce'] = 'POC';
1577
1557
  }
1578
- if (type === 'TRIGGER_MARKET') {
1579
- if (stopPrice === undefined) {
1580
- throw new errors.InvalidOrder('TRIGGER_MARKET requires a triggerPrice / stopPrice');
1581
- }
1582
- request['stopPrice'] = stopPrice;
1583
- }
1584
- }
1585
- const exchangeSpecificTifParam = this.safeStringUpperN(params, ['force', 'timeInForce']);
1586
- let postOnly = undefined;
1587
- [postOnly, params] = this.handlePostOnly(isMarketOrder, exchangeSpecificTifParam === 'POC', params);
1588
- if (isSpotMarket) {
1589
1558
  const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1590
1559
  if (createMarketBuyOrderRequiresPrice && isMarketOrder && (side === 'buy')) {
1591
1560
  if (price === undefined) {
@@ -1601,35 +1570,77 @@ class bingx extends bingx$1 {
1601
1570
  else {
1602
1571
  request['quantity'] = this.amountToPrecision(symbol, amount);
1603
1572
  }
1573
+ if (!isMarketOrder) {
1574
+ request['price'] = this.priceToPrecision(symbol, price);
1575
+ }
1576
+ response = await this.spotV1PrivatePostTradeOrder(this.extend(request, params));
1604
1577
  }
1605
1578
  else {
1579
+ [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'PostOnly', params);
1580
+ if (postOnly || (timeInForce === 'PostOnly')) {
1581
+ request['timeInForce'] = 'PostOnly';
1582
+ }
1583
+ else if (timeInForce === 'GTC') {
1584
+ request['timeInForce'] = 'GTC';
1585
+ }
1586
+ else if (timeInForce === 'FOK') {
1587
+ request['timeInForce'] = 'FOK';
1588
+ }
1589
+ if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) {
1590
+ request['price'] = this.priceToPrecision(symbol, price);
1591
+ }
1592
+ const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
1593
+ const stopLossPrice = this.safeNumber(params, 'stopLossPrice');
1594
+ const takeProfitPrice = this.safeNumber(params, 'takeProfitPrice');
1595
+ const isTriggerOrder = triggerPrice !== undefined;
1596
+ const isStopLossPriceOrder = stopLossPrice !== undefined;
1597
+ const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
1598
+ if (isTriggerOrder) {
1599
+ request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
1600
+ if (isMarketOrder || (type === 'TRIGGER_MARKET')) {
1601
+ request['type'] = 'TRIGGER_MARKET';
1602
+ }
1603
+ else if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT')) {
1604
+ request['type'] = 'TRIGGER_LIMIT';
1605
+ }
1606
+ }
1607
+ else if (isStopLossPriceOrder || isTakeProfitPriceOrder) {
1608
+ // This can be used to set the stop loss and take profit, but the position needs to be opened first
1609
+ if (isStopLossPriceOrder) {
1610
+ request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
1611
+ if (isMarketOrder || (type === 'STOP_MARKET')) {
1612
+ request['type'] = 'STOP_MARKET';
1613
+ }
1614
+ else if ((type === 'LIMIT') || (type === 'STOP')) {
1615
+ request['type'] = 'STOP';
1616
+ }
1617
+ }
1618
+ else if (isTakeProfitPriceOrder) {
1619
+ request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
1620
+ if (isMarketOrder || (type === 'TAKE_PROFIT_MARKET')) {
1621
+ request['type'] = 'TAKE_PROFIT_MARKET';
1622
+ }
1623
+ else if ((type === 'LIMIT') || (type === 'TAKE_PROFIT')) {
1624
+ request['type'] = 'TAKE_PROFIT';
1625
+ }
1626
+ }
1627
+ }
1628
+ const reduceOnly = this.safeValue(params, 'reduceOnly', false);
1629
+ let positionSide = undefined;
1630
+ if (reduceOnly) {
1631
+ positionSide = (side === 'buy') ? 'SHORT' : 'LONG';
1632
+ }
1633
+ else {
1634
+ positionSide = (side === 'buy') ? 'LONG' : 'SHORT';
1635
+ }
1636
+ request['positionSide'] = positionSide;
1606
1637
  request['quantity'] = this.amountToPrecision(symbol, amount);
1607
- }
1608
- if ((stopLossPrice !== undefined)) {
1609
- request['type'] = 'STOP_MARKET';
1610
- request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
1611
- }
1612
- if ((takeProfitPrice !== undefined)) {
1613
- request['type'] = 'TAKE_PROFIT_MARKET';
1614
- request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
1615
- }
1616
- if (postOnly) {
1617
- request['timeInForce'] = 'POC';
1618
- }
1619
- else if (exchangeSpecificTifParam === 'POC') {
1620
- request['timeInForce'] = 'POC';
1621
- }
1622
- else if (!isSpotMarket) {
1623
- request['timeInForce'] = 'GTC';
1624
- }
1625
- if (isSpotMarket) {
1626
- response = await this.spotV1PrivatePostTradeOrder(this.extend(request, query));
1627
- }
1628
- else {
1629
- response = await this.swapV2PrivatePostTradeOrder(this.extend(request, query));
1638
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
1639
+ response = await this.swapV2PrivatePostTradeOrder(this.extend(request, params));
1630
1640
  }
1631
1641
  //
1632
1642
  // spot
1643
+ //
1633
1644
  // {
1634
1645
  // "code": 0,
1635
1646
  // "msg": "",
@@ -1649,23 +1660,25 @@ class bingx extends bingx$1 {
1649
1660
  //
1650
1661
  // swap
1651
1662
  //
1652
- // {
1653
- // "code": 0,
1654
- // "msg": "",
1655
- // "data": {
1656
- // "order": {
1657
- // "symbol": "BTC-USDT",
1658
- // "orderId": 1590973236294713344,
1659
- // "side": "BUY",
1660
- // "positionSide": "LONG",
1661
- // "type": "LIMIT"
1662
- // }
1663
- // }
1664
- // }
1663
+ // {
1664
+ // "code": 0,
1665
+ // "msg": "",
1666
+ // "data": {
1667
+ // "order": {
1668
+ // "symbol": "BTC-USDT",
1669
+ // "orderId": 1709036527545438208,
1670
+ // "side": "BUY",
1671
+ // "positionSide": "LONG",
1672
+ // "type": "TRIGGER_LIMIT",
1673
+ // "clientOrderID": "",
1674
+ // "workingType": ""
1675
+ // }
1676
+ // }
1677
+ // }
1665
1678
  //
1666
- const data = this.safeValue(response, 'data');
1667
- const first = this.safeValue(data, 'order', data);
1668
- return this.parseOrder(first, market);
1679
+ const data = this.safeValue(response, 'data', {});
1680
+ const order = this.safeValue(data, 'order', data);
1681
+ return this.parseOrder(order, market);
1669
1682
  }
1670
1683
  parseOrder(order, market = undefined) {
1671
1684
  //
@@ -1735,65 +1748,68 @@ class bingx extends bingx$1 {
1735
1748
  //
1736
1749
  // fetchOrder, fetchOpenOrders, fetchClosedOrders
1737
1750
  //
1738
- // {
1739
- // "symbol": "LINK-USDT",
1740
- // "orderId": 1585839271162413056,
1741
- // "side": "BUY",
1742
- // "positionSide": "LONG",
1743
- // "type": "TRIGGER_MARKET",
1744
- // "origQty": "5.0",
1745
- // "price": "9",
1746
- // "executedQty": "0.0",
1747
- // "avgPrice": "0",
1748
- // "cumQuote": "0",
1749
- // "stopPrice": "5",
1750
- // "profit": "0.0000",
1751
- // "commission": "0.000000",
1752
- // "status": "CANCELLED",
1753
- // "time": 1667631605000,
1754
- // "updateTime": 1667631605000
1755
- // }
1751
+ // {
1752
+ // "symbol": "BTC-USDT",
1753
+ // "orderId": 1709036527545438208,
1754
+ // "side": "BUY",
1755
+ // "positionSide": "LONG",
1756
+ // "type": "TRIGGER_LIMIT",
1757
+ // "origQty": "0.0010",
1758
+ // "price": "22000.0",
1759
+ // "executedQty": "0.0000",
1760
+ // "avgPrice": "0.0",
1761
+ // "cumQuote": "",
1762
+ // "stopPrice": "23000.0",
1763
+ // "profit": "",
1764
+ // "commission": "",
1765
+ // "status": "NEW",
1766
+ // "time": 1696301035187,
1767
+ // "updateTime": 1696301035187,
1768
+ // "clientOrderId": "",
1769
+ // "leverage": "",
1770
+ // "takeProfit": "",
1771
+ // "stopLoss": "",
1772
+ // "advanceAttr": 0,
1773
+ // "positionID": 0,
1774
+ // "takeProfitEntrustPrice": 0,
1775
+ // "stopLossEntrustPrice": 0,
1776
+ // "orderType": "",
1777
+ // "workingType": "MARK_PRICE"
1778
+ // }
1756
1779
  //
1757
1780
  const positionSide = this.safeString(order, 'positionSide');
1758
1781
  const marketType = (positionSide === undefined) ? 'spot' : 'swap';
1759
1782
  const marketId = this.safeString(order, 'symbol');
1760
1783
  const symbol = this.safeSymbol(marketId, market, '-', marketType);
1761
- const orderId = this.safeString(order, 'orderId');
1762
- const side = this.safeStringLower(order, 'side');
1763
- const type = this.safeStringLower(order, 'type');
1764
1784
  const timestamp = this.safeInteger2(order, 'time', 'transactTime');
1765
- const lastTradeTimestamp = this.safeInteger(order, 'updateTime');
1766
- const price = this.safeString(order, 'price');
1767
- const average = this.safeString(order, 'avgPrice');
1768
- const amount = this.safeString(order, 'origQty');
1769
- const filled = this.safeString(order, 'executedQty');
1770
- const statusId = this.safeString(order, 'status');
1771
1785
  const fee = {
1772
1786
  'currency': this.safeString(order, 'feeAsset'),
1773
1787
  'rate': this.safeString2(order, 'fee', 'commission'),
1774
1788
  };
1775
- const clientOrderId = this.safeString(order, 'clientOrderId');
1776
1789
  return this.safeOrder({
1777
1790
  'info': order,
1778
- 'id': orderId,
1779
- 'clientOrderId': clientOrderId,
1791
+ 'id': this.safeString(order, 'orderId'),
1792
+ 'clientOrderId': this.safeString(order, 'clientOrderId'),
1780
1793
  'timestamp': timestamp,
1781
1794
  'datetime': this.iso8601(timestamp),
1782
- 'lastTradeTimestamp': lastTradeTimestamp,
1795
+ 'lastTradeTimestamp': this.safeInteger(order, 'updateTime'),
1796
+ 'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
1783
1797
  'symbol': symbol,
1784
- 'type': type,
1798
+ 'type': this.safeStringLower(order, 'type'),
1785
1799
  'timeInForce': undefined,
1786
1800
  'postOnly': undefined,
1787
- 'side': side,
1788
- 'price': price,
1789
- 'stopPrice': this.safeNumber(order, 'triggerPrice'),
1790
- 'triggerPrice': this.safeNumber(order, 'triggerPrice'),
1791
- 'average': average,
1801
+ 'side': this.safeStringLower(order, 'side'),
1802
+ 'price': this.safeString(order, 'price'),
1803
+ 'stopPrice': this.safeNumber(order, 'stopPrice'),
1804
+ 'triggerPrice': this.safeNumber(order, 'stopPrice'),
1805
+ 'stopLossPrice': this.safeNumber(order, 'stopLoss'),
1806
+ 'takeProfitPrice': this.safeNumber(order, 'takeProfit'),
1807
+ 'average': this.safeString(order, 'avgPrice'),
1792
1808
  'cost': undefined,
1793
- 'amount': amount,
1794
- 'filled': filled,
1809
+ 'amount': this.safeString(order, 'origQty'),
1810
+ 'filled': this.safeString(order, 'executedQty'),
1795
1811
  'remaining': undefined,
1796
- 'status': this.parseOrderStatus(statusId),
1812
+ 'status': this.parseOrderStatus(this.safeString(order, 'status')),
1797
1813
  'fee': fee,
1798
1814
  'trades': undefined,
1799
1815
  }, market);
@@ -3802,7 +3802,7 @@ class bitget extends bitget$1 {
3802
3802
  //
3803
3803
  const data = this.safeValue(response, 'data');
3804
3804
  if (data !== undefined) {
3805
- return this.safeValue2(data, 'orderList', 'data', []);
3805
+ return this.safeValue(data, 'orderList', data);
3806
3806
  }
3807
3807
  const parsedData = JSON.parse(response);
3808
3808
  return this.safeValue(parsedData, 'data', []);
@@ -71,7 +71,9 @@ class bitmart extends bitmart$1 {
71
71
  'fetchOrderBook': true,
72
72
  'fetchOrders': false,
73
73
  'fetchOrderTrades': true,
74
+ 'fetchPosition': true,
74
75
  'fetchPositionMode': false,
76
+ 'fetchPositions': true,
75
77
  'fetchStatus': true,
76
78
  'fetchTicker': true,
77
79
  'fetchTickers': true,
@@ -3756,6 +3758,180 @@ class bitmart extends bitmart$1 {
3756
3758
  'previousFundingDatetime': undefined,
3757
3759
  };
3758
3760
  }
3761
+ async fetchPosition(symbol, params = {}) {
3762
+ /**
3763
+ * @method
3764
+ * @name bitmart#fetchPosition
3765
+ * @description fetch data on a single open contract trade position
3766
+ * @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
3767
+ * @param {string} symbol unified market symbol of the market the position is held in
3768
+ * @param {object} [params] extra parameters specific to the bitmart api endpoint
3769
+ * @returns {object} a [position structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#position-structure}
3770
+ */
3771
+ await this.loadMarkets();
3772
+ const market = this.market(symbol);
3773
+ const request = {
3774
+ 'symbol': market['id'],
3775
+ };
3776
+ const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
3777
+ //
3778
+ // {
3779
+ // "code": 1000,
3780
+ // "message": "Ok",
3781
+ // "data": [
3782
+ // {
3783
+ // "symbol": "BTCUSDT",
3784
+ // "leverage": "10",
3785
+ // "timestamp": 1696392515269,
3786
+ // "current_fee": "0.0014250028",
3787
+ // "open_timestamp": 1696392256998,
3788
+ // "current_value": "27.4039",
3789
+ // "mark_price": "27.4039",
3790
+ // "position_value": "27.4079",
3791
+ // "position_cross": "3.75723474",
3792
+ // "maintenance_margin": "0.1370395",
3793
+ // "close_vol": "0",
3794
+ // "close_avg_price": "0",
3795
+ // "open_avg_price": "27407.9",
3796
+ // "entry_price": "27407.9",
3797
+ // "current_amount": "1",
3798
+ // "unrealized_value": "-0.004",
3799
+ // "realized_value": "-0.01644474",
3800
+ // "position_type": 1
3801
+ // }
3802
+ // ],
3803
+ // "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
3804
+ // }
3805
+ //
3806
+ const data = this.safeValue(response, 'data', []);
3807
+ const first = this.safeValue(data, 0, {});
3808
+ return this.parsePosition(first, market);
3809
+ }
3810
+ async fetchPositions(symbols = undefined, params = {}) {
3811
+ /**
3812
+ * @method
3813
+ * @name bitmart#fetchPositions
3814
+ * @description fetch all open contract positions
3815
+ * @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
3816
+ * @param {string[]|undefined} symbols list of unified market symbols
3817
+ * @param {object} [params] extra parameters specific to the bitmart api endpoint
3818
+ * @returns {object[]} a list of [position structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#position-structure}
3819
+ */
3820
+ await this.loadMarkets();
3821
+ let market = undefined;
3822
+ let symbolsLength = undefined;
3823
+ if (symbols !== undefined) {
3824
+ symbolsLength = symbols.length;
3825
+ const first = this.safeString(symbols, 0);
3826
+ market = this.market(first);
3827
+ }
3828
+ const request = {};
3829
+ if (symbolsLength === 1) {
3830
+ // only supports symbols as undefined or sending one symbol
3831
+ request['symbol'] = market['id'];
3832
+ }
3833
+ const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
3834
+ //
3835
+ // {
3836
+ // "code": 1000,
3837
+ // "message": "Ok",
3838
+ // "data": [
3839
+ // {
3840
+ // "symbol": "BTCUSDT",
3841
+ // "leverage": "10",
3842
+ // "timestamp": 1696392515269,
3843
+ // "current_fee": "0.0014250028",
3844
+ // "open_timestamp": 1696392256998,
3845
+ // "current_value": "27.4039",
3846
+ // "mark_price": "27.4039",
3847
+ // "position_value": "27.4079",
3848
+ // "position_cross": "3.75723474",
3849
+ // "maintenance_margin": "0.1370395",
3850
+ // "close_vol": "0",
3851
+ // "close_avg_price": "0",
3852
+ // "open_avg_price": "27407.9",
3853
+ // "entry_price": "27407.9",
3854
+ // "current_amount": "1",
3855
+ // "unrealized_value": "-0.004",
3856
+ // "realized_value": "-0.01644474",
3857
+ // "position_type": 1
3858
+ // },
3859
+ // ],
3860
+ // "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
3861
+ // }
3862
+ //
3863
+ const positions = this.safeValue(response, 'data', []);
3864
+ const result = [];
3865
+ for (let i = 0; i < positions.length; i++) {
3866
+ result.push(this.parsePosition(positions[i]));
3867
+ }
3868
+ symbols = this.marketSymbols(symbols);
3869
+ return this.filterByArrayPositions(result, 'symbol', symbols, false);
3870
+ }
3871
+ parsePosition(position, market = undefined) {
3872
+ //
3873
+ // {
3874
+ // "symbol": "BTCUSDT",
3875
+ // "leverage": "10",
3876
+ // "timestamp": 1696392515269,
3877
+ // "current_fee": "0.0014250028",
3878
+ // "open_timestamp": 1696392256998,
3879
+ // "current_value": "27.4039",
3880
+ // "mark_price": "27.4039",
3881
+ // "position_value": "27.4079",
3882
+ // "position_cross": "3.75723474",
3883
+ // "maintenance_margin": "0.1370395",
3884
+ // "close_vol": "0",
3885
+ // "close_avg_price": "0",
3886
+ // "open_avg_price": "27407.9",
3887
+ // "entry_price": "27407.9",
3888
+ // "current_amount": "1",
3889
+ // "unrealized_value": "-0.004",
3890
+ // "realized_value": "-0.01644474",
3891
+ // "position_type": 1
3892
+ // }
3893
+ //
3894
+ const marketId = this.safeString(position, 'symbol');
3895
+ market = this.safeMarket(marketId, market);
3896
+ const symbol = market['symbol'];
3897
+ const timestamp = this.safeInteger(position, 'timestamp');
3898
+ const side = this.safeInteger(position, 'position_type');
3899
+ const maintenanceMargin = this.safeString(position, 'maintenance_margin');
3900
+ const notional = this.safeString(position, 'current_value');
3901
+ const collateral = this.safeString(position, 'position_cross');
3902
+ const maintenanceMarginPercentage = Precise["default"].stringDiv(maintenanceMargin, notional);
3903
+ const marginRatio = Precise["default"].stringDiv(maintenanceMargin, collateral);
3904
+ return this.safePosition({
3905
+ 'info': position,
3906
+ 'id': undefined,
3907
+ 'symbol': symbol,
3908
+ 'timestamp': timestamp,
3909
+ 'datetime': this.iso8601(timestamp),
3910
+ 'lastUpdateTimestamp': undefined,
3911
+ 'hedged': undefined,
3912
+ 'side': (side === 1) ? 'long' : 'short',
3913
+ 'contracts': this.safeNumber(position, 'current_amount'),
3914
+ 'contractSize': this.safeNumber(market, 'contractSize'),
3915
+ 'entryPrice': this.safeNumber(position, 'entry_price'),
3916
+ 'markPrice': this.safeNumber(position, 'mark_price'),
3917
+ 'lastPrice': undefined,
3918
+ 'notional': this.parseNumber(notional),
3919
+ 'leverage': this.safeNumber(position, 'leverage'),
3920
+ 'collateral': this.parseNumber(collateral),
3921
+ 'initialMargin': undefined,
3922
+ 'initialMarginPercentage': undefined,
3923
+ 'maintenanceMargin': this.parseNumber(maintenanceMargin),
3924
+ 'maintenanceMarginPercentage': this.parseNumber(maintenanceMarginPercentage),
3925
+ 'unrealizedPnl': this.safeNumber(position, 'unrealized_value'),
3926
+ 'realizedPnl': this.safeNumber(position, 'realized_value'),
3927
+ 'liquidationPrice': undefined,
3928
+ 'marginMode': undefined,
3929
+ 'percentage': undefined,
3930
+ 'marginRatio': this.parseNumber(marginRatio),
3931
+ 'stopLossPrice': undefined,
3932
+ 'takeProfitPrice': undefined,
3933
+ });
3934
+ }
3759
3935
  nonce() {
3760
3936
  return this.milliseconds();
3761
3937
  }
@@ -490,7 +490,7 @@ class deribit extends deribit$1 {
490
490
  const defaultCode = this.safeValue(this.options, 'code', 'BTC');
491
491
  const options = this.safeValue(this.options, methodName, {});
492
492
  const code = this.safeValue(options, 'code', defaultCode);
493
- return this.safeValue(params, 'code', code);
493
+ return this.safeValue2(params, 'code', code);
494
494
  }
495
495
  async fetchStatus(params = {}) {
496
496
  /**
@@ -1516,7 +1516,7 @@ class idex extends idex$1 {
1516
1516
  //
1517
1517
  // { serverTime: '1655258263236' }
1518
1518
  //
1519
- return this.safeNumber(response, 'serverTime');
1519
+ return this.safeInteger(response, 'serverTime');
1520
1520
  }
1521
1521
  async fetchWithdrawal(id, code = undefined, params = {}) {
1522
1522
  /**