ccxt 4.1.2 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -214,13 +214,13 @@ console.log(version, Object.keys(exchanges));
214
214
 
215
215
  All-in-one browser bundle (dependencies included), served from a CDN of your choice:
216
216
 
217
- * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.1.2/dist/ccxt.browser.js
218
- * unpkg: https://unpkg.com/ccxt@4.1.2/dist/ccxt.browser.js
217
+ * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.1.3/dist/ccxt.browser.js
218
+ * unpkg: https://unpkg.com/ccxt@4.1.3/dist/ccxt.browser.js
219
219
 
220
220
  CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.
221
221
 
222
222
  ```HTML
223
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.1.2/dist/ccxt.browser.js"></script>
223
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.1.3/dist/ccxt.browser.js"></script>
224
224
  ```
225
225
 
226
226
  Creates a global `ccxt` object:
@@ -26465,6 +26465,8 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
26465
26465
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
26466
26466
  * @param {object} [params] extra parameters specific to the bingx api endpoint
26467
26467
  * @param {bool} [params.postOnly] true to place a post only order
26468
+ * @param {string} [params.timeInForce] spot supports 'PO' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
26469
+ * @param {bool} [params.reduceOnly] *swap only* true or false whether the order is reduce only
26468
26470
  * @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
26469
26471
  * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
26470
26472
  * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
@@ -26472,8 +26474,10 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
26472
26474
  */
26473
26475
  await this.loadMarkets();
26474
26476
  const market = this.market(symbol);
26477
+ let postOnly = undefined;
26475
26478
  let response = undefined;
