ccxt 4.2.40 → 4.2.41

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/js/src/binance.js CHANGED
@@ -4340,20 +4340,73 @@ export default class binance extends Exchange {
4340
4340
  // "time": 1676366446072
4341
4341
  // }
4342
4342
  //
4343
+ // fetchMyTrades: linear portfolio margin
4344
+ //
4345
+ // {
4346
+ // "symbol": "BTCUSDT",
4347
+ // "id": 4575108247,
4348
+ // "orderId": 261942655610,
4349
+ // "side": "SELL",
4350
+ // "price": "47263.40",
4351
+ // "qty": "0.010",
4352
+ // "realizedPnl": "27.38400000",
4353
+ // "marginAsset": "USDT",
4354
+ // "quoteQty": "472.63",
4355
+ // "commission": "0.18905360",
4356
+ // "commissionAsset": "USDT",
4357
+ // "time": 1707530039409,
4358
+ // "buyer": false,
4359
+ // "maker": false,
4360
+ // "positionSide": "LONG"
4361
+ // }
4362
+ //
4363
+ // fetchMyTrades: inverse portfolio margin
4364
+ //
4365
+ // {
4366
+ // "symbol": "ETHUSD_PERP",
4367
+ // "id": 701907838,
4368
+ // "orderId": 71548909034,
4369
+ // "pair": "ETHUSD",
4370
+ // "side": "SELL",
4371
+ // "price": "2498.15",
4372
+ // "qty": "1",
4373
+ // "realizedPnl": "0.00012517",
4374
+ // "marginAsset": "ETH",
4375
+ // "baseQty": "0.00400296",
4376
+ // "commission": "0.00000160",
4377
+ // "commissionAsset": "ETH",
4378
+ // "time": 1707530317519,
4379
+ // "positionSide": "LONG",
4380
+ // "buyer": false,
4381
+ // "maker": false
4382
+ // }
4383
+ //
4384
+ // fetchMyTrades: spot margin portfolio margin
4385
+ //
4386
+ // {
4387
+ // "symbol": "ADAUSDT",
4388
+ // "id": 470227543,
4389
+ // "orderId": 4421170947,
4390
+ // "price": "0.53880000",
4391
+ // "qty": "10.00000000",
4392
+ // "quoteQty": "5.38800000",
4393
+ // "commission": "0.00538800",
4394
+ // "commissionAsset": "USDT",
4395
+ // "time": 1707545780522,
4396
+ // "isBuyer": false,
4397
+ // "isMaker": false,
4398
+ // "isBestMatch": true
4399
+ // }
4400
+ //
4343
4401
  const timestamp = this.safeInteger2(trade, 'T', 'time');
4344
- const price = this.safeString2(trade, 'p', 'price');
4345
4402
  let amount = this.safeString2(trade, 'q', 'qty');
4346
4403
  amount = this.safeString(trade, 'quantity', amount);
4347
- const cost = this.safeString2(trade, 'quoteQty', 'baseQty'); // inverse futures
4348
4404
  const marketId = this.safeString(trade, 'symbol');
4349
- const isSpotTrade = ('isIsolated' in trade) || ('M' in trade) || ('orderListId' in trade);
4405
+ const isSpotTrade = ('isIsolated' in trade) || ('M' in trade) || ('orderListId' in trade) || ('isMaker' in trade);
4350
4406
  const marketType = isSpotTrade ? 'spot' : 'contract';
4351
4407
  market = this.safeMarket(marketId, market, undefined, marketType);
4352
4408
  const symbol = market['symbol'];
4353
- let id = this.safeString2(trade, 't', 'a');
4354
- id = this.safeString2(trade, 'tradeId', 'id', id);
4355
4409
  let side = undefined;
4356
- const orderId = this.safeString(trade, 'orderId');
4357
4410
  const buyerMaker = this.safeValue2(trade, 'm', 'isBuyerMaker');
4358
4411
  let takerOrMaker = undefined;
4359
4412
  if (buyerMaker !== undefined) {
@@ -4403,14 +4456,14 @@ export default class binance extends Exchange {
4403
4456
  'timestamp': timestamp,
4404
4457
  'datetime': this.iso8601(timestamp),
4405
4458
  'symbol': symbol,
4406
- 'id': id,
4407
- 'order': orderId,
4459
+ 'id': this.safeStringN(trade, ['t', 'a', 'tradeId', 'id']),
4460
+ 'order': this.safeString(trade, 'orderId'),
4408
4461
  'type': this.safeStringLower(trade, 'type'),
4409
4462
  'side': side,
4410
4463
  'takerOrMaker': takerOrMaker,
4411
- 'price': price,
4464
+ 'price': this.safeString2(trade, 'p', 'price'),
4412
4465
  'amount': amount,
4413
- 'cost': cost,
4466
+ 'cost': this.safeString2(trade, 'quoteQty', 'baseQty'),
4414
4467
  'fee': fee,
4415
4468
  }, market);
4416
4469
  }
