ccxt 4.2.40 → 4.2.42

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.
Files changed (44) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +261 -58
  3. package/dist/ccxt.browser.min.js +2 -2
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/binance.js +189 -22
  6. package/dist/cjs/src/bingx.js +22 -3
  7. package/dist/cjs/src/bitforex.js +2 -2
  8. package/dist/cjs/src/bitget.js +9 -2
  9. package/dist/cjs/src/bitrue.js +7 -15
  10. package/dist/cjs/src/currencycom.js +1 -1
  11. package/dist/cjs/src/digifinex.js +4 -1
  12. package/dist/cjs/src/gate.js +4 -1
  13. package/dist/cjs/src/gemini.js +4 -1
  14. package/dist/cjs/src/htx.js +1 -1
  15. package/dist/cjs/src/mexc.js +5 -2
  16. package/dist/cjs/src/phemex.js +4 -1
  17. package/dist/cjs/src/poloniex.js +4 -1
  18. package/dist/cjs/src/pro/cex.js +1 -1
  19. package/dist/cjs/src/pro/gemini.js +1 -1
  20. package/dist/cjs/src/pro/hitbtc.js +1 -1
  21. package/dist/cjs/src/pro/poloniex.js +1 -1
  22. package/js/ccxt.d.ts +1 -1
  23. package/js/ccxt.js +1 -1
  24. package/js/src/base/Exchange.d.ts +20 -20
  25. package/js/src/binance.js +189 -22
  26. package/js/src/bingx.d.ts +1 -0
  27. package/js/src/bingx.js +22 -3
  28. package/js/src/bitforex.js +2 -2
  29. package/js/src/bitget.d.ts +2 -2
  30. package/js/src/bitget.js +9 -2
  31. package/js/src/bitrue.js +7 -15
  32. package/js/src/currencycom.js +1 -1
  33. package/js/src/digifinex.js +4 -1
  34. package/js/src/gate.js +4 -1
  35. package/js/src/gemini.js +4 -1
  36. package/js/src/htx.js +1 -1
  37. package/js/src/mexc.js +5 -2
  38. package/js/src/phemex.js +4 -1
  39. package/js/src/poloniex.js +4 -1
  40. package/js/src/pro/cex.js +1 -1
  41. package/js/src/pro/gemini.js +1 -1
  42. package/js/src/pro/hitbtc.js +1 -1
  43. package/js/src/pro/poloniex.js +1 -1
  44. package/package.json +1 -1