26476
- const [marketType, query] = this.handleMarketTypeAndParams('createOrder', market, params);
26479
+ let marketType = undefined;
26480
+ [marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
26477
26481
  type = type.toUpperCase();
26478
26482
  const request = {
26479
26483
  'symbol': market['id'],
@@ -26481,51 +26485,16 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
26481
26485
  'side': side.toUpperCase(),
26482
26486
  };
26483
26487
  const isMarketOrder = type === 'MARKET';
26484
- const isSpotMarket = marketType === 'spot';
26485
- let stopPriceRaw = undefined;
26486
- let stopPrice = undefined;
26487
- let stopLossPrice = undefined;
26488
- let takeProfitPrice = undefined;
26489
- if (!isSpotMarket) {
26490
- stopPriceRaw = this.safeValue2(params, 'stopPrice', 'triggerPrice');
26491
- if (stopPriceRaw !== undefined) {
26492
- stopPrice = this.priceToPrecision(symbol, stopPriceRaw);
26493
- }
26494
- stopLossPrice = this.safeValue(params, 'stopLossPrice');
26495
- takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
26496
- }
26497
- if ((stopLossPrice !== undefined) && (takeProfitPrice !== undefined)) {
26498
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder('Order is either a takeProfit order or a stopLoss order');
26499
- }
26500
- if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT')) {
26501
- request['price'] = this.priceToPrecision(symbol, price);
26502
- if ((stopPrice !== undefined)) {
26503
- request['type'] = 'TRIGGER_LIMIT';
26504
- request['stopPrice'] = stopPrice;
26505
- }
26506
- if (type === 'TRIGGER_LIMIT') {
26507
- if (stopPrice === undefined) {
26508
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder('TRIGGER_LIMIT requires a triggerPrice / stopPrice');
26509
- }
26510
- request['stopPrice'] = stopPrice;
26511
- }
26488
+ const isSpot = marketType === 'spot';
26489
+ const timeInForce = this.safeStringUpper(params, 'timeInForce');
26490
+ if (timeInForce === 'IOC') {
26491
+ request['timeInForce'] = 'IOC';
26512
26492
  }
26513
- if (isMarketOrder || (type === 'TRIGGER_MARKET')) {
26514
- if ((stopPrice !== undefined)) {
26515
- request['type'] = 'TRIGGER_MARKET';
26516
- request['stopPrice'] = stopPrice;
26517
- }
26518
- if (type === 'TRIGGER_MARKET') {
26519
- if (stopPrice === undefined) {
26520
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder('TRIGGER_MARKET requires a triggerPrice / stopPrice');
26521
- }
26522
- request['stopPrice'] = stopPrice;
26493
+ if (isSpot) {
26494
+ [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'POC', params);
26495
+ if (postOnly || (timeInForce === 'POC')) {
26496
+ request['timeInForce'] = 'POC';
26523
26497
  }
26524
- }
26525
- const exchangeSpecificTifParam = this.safeStringUpperN(params, ['force', 'timeInForce']);
26526
- let postOnly = undefined;
26527
- [postOnly, params] = this.handlePostOnly(isMarketOrder, exchangeSpecificTifParam === 'POC', params);
26528
- if (isSpotMarket) {
26529
26498
  const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
26530
26499
  if (createMarketBuyOrderRequiresPrice && isMarketOrder && (side === 'buy')) {
26531
26500
  if (price === undefined) {
@@ -26541,35 +26510,77 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
26541
26510
  else {
26542
26511
  request['quantity'] = this.amountToPrecision(symbol, amount);
26543
26512
  }
26513
+ if (!isMarketOrder) {
26514
+ request['price'] = this.priceToPrecision(symbol, price);
26515
+ }
26516
+ response = await this.spotV1PrivatePostTradeOrder(this.extend(request, params));
26544
26517
  }
26545
26518
  else {
26519
+ [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'PostOnly', params);
26520
+ if (postOnly || (timeInForce === 'PostOnly')) {
26521
+ request['timeInForce'] = 'PostOnly';
26522
+ }
26523
+ else if (timeInForce === 'GTC') {
26524
+ request['timeInForce'] = 'GTC';
26525
+ }
26526
+ else if (timeInForce === 'FOK') {
26527
+ request['timeInForce'] = 'FOK';
26528
+ }
26529
+ if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) {
26530
+ request['price'] = this.priceToPrecision(symbol, price);
26531
+ }
26532
+ const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
26533
+ const stopLossPrice = this.safeNumber(params, 'stopLossPrice');
26534
+ const takeProfitPrice = this.safeNumber(params, 'takeProfitPrice');
26535
+ const isTriggerOrder = triggerPrice !== undefined;
26536
+ const isStopLossPriceOrder = stopLossPrice !== undefined;
26537
+ const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
26538
+ if (isTriggerOrder) {
26539
+ request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
26540
+ if (isMarketOrder || (type === 'TRIGGER_MARKET')) {
26541
+ request['type'] = 'TRIGGER_MARKET';
26542
+ }
26543
+ else if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT')) {
26544
+ request['type'] = 'TRIGGER_LIMIT';
26545
+ }
26546
+ }
26547
+ else if (isStopLossPriceOrder || isTakeProfitPriceOrder) {
26548
+ // This can be used to set the stop loss and take profit, but the position needs to be opened first
26549
+ if (isStopLossPriceOrder) {
26550
+ request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
26551
+ if (isMarketOrder || (type === 'STOP_MARKET')) {
26552
+ request['type'] = 'STOP_MARKET';
26553
+ }
26554
+ else if ((type === 'LIMIT') || (type === 'STOP')) {
26555
+ request['type'] = 'STOP';
26556
+ }
26557
+ }
26558
+ else if (isTakeProfitPriceOrder) {
26559
+ request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
26560
+ if (isMarketOrder || (type === 'TAKE_PROFIT_MARKET')) {
26561
+ request['type'] = 'TAKE_PROFIT_MARKET';
26562
+ }
26563
+ else if ((type === 'LIMIT') || (type === 'TAKE_PROFIT')) {
26564
+ request['type'] = 'TAKE_PROFIT';
26565
+ }
26566
+ }
26567
+ }
26568
+ const reduceOnly = this.safeValue(params, 'reduceOnly', false);
26569
+ let positionSide = undefined;
26570
+ if (reduceOnly) {
26571
+ positionSide = (side === 'buy') ? 'SHORT' : 'LONG';
26572
+ }
26573
+ else {
26574
+ positionSide = (side === 'buy') ? 'LONG' : 'SHORT';
26575
+ }
26576
+ request['positionSide'] = positionSide;
26546
26577
  request['quantity'] = this.amountToPrecision(symbol, amount);
26547
- }
26548
- if ((stopLossPrice !== undefined)) {
26549
- request['type'] = 'STOP_MARKET';
26550
- request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
26551
- }
26552
- if ((takeProfitPrice !== undefined)) {
26553
- request['type'] = 'TAKE_PROFIT_MARKET';
26554
- request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
26555
- }
26556
- if (postOnly) {
26557
- request['timeInForce'] = 'POC';
26558
- }
26559
- else if (exchangeSpecificTifParam === 'POC') {
26560
- request['timeInForce'] = 'POC';
26561
- }
26562
- else if (!isSpotMarket) {
26563
- request['timeInForce'] = 'GTC';
26564
- }
26565
- if (isSpotMarket) {
26566
- response = await this.spotV1PrivatePostTradeOrder(this.extend(request, query));
26567
- }
26568
- else {
26569
- response = await this.swapV2PrivatePostTradeOrder(this.extend(request, query));
26578
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
26579
+ response = await this.swapV2PrivatePostTradeOrder(this.extend(request, params));
26570
26580
  }
26571
26581
  //
26572
26582
  // spot
26583
+ //
26573
26584
  // {
26574
26585
  // "code": 0,
26575
26586
  // "msg": "",
@@ -26589,23 +26600,25 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
26589
26600
  //
26590
26601
  // swap
26591
26602
  //
26592
- // {
26593
- // "code": 0,
26594
- // "msg": "",
26595
- // "data": {
26596
- // "order": {
26597
- // "symbol": "BTC-USDT",
26598
- // "orderId": 1590973236294713344,
26599
- // "side": "BUY",
26600
- // "positionSide": "LONG",
26601
- // "type": "LIMIT"
26602
- // }
26603
- // }
26604
- // }
26603
+ // {
26604
+ // "code": 0,
26605
+ // "msg": "",
26606
+ // "data": {
26607
+ // "order": {
26608
+ // "symbol": "BTC-USDT",
26609
+ // "orderId": 1709036527545438208,
26610
+ // "side": "BUY",
26611
+ // "positionSide": "LONG",
26612
+ // "type": "TRIGGER_LIMIT",
26613
+ // "clientOrderID": "",
26614
+ // "workingType": ""
26615
+ // }
26616
+ // }
26617
+ // }
26605
26618
  //
26606
- const data = this.safeValue(response, 'data');
26607
- const first = this.safeValue(data, 'order', data);
26608
- return this.parseOrder(first, market);
26619
+ const data = this.safeValue(response, 'data', {});
26620
+ const order = this.safeValue(data, 'order', data);
26621
+ return this.parseOrder(order, market);
26609
26622
  }
26610
26623
  parseOrder(order, market = undefined) {
26611
26624
  //
@@ -26675,65 +26688,68 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
26675
26688
  //
26676
26689
  // fetchOrder, fetchOpenOrders, fetchClosedOrders
26677
26690
  //
26678
- // {
26679
- // "symbol": "LINK-USDT",
26680
- // "orderId": 1585839271162413056,
26681
- // "side": "BUY",
26682
- // "positionSide": "LONG",
26683
- // "type": "TRIGGER_MARKET",
26684
- // "origQty": "5.0",
26685
- // "price": "9",
26686
- // "executedQty": "0.0",
26687
- // "avgPrice": "0",
26688
- // "cumQuote": "0",
26689
- // "stopPrice": "5",
26690
- // "profit": "0.0000",
26691
- // "commission": "0.000000",
26692
- // "status": "CANCELLED",
26693
- // "time": 1667631605000,
26694
- // "updateTime": 1667631605000
26695
- // }
26691
+ // {
26692
+ // "symbol": "BTC-USDT",
26693
+ // "orderId": 1709036527545438208,
26694
+ // "side": "BUY",
26695
+ // "positionSide": "LONG",
26696
+ // "type": "TRIGGER_LIMIT",
26697
+ // "origQty": "0.0010",
26698
+ // "price": "22000.0",
26699
+ // "executedQty": "0.0000",
26700
+ // "avgPrice": "0.0",
26701
+ // "cumQuote": "",
26702
+ // "stopPrice": "23000.0",
26703
+ // "profit": "",
26704
+ // "commission": "",
26705
+ // "status": "NEW",
26706
+ // "time": 1696301035187,
26707
+ // "updateTime": 1696301035187,
26708
+ // "clientOrderId": "",
26709
+ // "leverage": "",
26710
+ // "takeProfit": "",
26711
+ // "stopLoss": "",
26712
+ // "advanceAttr": 0,
26713
+ // "positionID": 0,
26714
+ // "takeProfitEntrustPrice": 0,
26715
+ // "stopLossEntrustPrice": 0,
26716
+ // "orderType": "",
26717
+ // "workingType": "MARK_PRICE"
26718
+ // }
26696
26719
  //
26697
26720
  const positionSide = this.safeString(order, 'positionSide');
26698
26721
  const marketType = (positionSide === undefined) ? 'spot' : 'swap';
26699
26722
  const marketId = this.safeString(order, 'symbol');
26700
26723
  const symbol = this.safeSymbol(marketId, market, '-', marketType);
26701
- const orderId = this.safeString(order, 'orderId');
26702
- const side = this.safeStringLower(order, 'side');
26703
- const type = this.safeStringLower(order, 'type');
26704
26724
  const timestamp = this.safeInteger2(order, 'time', 'transactTime');
26705
- const lastTradeTimestamp = this.safeInteger(order, 'updateTime');
26706
- const price = this.safeString(order, 'price');
26707
- const average = this.safeString(order, 'avgPrice');
26708
- const amount = this.safeString(order, 'origQty');
26709
- const filled = this.safeString(order, 'executedQty');
26710
- const statusId = this.safeString(order, 'status');
26711
26725
  const fee = {
26712
26726
  'currency': this.safeString(order, 'feeAsset'),
26713
26727
  'rate': this.safeString2(order, 'fee', 'commission'),
26714
26728
  };
26715
- const clientOrderId = this.safeString(order, 'clientOrderId');
26716
26729
  return this.safeOrder({
26717
26730
  'info': order,
26718
- 'id': orderId,
26719
- 'clientOrderId': clientOrderId,
26731
+ 'id': this.safeString(order, 'orderId'),
26732
+ 'clientOrderId': this.safeString(order, 'clientOrderId'),
26720
26733
  'timestamp': timestamp,
26721
26734
  'datetime': this.iso8601(timestamp),
26722
- 'lastTradeTimestamp': lastTradeTimestamp,
26735
+ 'lastTradeTimestamp': this.safeInteger(order, 'updateTime'),
26736
+ 'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
26723
26737
  'symbol': symbol,
26724
- 'type': type,
26738
+ 'type': this.safeStringLower(order, 'type'),
26725
26739
  'timeInForce': undefined,
26726
26740
  'postOnly': undefined,
26727
- 'side': side,
26728
- 'price': price,
26729
- 'stopPrice': this.safeNumber(order, 'triggerPrice'),
26730
- 'triggerPrice': this.safeNumber(order, 'triggerPrice'),
26731
- 'average': average,
26741
+ 'side': this.safeStringLower(order, 'side'),
26742
+ 'price': this.safeString(order, 'price'),
26743
+ 'stopPrice': this.safeNumber(order, 'stopPrice'),
26744
+ 'triggerPrice': this.safeNumber(order, 'stopPrice'),
26745
+ 'stopLossPrice': this.safeNumber(order, 'stopLoss'),
26746
+ 'takeProfitPrice': this.safeNumber(order, 'takeProfit'),
26747
+ 'average': this.safeString(order, 'avgPrice'),
26732
26748
  'cost': undefined,
26733
- 'amount': amount,
26734
- 'filled': filled,
26749
+ 'amount': this.safeString(order, 'origQty'),
26750
+ 'filled': this.safeString(order, 'executedQty'),
26735
26751
  'remaining': undefined,
26736
- 'status': this.parseOrderStatus(statusId),
26752
+ 'status': this.parseOrderStatus(this.safeString(order, 'status')),
26737
26753
  'fee': fee,
26738
26754
  'trades': undefined,
26739
26755
  }, market);
@@ -41476,7 +41492,7 @@ class bitget extends _abstract_bitget_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
41476
41492
  //
41477
41493
  const data = this.safeValue(response, 'data');
41478
41494
  if (data !== undefined) {
41479
- return this.safeValue2(data, 'orderList', 'data', []);
41495
+ return this.safeValue(data, 'orderList', data);
41480
41496
  }
41481
41497
  const parsedData = JSON.parse(response);
41482
41498
  return this.safeValue(parsedData, 'data', []);
@@ -44007,7 +44023,9 @@ class bitmart extends _abstract_bitmart_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
44007
44023
  'fetchOrderBook': true,
44008
44024
  'fetchOrders': false,
44009
44025
  'fetchOrderTrades': true,
44026
+ 'fetchPosition': true,
44010
44027
  'fetchPositionMode': false,
44028
+ 'fetchPositions': true,
44011
44029
  'fetchStatus': true,
44012
44030
  'fetchTicker': true,
44013
44031
  'fetchTickers': true,
@@ -47692,6 +47710,180 @@ class bitmart extends _abstract_bitmart_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
47692
47710
  'previousFundingDatetime': undefined,
47693
47711
  };
47694
47712
  }
47713
+ async fetchPosition(symbol, params = {}) {
47714
+ /**
47715
+ * @method
47716
+ * @name bitmart#fetchPosition
47717
+ * @description fetch data on a single open contract trade position
47718
+ * @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
47719
+ * @param {string} symbol unified market symbol of the market the position is held in
47720
+ * @param {object} [params] extra parameters specific to the bitmart api endpoint
47721
+ * @returns {object} a [position structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#position-structure}
47722
+ */
47723
+ await this.loadMarkets();
47724
+ const market = this.market(symbol);
47725
+ const request = {
47726
+ 'symbol': market['id'],
47727
+ };
47728
+ const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
47729
+ //
47730
+ // {
47731
+ // "code": 1000,
47732
+ // "message": "Ok",
47733
+ // "data": [
47734
+ // {
47735
+ // "symbol": "BTCUSDT",
47736
+ // "leverage": "10",
47737
+ // "timestamp": 1696392515269,
47738
+ // "current_fee": "0.0014250028",
47739
+ // "open_timestamp": 1696392256998,
47740
+ // "current_value": "27.4039",
47741
+ // "mark_price": "27.4039",
47742
+ // "position_value": "27.4079",
47743
+ // "position_cross": "3.75723474",
47744
+ // "maintenance_margin": "0.1370395",
47745
+ // "close_vol": "0",
47746
+ // "close_avg_price": "0",
47747
+ // "open_avg_price": "27407.9",
47748
+ // "entry_price": "27407.9",
47749
+ // "current_amount": "1",
47750
+ // "unrealized_value": "-0.004",
47751
+ // "realized_value": "-0.01644474",
47752
+ // "position_type": 1
47753
+ // }
47754
+ // ],
47755
+ // "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
47756
+ // }
47757
+ //
47758
+ const data = this.safeValue(response, 'data', []);
47759
+ const first = this.safeValue(data, 0, {});
47760
+ return this.parsePosition(first, market);
47761
+ }
47762
+ async fetchPositions(symbols = undefined, params = {}) {
47763
+ /**
47764
+ * @method
47765
+ * @name bitmart#fetchPositions
47766
+ * @description fetch all open contract positions
47767
+ * @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
47768
+ * @param {string[]|undefined} symbols list of unified market symbols
47769
+ * @param {object} [params] extra parameters specific to the bitmart api endpoint
47770
+ * @returns {object[]} a list of [position structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#position-structure}
47771
+ */
47772
+ await this.loadMarkets();
47773
+ let market = undefined;
47774
+ let symbolsLength = undefined;
47775
+ if (symbols !== undefined) {
47776
+ symbolsLength = symbols.length;
47777
+ const first = this.safeString(symbols, 0);
47778
+ market = this.market(first);
47779
+ }
47780
+ const request = {};
47781
+ if (symbolsLength === 1) {
47782
+ // only supports symbols as undefined or sending one symbol
47783
+ request['symbol'] = market['id'];
47784
+ }
47785
+ const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
47786
+ //
47787
+ // {
47788
+ // "code": 1000,
47789
+ // "message": "Ok",
47790
+ // "data": [
47791
+ // {
47792
+ // "symbol": "BTCUSDT",
47793
+ // "leverage": "10",
47794
+ // "timestamp": 1696392515269,
47795
+ // "current_fee": "0.0014250028",
47796
+ // "open_timestamp": 1696392256998,
47797
+ // "current_value": "27.4039",
47798
+ // "mark_price": "27.4039",
47799
+ // "position_value": "27.4079",
47800
+ // "position_cross": "3.75723474",
47801
+ // "maintenance_margin": "0.1370395",
47802
+ // "close_vol": "0",
47803
+ // "close_avg_price": "0",
47804
+ // "open_avg_price": "27407.9",
47805
+ // "entry_price": "27407.9",
47806
+ // "current_amount": "1",
47807
+ // "unrealized_value": "-0.004",
47808
+ // "realized_value": "-0.01644474",
47809
+ // "position_type": 1
47810
+ // },
47811
+ // ],
47812
+ // "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
47813
+ // }
47814
+ //
47815
+ const positions = this.safeValue(response, 'data', []);
47816
+ const result = [];
47817
+ for (let i = 0; i < positions.length; i++) {
47818
+ result.push(this.parsePosition(positions[i]));
47819
+ }
47820
+ symbols = this.marketSymbols(symbols);
47821
+ return this.filterByArrayPositions(result, 'symbol', symbols, false);
47822
+ }
47823
+ parsePosition(position, market = undefined) {
47824
+ //
47825
+ // {
47826
+ // "symbol": "BTCUSDT",
47827
+ // "leverage": "10",
47828
+ // "timestamp": 1696392515269,
47829
+ // "current_fee": "0.0014250028",
47830
+ // "open_timestamp": 1696392256998,
47831
+ // "current_value": "27.4039",
47832
+ // "mark_price": "27.4039",
47833
+ // "position_value": "27.4079",
47834
+ // "position_cross": "3.75723474",
47835
+ // "maintenance_margin": "0.1370395",
47836
+ // "close_vol": "0",
47837
+ // "close_avg_price": "0",
47838
+ // "open_avg_price": "27407.9",
47839
+ // "entry_price": "27407.9",
47840
+ // "current_amount": "1",
47841
+ // "unrealized_value": "-0.004",
47842
+ // "realized_value": "-0.01644474",
47843
+ // "position_type": 1
47844
+ // }
47845
+ //
47846
+ const marketId = this.safeString(position, 'symbol');
47847
+ market = this.safeMarket(marketId, market);
47848
+ const symbol = market['symbol'];
47849
+ const timestamp = this.safeInteger(position, 'timestamp');
47850
+ const side = this.safeInteger(position, 'position_type');
47851
+ const maintenanceMargin = this.safeString(position, 'maintenance_margin');
47852
+ const notional = this.safeString(position, 'current_value');
47853
+ const collateral = this.safeString(position, 'position_cross');
47854
+ const maintenanceMarginPercentage = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise.stringDiv */ .O.stringDiv(maintenanceMargin, notional);
47855
+ const marginRatio = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise.stringDiv */ .O.stringDiv(maintenanceMargin, collateral);
47856
+ return this.safePosition({
47857
+ 'info': position,
47858
+ 'id': undefined,
47859
+ 'symbol': symbol,
47860
+ 'timestamp': timestamp,
47861
+ 'datetime': this.iso8601(timestamp),
47862
+ 'lastUpdateTimestamp': undefined,
47863
+ 'hedged': undefined,
47864
+ 'side': (side === 1) ? 'long' : 'short',
47865
+ 'contracts': this.safeNumber(position, 'current_amount'),
47866
+ 'contractSize': this.safeNumber(market, 'contractSize'),
47867
+ 'entryPrice': this.safeNumber(position, 'entry_price'),
47868
+ 'markPrice': this.safeNumber(position, 'mark_price'),
47869
+ 'lastPrice': undefined,
47870
+ 'notional': this.parseNumber(notional),
47871
+ 'leverage': this.safeNumber(position, 'leverage'),
47872
+ 'collateral': this.parseNumber(collateral),
47873
+ 'initialMargin': undefined,
47874
+ 'initialMarginPercentage': undefined,
47875
+ 'maintenanceMargin': this.parseNumber(maintenanceMargin),
47876
+ 'maintenanceMarginPercentage': this.parseNumber(maintenanceMarginPercentage),
47877
+ 'unrealizedPnl': this.safeNumber(position, 'unrealized_value'),
47878
+ 'realizedPnl': this.safeNumber(position, 'realized_value'),
47879
+ 'liquidationPrice': undefined,
47880
+ 'marginMode': undefined,
47881
+ 'percentage': undefined,
47882
+ 'marginRatio': this.parseNumber(marginRatio),
47883
+ 'stopLossPrice': undefined,
47884
+ 'takeProfitPrice': undefined,
47885
+ });
47886
+ }
47695
47887
  nonce() {
47696
47888
  return this.milliseconds();
47697
47889
  }
@@ -104367,7 +104559,7 @@ class deribit extends _abstract_deribit_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
104367
104559
  const defaultCode = this.safeValue(this.options, 'code', 'BTC');
104368
104560
  const options = this.safeValue(this.options, methodName, {});
104369
104561
  const code = this.safeValue(options, 'code', defaultCode);
104370
- return this.safeValue(params, 'code', code);
104562
+ return this.safeValue2(params, 'code', code);
104371
104563
  }