@@ -6499,12 +6552,16 @@ export default class binance extends Exchange {
6499
6552
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-trade-list-user_data
6500
6553
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-trade-list-user_data
6501
6554
  * @see https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-trade-list-user_data
6555
+ * @see https://binance-docs.github.io/apidocs/pm/en/#margin-account-trade-list-user_data
6556
+ * @see https://binance-docs.github.io/apidocs/pm/en/#um-account-trade-list-user_data
6557
+ * @see https://binance-docs.github.io/apidocs/pm/en/#cm-account-trade-list-user_data
6502
6558
  * @param {string} symbol unified market symbol
6503
6559
  * @param {int} [since] the earliest time in ms to fetch trades for
6504
6560
  * @param {int} [limit] the maximum number of trades structures to retrieve
6505
6561
  * @param {object} [params] extra parameters specific to the exchange API endpoint
6506
- * @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)
6562
+ * @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)
6507
6563
  * @param {int} [params.until] the latest time in ms to fetch entries for
6564
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch trades for a portfolio margin account
6508
6565
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
6509
6566
  */
6510
6567
  await this.loadMarkets();
@@ -6558,8 +6615,13 @@ export default class binance extends Exchange {
6558
6615
  throw new ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
6559
6616
  }
6560
6617
  [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
6618
+ let isPortfolioMargin = undefined;
6619
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchMyTrades', 'papi', 'portfolioMargin', false);
6561
6620
  if (type === 'spot' || type === 'margin') {
6562
- if ((type === 'margin') || (marginMode !== undefined)) {
6621
+ if (isPortfolioMargin) {
6622
+ response = await this.papiGetMarginMyTrades(this.extend(request, params));
6623
+ }
6624
+ else if ((type === 'margin') || (marginMode !== undefined)) {
6563
6625
  if (marginMode === 'isolated') {
6564
6626
  request['isIsolated'] = true;
6565
6627
  }
@@ -6570,10 +6632,20 @@ export default class binance extends Exchange {
6570
6632
  }
6571
6633
  }
6572
6634
  else if (market['linear']) {
6573
- response = await this.fapiPrivateGetUserTrades(this.extend(request, params));
6635
+ if (isPortfolioMargin) {
6636
+ response = await this.papiGetUmUserTrades(this.extend(request, params));
6637
+ }
6638
+ else {
6639
+ response = await this.fapiPrivateGetUserTrades(this.extend(request, params));
6640
+ }
6574
6641
  }
6575
6642
  else if (market['inverse']) {
6576
- response = await this.dapiPrivateGetUserTrades(this.extend(request, params));
6643
+ if (isPortfolioMargin) {
6644
+ response = await this.papiGetCmUserTrades(this.extend(request, params));
6645
+ }
6646
+ else {
6647
+ response = await this.dapiPrivateGetUserTrades(this.extend(request, params));
6648
+ }
6577
6649
  }
6578
6650
  }
6579
6651
  //
@@ -6641,6 +6713,70 @@ export default class binance extends Exchange {
6641
6713
  // }
6642
6714
  // ]
6643
6715
  //
6716
+ // linear portfolio margin
6717
+ //
6718
+ // [
6719
+ // {
6720
+ // "symbol": "BTCUSDT",
6721
+ // "id": 4575108247,
6722
+ // "orderId": 261942655610,
6723
+ // "side": "SELL",
6724
+ // "price": "47263.40",
6725
+ // "qty": "0.010",
6726
+ // "realizedPnl": "27.38400000",
6727
+ // "marginAsset": "USDT",
6728
+ // "quoteQty": "472.63",
6729
+ // "commission": "0.18905360",
6730
+ // "commissionAsset": "USDT",
6731
+ // "time": 1707530039409,
6732
+ // "buyer": false,
6733
+ // "maker": false,
6734
+ // "positionSide": "LONG"
6735
+ // }
6736
+ // ]
6737
+ //
6738
+ // inverse portfolio margin
6739
+ //
6740
+ // [
6741
+ // {
6742
+ // "symbol": "ETHUSD_PERP",
6743
+ // "id": 701907838,
6744
+ // "orderId": 71548909034,
6745
+ // "pair": "ETHUSD",
6746
+ // "side": "SELL",
6747
+ // "price": "2498.15",
6748
+ // "qty": "1",
6749
+ // "realizedPnl": "0.00012517",
6750
+ // "marginAsset": "ETH",
6751
+ // "baseQty": "0.00400296",
6752
+ // "commission": "0.00000160",
6753
+ // "commissionAsset": "ETH",
6754
+ // "time": 1707530317519,
6755
+ // "positionSide": "LONG",
6756
+ // "buyer": false,
6757
+ // "maker": false
6758
+ // }
6759
+ // ]
6760
+ //
6761
+ // spot margin portfolio margin
6762
+ //
6763
+ // [
6764
+ // {
6765
+ // "symbol": "ADAUSDT",
6766
+ // "id": 470227543,
6767
+ // "orderId": 4421170947,
6768
+ // "price": "0.53880000",
6769
+ // "qty": "10.00000000",
6770
+ // "quoteQty": "5.38800000",
6771
+ // "commission": "0.00538800",
6772
+ // "commissionAsset": "USDT",
6773
+ // "time": 1707545780522,
6774
+ // "isBuyer": false,
6775
+ // "isMaker": false,
6776
+ // "isBestMatch": true
6777
+ // }
6778
+ // ]
6779
+ //
6644
6780
  return this.parseTrades(response, market, since, limit);
6645
6781
  }
6646
6782
  async fetchMyDustTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -10527,15 +10663,19 @@ export default class binance extends Exchange {
10527
10663
  * @name binance#fetchBorrowInterest
10528
10664
  * @description fetch the interest owed by the user for borrowing currency for margin trading
10529
10665
  * @see https://binance-docs.github.io/apidocs/spot/en/#get-interest-history-user_data
10530
- * @param {string} code unified currency code
10531
- * @param {string} symbol unified market symbol when fetch interest in isolated markets
10666
+ * @see https://binance-docs.github.io/apidocs/pm/en/#get-margin-borrow-loan-interest-history-user_data
10667
+ * @param {string} [code] unified currency code
10668
+ * @param {string} [symbol] unified market symbol when fetch interest in isolated markets
10532
10669
  * @param {int} [since] the earliest time in ms to fetch borrrow interest for
10533
10670
  * @param {int} [limit] the maximum number of structures to retrieve
10534
10671
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10672
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the borrow interest in a portfolio margin account
10535
10673
  * @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/#/?id=borrow-interest-structure}
10536
10674
  */
10537
10675
  await this.loadMarkets();
10538
- const request = {};
10676
+ let isPortfolioMargin = undefined;
10677
+ [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'fetchBorrowInterest', 'papi', 'portfolioMargin', false);
10678
+ let request = {};
10539
10679
  let market = undefined;
10540
10680
  if (code !== undefined) {
10541
10681
  const currency = this.currency(code);
@@ -10547,11 +10687,20 @@ export default class binance extends Exchange {
10547
10687
  if (limit !== undefined) {
10548
10688
  request['size'] = limit;
10549
10689
  }
10550
- if (symbol !== undefined) { // Isolated
10551
- market = this.market(symbol);
10552
- request['isolatedSymbol'] = market['id'];
10690
+ [request, params] = this.handleUntilOption('endTime', request, params);
10691
+ let response = undefined;
10692
+ if (isPortfolioMargin) {
10693
+ response = await this.papiGetMarginMarginInterestHistory(this.extend(request, params));
10694
+ }
10695
+ else {
10696
+ if (symbol !== undefined) {
10697
+ market = this.market(symbol);
10698
+ request['isolatedSymbol'] = market['id'];
10699
+ }
10700
+ response = await this.sapiGetMarginInterestHistory(this.extend(request, params));
10553
10701
  }
10554
- const response = await this.sapiGetMarginInterestHistory(this.extend(request, params));
10702
+ //
10703
+ // spot margin
10555
10704
  //
10556
10705
  // {
10557
10706
  // "rows":[
@@ -10568,13 +10717,31 @@ export default class binance extends Exchange {
10568
10717
  // "total": 1
10569
10718
  // }
10570
10719
  //
10720
+ // spot margin portfolio margin
10721
+ //
10722
+ // {
10723
+ // "total": 49,
10724
+ // "rows": [
10725
+ // {
10726
+ // "txId": 1656187724899910076,
10727
+ // "interestAccuredTime": 1707541200000,
10728
+ // "asset": "USDT",
10729
+ // "rawAsset": "USDT",
10730
+ // "principal": "0.00011146",
10731
+ // "interest": "0.00000001",
10732
+ // "interestRate": "0.00089489",
10733
+ // "type": "PERIODIC"
10734
+ // },
10735
+ // ]
10736
+ // }
10737
+ //
10571
10738
  const rows = this.safeList(response, 'rows');
10572
10739
  const interest = this.parseBorrowInterests(rows, market);
10573
10740
  return this.filterByCurrencySinceLimit(interest, code, since, limit);
10574
10741
  }
10575
10742
  parseBorrowInterest(info, market = undefined) {
10576
10743
  const symbol = this.safeString(info, 'isolatedSymbol');
10577
- const timestamp = this.safeNumber(info, 'interestAccuredTime');
10744
+ const timestamp = this.safeInteger(info, 'interestAccuredTime');
10578
10745
  const marginMode = (symbol === undefined) ? 'cross' : 'isolated';
10579
10746
  return {
10580
10747
  'account': (symbol === undefined) ? 'cross' : symbol,
package/js/src/bingx.d.ts CHANGED
@@ -73,6 +73,7 @@ export default class bingx extends Exchange {
73
73
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: number, params?: {}): Promise<Order>;
74
74
  createOrders(orders: OrderRequest[], params?: {}): Promise<Order[]>;
75
75
  parseOrderSide(side: any): string;
76
+ parseOrderType(type: any): string;
76
77
  parseOrder(order: any, market?: Market): Order;
77
78
  parseOrderStatus(status: any): string;
78
79
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;
package/js/src/bingx.js CHANGED
@@ -1800,6 +1800,7 @@ export default class bingx extends Exchange {
1800
1800
  if (timeInForce === 'IOC') {
1801
1801
  request['timeInForce'] = 'IOC';
1802
1802
  }
1803
+ const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1803
1804
  if (isSpot) {
1804
1805
  [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'POC', params);
1805
1806
  if (postOnly || (timeInForce === 'POC')) {
@@ -1811,7 +1812,7 @@ export default class bingx extends Exchange {
1811
1812
  request['quoteOrderQty'] = this.parseToNumeric(this.costToPrecision(symbol, cost));
1812
1813
  }
1813
1814
  else {
1814
- if (market['spot'] && isMarketOrder && (price !== undefined)) {
1815
+ if (isMarketOrder && (price !== undefined)) {
1815
1816
  // keep the legacy behavior, to avoid breaking the old spot-market-buying code
1816
1817
  const calculatedCost = Precise.stringMul(this.numberToString(amount), this.numberToString(price));
1817
1818
  request['quoteOrderQty'] = this.parseToNumeric(calculatedCost);
@@ -1823,6 +1824,18 @@ export default class bingx extends Exchange {
1823
1824
  if (!isMarketOrder) {
1824
1825
  request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1825
1826
  }
1827
+ if (triggerPrice !== undefined) {
1828
+ if (isMarketOrder && this.safeString(request, 'quoteOrderQty') === undefined) {
1829
+ throw new ArgumentsRequired(this.id + ' createOrder() requires the cost parameter (or the amount + price) for placing spot market-buy trigger orders');
1830
+ }
1831
+ request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
1832
+ if (type === 'LIMIT') {
1833
+ request['type'] = 'TRIGGER_LIMIT';
1834
+ }
1835
+ else if (type === 'MARKET') {
1836
+ request['type'] = 'TRIGGER_MARKET';
1837
+ }
1838
+ }
1826
1839
  }
1827
1840
  else {
1828
1841
  [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'PostOnly', params);
@@ -1835,7 +1848,6 @@ export default class bingx extends Exchange {
1835
1848
  else if (timeInForce === 'FOK') {
1836
1849
  request['timeInForce'] = 'FOK';
1837
1850
  }
1838
- const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1839
1851
  const stopLossPrice = this.safeString(params, 'stopLossPrice');
1840
1852
  const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1841
1853
  const trailingAmount = this.safeString(params, 'trailingAmount');
@@ -2135,6 +2147,13 @@ export default class bingx extends Exchange {
2135
2147
  };
2136
2148
  return this.safeString(sides, side, side);
2137
2149
  }
2150
+ parseOrderType(type) {
2151
+ const types = {
2152
+ 'trigger_market': 'market',
2153
+ 'trigger_limit': 'limit',
2154
+ };
2155
+ return this.safeString(types, type, type);
2156
+ }
2138
2157
  parseOrder(order, market = undefined) {
2139
2158
  //
2140
2159
  // spot
@@ -2399,7 +2418,7 @@ export default class bingx extends Exchange {
2399
2418
  'datetime': this.iso8601(timestamp),
2400
2419
  'lastTradeTimestamp': lastTradeTimestamp,
2401
2420
  'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
2402
- 'type': this.safeStringLower2(order, 'type', 'o'),
2421
+ 'type': this.parseOrderType(this.safeStringLower2(order, 'type', 'o')),
2403
2422
  'timeInForce': this.safeString(order, 'timeInForce'),
2404
2423
  'postOnly': undefined,
2405
2424
  'side': this.parseOrderSide(side),
@@ -645,8 +645,8 @@ export default class bitforex extends Exchange {
645
645
  }
646
646
  parseOrder(order, market = undefined) {
647
647
  const id = this.safeString(order, 'orderId');
648
- const timestamp = this.safeNumber(order, 'createTime');
649
- const lastTradeTimestamp = this.safeNumber(order, 'lastTime');
648
+ const timestamp = this.safeInteger(order, 'createTime');
649
+ const lastTradeTimestamp = this.safeInteger(order, 'lastTime');
650
650
  const symbol = market['symbol'];
651
651
  const sideId = this.safeInteger(order, 'tradeType');
652
652
  const side = this.parseSide(sideId);
@@ -1939,7 +1939,7 @@ export default class currencycom extends Exchange {
1939
1939
  //
1940
1940
  market = this.safeMarket(this.safeString(position, 'symbol'), market);
1941
1941
  const symbol = market['symbol'];
1942
- const timestamp = this.safeNumber(position, 'createdTimestamp');
1942
+ const timestamp = this.safeInteger(position, 'createdTimestamp');
1943
1943
  const quantityRaw = this.safeString(position, 'openQuantity');
1944
1944
  const side = Precise.stringGt(quantityRaw, '0') ? 'long' : 'short';
1945
1945
  const quantity = Precise.stringAbs(quantityRaw);
package/js/src/htx.js CHANGED
@@ -7091,7 +7091,7 @@ export default class htx extends Exchange {
7091
7091
  const marginMode = (marketId === undefined) ? 'cross' : 'isolated';
7092
7092
  market = this.safeMarket(marketId);
7093
7093
  const symbol = this.safeString(market, 'symbol');
7094
- const timestamp = this.safeNumber(info, 'accrued-at');
7094
+ const timestamp = this.safeInteger(info, 'accrued-at');
7095
7095
  return {
7096
7096
  'account': (marginMode === 'isolated') ? symbol : 'cross',
7097
7097
  'symbol': symbol,
package/js/src/mexc.js CHANGED
@@ -4756,7 +4756,7 @@ export default class mexc extends Exchange {
4756
4756
  const marginType = (openType === '1') ? 'isolated' : 'cross';
4757
4757
  const leverage = this.safeNumber(position, 'leverage');
4758
4758
  const liquidationPrice = this.safeNumber(position, 'liquidatePrice');
4759
- const timestamp = this.safeNumber(position, 'updateTime');
4759
+ const timestamp = this.safeInteger(position, 'updateTime');
4760
4760
  return this.safePosition({
4761
4761
  'info': position,
4762
4762
  'id': undefined,
package/js/src/pro/cex.js CHANGED
@@ -188,7 +188,7 @@ export default class cex extends cexRest {
188
188
  trade = trade.split(':');
189
189
  }
190
190
  const side = this.safeString(trade, 0);
191
- const timestamp = this.safeNumber(trade, 1);
191
+ const timestamp = this.safeInteger(trade, 1);
192
192
  const amount = this.safeString(trade, 2);
193
193
  const price = this.safeString(trade, 3);
194
194
  const id = this.safeString(trade, 4);
@@ -644,7 +644,7 @@ export default class gemini extends geminiRest {
644
644
  // "socket_sequence": 139
645
645
  // }
646
646
  //
647
- const timestamp = this.safeNumber(order, 'timestampms');
647
+ const timestamp = this.safeInteger(order, 'timestampms');
648
648
  const status = this.safeString(order, 'type');
649
649
  const marketId = this.safeString(order, 'symbol');
650
650
  const typeId = this.safeString(order, 'order_type');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.40",
3
+ "version": "4.2.41",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",