@@ -557,14 +557,14 @@ export default class Exchange {
557
557
  countedOrderBook(snapshot?: {}, depth?: number): CountedOrderBook;
558
558
  handleMessage(client: any, message: any): void;
559
559
  ping(client: any): any;
560
- client(url: any): WsClient;
561
- watchMultiple(url: any, messageHashes: any, message?: any, subscribeHashes?: any, subscription?: any): import("./ws/Future.js").FutureInterface;
562
- watch(url: any, messageHash: any, message?: any, subscribeHash?: any, subscription?: any): any;
560
+ client(url: string): WsClient;
561
+ watchMultiple(url: string, messageHashes: string[], message?: any, subscribeHashes?: any, subscription?: any): import("./ws/Future.js").FutureInterface;
562
+ watch(url: string, messageHash: string, message?: any, subscribeHash?: any, subscription?: any): any;
563
563
  onConnected(client: any, message?: any): void;
564
564
  onError(client: any, error: any): void;
565
565
  onClose(client: any, error: any): void;
566
566
  close(): Promise<void>;
567
- loadOrderBook(client: any, messageHash: any, symbol: any, limit?: any, params?: {}): Promise<void>;
567
+ loadOrderBook(client: any, messageHash: string, symbol: string, limit?: Int, params?: {}): Promise<void>;
568
568
  convertToBigInt(value: string): bigint;
569
569
  stringToCharsArray(value: any): any;
570
570
  valueIsDefined(value: any): boolean;
@@ -572,7 +572,7 @@ export default class Exchange {
572
572
  getProperty(obj: any, property: any, defaultValue?: any): any;
573
573
  setProperty(obj: any, property: any, defaultValue?: any): void;
574
574
  axolotl(payload: any, hexKey: any, ed25519: any): string;
575
- fixStringifiedJsonMembers(content: any): any;
575
+ fixStringifiedJsonMembers(content: string): any;
576
576
  safeBoolN(dictionaryOrList: any, keys: IndexType[], defaultValue?: boolean): boolean | undefined;
577
577
  safeBool2(dictionary: any, key1: IndexType, key2: IndexType, defaultValue?: boolean): boolean | undefined;
578
578
  safeBool(dictionary: any, key: IndexType, defaultValue?: boolean): boolean | undefined;
@@ -586,8 +586,8 @@ export default class Exchange {
586
586
  handleDelta(bookside: any, delta: any): void;
587
587
  getCacheIndex(orderbook: any, deltas: any): number;
588
588
  findTimeframe(timeframe: any, timeframes?: any): string;
589
- checkProxyUrlSettings(url?: any, method?: any, headers?: any, body?: any): any;
590
- checkProxySettings(url?: any, method?: any, headers?: any, body?: any): any[];
589
+ checkProxyUrlSettings(url?: string, method?: string, headers?: any, body?: any): any;
590
+ checkProxySettings(url?: string, method?: string, headers?: any, body?: any): any[];
591
591
  checkWsProxySettings(): any[];
592
592
  checkConflictingProxies(proxyAgentSet: any, proxyUrlSet: any): void;
593
593
  findMessageHashes(client: any, element: string): string[];
@@ -718,8 +718,8 @@ export default class Exchange {
718
718
  fetchL2OrderBook(symbol: string, limit?: Int, params?: {}): Promise<any>;
719
719
  filterBySymbol(objects: any, symbol?: string): any;
720
720
  parseOHLCV(ohlcv: any, market?: Market): OHLCV;
721
- networkCodeToId(networkCode: any, currencyCode?: any): string;
722
- networkIdToCode(networkId: any, currencyCode?: any): string;
721
+ networkCodeToId(networkCode: string, currencyCode?: string): string;
722
+ networkIdToCode(networkId: string, currencyCode?: string): string;
723
723
  handleNetworkCodeAndParams(params: any): any[];
724
724
  defaultNetworkCode(currencyCode: string): any;
725
725
  selectNetworkCodeFromUnifiedNetworks(currencyCode: any, networkCode: any, indexedNetworkEntries: any): any;
@@ -728,14 +728,14 @@ export default class Exchange {
728
728
  safeNumber2(dictionary: object, key1: IndexType, key2: IndexType, d?: any): number;
729
729
  parseOrderBook(orderbook: object, symbol: string, timestamp?: Int, bidsKey?: string, asksKey?: string, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): OrderBook;
730
730
  parseOHLCVs(ohlcvs: object[], market?: any, timeframe?: string, since?: Int, limit?: Int): OHLCV[];
731
- parseLeverageTiers(response: any, symbols?: string[], marketIdKey?: any): {};
731
+ parseLeverageTiers(response: object[], symbols?: string[], marketIdKey?: any): {};
732
732
  loadTradingLimits(symbols?: string[], reload?: boolean, params?: {}): Promise<Dictionary<any>>;
733
733
  safePosition(position: any): Position;
734
- parsePositions(positions: any, symbols?: string[], params?: {}): Position[];
735
- parseAccounts(accounts: any, params?: {}): any[];
736
- parseTrades(trades: any, market?: Market, since?: Int, limit?: Int, params?: {}): Trade[];
737
- parseTransactions(transactions: any, currency?: Currency, since?: Int, limit?: Int, params?: {}): Transaction[];
738
- parseTransfers(transfers: any, currency?: Currency, since?: Int, limit?: Int, params?: {}): any;
734
+ parsePositions(positions: any[], symbols?: string[], params?: {}): Position[];
735
+ parseAccounts(accounts: any[], params?: {}): any[];
736
+ parseTrades(trades: any[], market?: Market, since?: Int, limit?: Int, params?: {}): Trade[];
737
+ parseTransactions(transactions: any[], currency?: Currency, since?: Int, limit?: Int, params?: {}): Transaction[];
738
+ parseTransfers(transfers: any[], currency?: Currency, since?: Int, limit?: Int, params?: {}): any;
739
739
  parseLedger(data: any, currency?: Currency, since?: Int, limit?: Int, params?: {}): any;
740
740
  nonce(): number;
741
741
  setHeaders(headers: any): any;
@@ -748,9 +748,9 @@ export default class Exchange {
748
748
  loadAccounts(reload?: boolean, params?: {}): Promise<any>;
749
749
  buildOHLCVC(trades: Trade[], timeframe?: string, since?: number, limit?: number): OHLCVC[];
750
750
  parseTradingViewOHLCV(ohlcvs: any, market?: any, timeframe?: string, since?: Int, limit?: Int): OHLCV[];
751
- editLimitBuyOrder(id: any, symbol: any, amount: number, price?: number, params?: {}): Promise<Order>;
752
- editLimitSellOrder(id: any, symbol: any, amount: number, price?: number, params?: {}): Promise<Order>;
753
- editLimitOrder(id: any, symbol: any, side: any, amount: number, price?: number, params?: {}): Promise<Order>;
751
+ editLimitBuyOrder(id: string, symbol: string, amount: number, price?: number, params?: {}): Promise<Order>;
752
+ editLimitSellOrder(id: string, symbol: string, amount: number, price?: number, params?: {}): Promise<Order>;
753
+ editLimitOrder(id: string, symbol: string, side: OrderSide, amount: number, price?: number, params?: {}): Promise<Order>;
754
754
  editOrder(id: string, symbol: string, type: OrderType, side: OrderSide, amount?: number, price?: number, params?: {}): Promise<Order>;
755
755
  editOrderWs(id: string, symbol: string, type: OrderType, side: OrderSide, amount: number, price?: number, params?: {}): Promise<Order>;
756
756
  fetchPermissions(params?: {}): Promise<{}>;
@@ -912,7 +912,7 @@ export default class Exchange {
912
912
  fetchPremiumIndexOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
913
913
  handleTimeInForce(params?: {}): string;
914
914
  convertTypeToAccount(account: any): any;
915
- checkRequiredArgument(methodName: any, argument: any, argumentName: any, options?: any[]): void;
915
+ checkRequiredArgument(methodName: string, argument: any, argumentName: any, options?: any[]): void;
916
916
  checkRequiredMarginArgument(methodName: string, symbol: Str, marginMode: string): void;
917
917
  parseDepositWithdrawFees(response: any, codes?: string[], currencyIdKey?: any): any;
918
918
  parseDepositWithdrawFee(fee: any, currency?: Currency): any;
@@ -934,7 +934,7 @@ export default class Exchange {
934
934
  fetchPaginatedCallIncremental(method: string, symbol?: string, since?: any, limit?: any, params?: {}, pageKey?: any, maxEntriesPerRequest?: any): Promise<any>;
935
935
  sortCursorPaginatedResult(result: any): any;
936
936
  removeRepeatedElementsFromArray(input: any): any;
937
- handleUntilOption(key: any, request: any, params: any, multiplier?: number): any[];
937
+ handleUntilOption(key: string, request: any, params: any, multiplier?: number): any[];
938
938
  safeOpenInterest(interest: any, market?: Market): OpenInterest;
939
939
  parseLiquidation(liquidation: any, market?: Market): Liquidation;
940
940
  parseLiquidations(liquidations: any, market?: any, since?: Int, limit?: Int): Liquidation[];
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);
@@ -25,14 +25,14 @@ export default class bitget extends Exchange {
25
25
  currency: string;
26
26
  address: string;
27
27
  tag: string;
28
- network: string;
28
+ network: any;
29
29
  info: any;
30
30
  }>;
31
31
  parseDepositAddress(depositAddress: any, currency?: Currency): {
32
32
  currency: string;
33
33
  address: string;
34
34
  tag: string;
35
- network: string;
35
+ network: any;
36
36
  info: any;
37
37
  };
38
38
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
package/js/src/bitget.js CHANGED
@@ -2421,7 +2421,10 @@ export default class bitget extends Exchange {
2421
2421
  await this.loadMarkets();
2422
2422
  const networkCode = this.safeString2(params, 'chain', 'network');
2423
2423
  params = this.omit(params, 'network');
2424
- const networkId = this.networkCodeToId(networkCode, code);
2424
+ let networkId = undefined;
2425
+ if (networkCode !== undefined) {
2426
+ networkId = this.networkCodeToId(networkCode, code);
2427
+ }
2425
2428
  const currency = this.currency(code);
2426
2429
  const request = {
2427
2430
  'coin': currency['code'],
@@ -2460,11 +2463,15 @@ export default class bitget extends Exchange {
2460
2463
  const currencyId = this.safeString(depositAddress, 'coin');
2461
2464
  const networkId = this.safeString(depositAddress, 'chain');
2462
2465
  const parsedCurrency = this.safeCurrencyCode(currencyId, currency);
2466
+ let network = undefined;
2467
+ if (networkId !== undefined) {
2468
+ network = this.networkIdToCode(networkId, parsedCurrency);
2469
+ }
2463
2470
  return {
2464
2471
  'currency': parsedCurrency,
2465
2472
  'address': this.safeString(depositAddress, 'address'),
2466
2473
  'tag': this.safeString(depositAddress, 'tag'),
2467
- 'network': this.networkIdToCode(networkId, parsedCurrency),
2474
+ 'network': network,
2468
2475
  'info': depositAddress,
2469
2476
  };
2470
2477
  }
package/js/src/bitrue.js CHANGED
@@ -2780,28 +2780,20 @@ export default class bitrue extends Exchange {
2780
2780
  this.checkAddress(address);
2781
2781
  await this.loadMarkets();
2782
2782
  const currency = this.currency(code);
2783
- let chainName = this.safeString2(params, 'network', 'chainName');
2784
- if (chainName === undefined) {
2785
- const networks = this.safeValue(currency, 'networks', {});
2786
- const optionsNetworks = this.safeValue(this.options, 'networks', {});
2787
- let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
2788
- network = this.safeString(optionsNetworks, network, network);
2789
- const networkEntry = this.safeValue(networks, network, {});
2790
- chainName = this.safeString(networkEntry, 'id'); // handle ERC20>ETH alias
2791
- if (chainName === undefined) {
2792
- throw new ArgumentsRequired(this.id + ' withdraw() requires a network parameter or a chainName parameter');
2793
- }
2794
- params = this.omit(params, 'network');
2795
- }
2796
2783
  const request = {
2797
- 'coin': currency['id'].toUpperCase(),
2784
+ 'coin': currency['id'],
2798
2785
  'amount': amount,
2799
2786
  'addressTo': address,
2800
- 'chainName': chainName, // 'ERC20', 'TRC20', 'SOL'
2787
+ // 'chainName': chainName, // 'ERC20', 'TRC20', 'SOL'
2801
2788
  // 'addressMark': '', // mark of address
2802
2789
  // 'addrType': '', // type of address
2803
2790
  // 'tag': tag,
2804
2791
  };
2792
+ let networkCode = undefined;
2793
+ [networkCode, params] = this.handleNetworkCodeAndParams(params);
2794
+ if (networkCode !== undefined) {
2795
+ request['chainName'] = this.networkCodeToId(networkCode);
2796
+ }
2805
2797
  if (tag !== undefined) {
2806
2798
  request['tag'] = tag;
2807
2799
  }
@@ -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);
@@ -415,7 +415,10 @@ export default class digifinex extends Exchange {
415
415
  const minFoundPrecision = Precise.stringMin(feeString, Precise.stringMin(minDepositString, minWithdrawString));
416
416
  const precision = this.parseNumber(minFoundPrecision);
417
417
  const networkId = this.safeString(currency, 'chain');
418
- const networkCode = this.networkIdToCode(networkId);
418
+ let networkCode = undefined;
419
+ if (networkId !== undefined) {
420
+ networkCode = this.networkIdToCode(networkId);
421
+ }
419
422
  const network = {
420
423
  'info': currency,
421
424
  'id': networkId,
package/js/src/gate.js CHANGED
@@ -1590,7 +1590,10 @@ export default class gate extends Exchange {
1590
1590
  const currency = parts[0];
1591
1591
  const code = this.safeCurrencyCode(currency);
1592
1592
  const networkId = this.safeString(entry, 'chain');
1593
- const networkCode = this.networkIdToCode(networkId, code);
1593
+ let networkCode = undefined;
1594
+ if (networkId !== undefined) {
1595
+ networkCode = this.networkIdToCode(networkId, code);
1596
+ }
1594
1597
  const delisted = this.safeValue(entry, 'delisted');
1595
1598
  const withdrawDisabled = this.safeBool(entry, 'withdraw_disabled', false);
1596
1599
  const depositDisabled = this.safeBool(entry, 'deposit_disabled', false);
package/js/src/gemini.js CHANGED
@@ -346,7 +346,10 @@ export default class gemini extends Exchange {
346
346
  const precision = this.parseNumber(this.parsePrecision(this.safeString(currency, 5)));
347
347
  const networks = {};
348
348
  const networkId = this.safeString(currency, 9);
349
- const networkCode = this.networkIdToCode(networkId);
349
+ let networkCode = undefined;
350
+ if (networkId !== undefined) {
351
+ networkCode = this.networkIdToCode(networkId);
352
+ }
350
353
  if (networkCode !== undefined) {
351
354
  networks[networkCode] = {
352
355
  'info': currency,
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,