104372
104564
  async fetchStatus(params = {}) {
104373
104565
  /**
@@ -193273,14 +193465,20 @@ class binance extends _binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
193273
193465
  // valid <levels> are 5, 10, or 20
193274
193466
  //
193275
193467
  // default 100, max 1000, valid limits 5, 10, 20, 50, 100, 500, 1000
193468
+ await this.loadMarkets();
193469
+ const market = this.market(symbol);
193276
193470
  if (limit !== undefined) {
193277
- if ((limit !== 5) && (limit !== 10) && (limit !== 20) && (limit !== 50) && (limit !== 100) && (limit !== 500) && (limit !== 1000)) {
193278
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ExchangeError(this.id + ' watchOrderBook limit argument must be undefined, 5, 10, 20, 50, 100, 500 or 1000');
193471
+ if (market['contract']) {
193472
+ if ((limit !== 5) && (limit !== 10) && (limit !== 20) && (limit !== 50) && (limit !== 100) && (limit !== 500) && (limit !== 1000)) {
193473
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ExchangeError(this.id + ' watchOrderBook limit argument must be undefined, 5, 10, 20, 50, 100, 500 or 1000');
193474
+ }
193475
+ }
193476
+ else {
193477
+ if (limit > 5000) {
193478
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ExchangeError(this.id + ' watchOrderBook limit argument must be less than or equal to 5000');
193479
+ }
193279
193480
  }
193280
193481
  }
193281
- //
193282
- await this.loadMarkets();
193283
- const market = this.market(symbol);
193284
193482
  let type = market['type'];
193285
193483
  if (market['contract']) {
193286
193484
  type = market['linear'] ? 'future' : 'delivery';
@@ -273795,7 +273993,7 @@ SOFTWARE.
273795
273993
 
273796
273994
  //-----------------------------------------------------------------------------
273797
273995
  // this is updated by vss.js when building
273798
- const version = '4.1.2';
273996
+ const version = '4.1.3';
273799
273997
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange.ccxtVersion */ .e.ccxtVersion = version;
273800
273998
  //-----------------------------------------------------------------------------
273801
273999