ccxt 4.5.39 → 4.5.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.
Files changed (138) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +18 -18
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/lighter.js +11 -0
  5. package/dist/cjs/src/ascendex.js +73 -1
  6. package/dist/cjs/src/base/Exchange.js +211 -22
  7. package/dist/cjs/src/base/functions/generic.js +1 -0
  8. package/dist/cjs/src/base/functions/io.js +160 -0
  9. package/dist/cjs/src/base/functions.js +6 -0
  10. package/dist/cjs/src/base/ws/Client.js +1 -0
  11. package/dist/cjs/src/base/ws/WsClient.js +1 -0
  12. package/dist/cjs/src/binance.js +143 -0
  13. package/dist/cjs/src/bingx.js +150 -123
  14. package/dist/cjs/src/bitmart.js +20 -6
  15. package/dist/cjs/src/bitmex.js +436 -0
  16. package/dist/cjs/src/blofin.js +86 -1
  17. package/dist/cjs/src/bybit.js +135 -0
  18. package/dist/cjs/src/coinspot.js +7 -2
  19. package/dist/cjs/src/delta.js +367 -0
  20. package/dist/cjs/src/gate.js +11 -4
  21. package/dist/cjs/src/gemini.js +76 -1
  22. package/dist/cjs/src/htx.js +266 -3
  23. package/dist/cjs/src/hyperliquid.js +20 -7
  24. package/dist/cjs/src/independentreserve.js +7 -7
  25. package/dist/cjs/src/kraken.js +1 -1
  26. package/dist/cjs/src/krakenfutures.js +96 -5
  27. package/dist/cjs/src/kucoin.js +3 -3
  28. package/dist/cjs/src/kucoinfutures.js +121 -0
  29. package/dist/cjs/src/lighter.js +2931 -0
  30. package/dist/cjs/src/mexc.js +9 -2
  31. package/dist/cjs/src/phemex.js +359 -0
  32. package/dist/cjs/src/poloniex.js +5 -0
  33. package/dist/cjs/src/pro/binance.js +2 -2
  34. package/dist/cjs/src/pro/bingx.js +248 -35
  35. package/dist/cjs/src/pro/bitget.js +49 -90
  36. package/dist/cjs/src/pro/bitmart.js +68 -0
  37. package/dist/cjs/src/pro/blofin.js +52 -1
  38. package/dist/cjs/src/pro/coinbaseinternational.js +5 -2
  39. package/dist/cjs/src/pro/defx.js +1 -1
  40. package/dist/cjs/src/pro/kucoinfutures.js +1 -1
  41. package/dist/cjs/src/pro/lighter.js +787 -0
  42. package/dist/cjs/src/pro/mexc.js +73 -1
  43. package/dist/cjs/src/pro/okx.js +7 -4
  44. package/dist/cjs/src/pro/paradex.js +138 -1
  45. package/dist/cjs/src/pro/woo.js +43 -0
  46. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +1 -0
  47. package/dist/cjs/src/static_dependencies/ethers/address/address.js +1 -0
  48. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +1 -0
  49. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +1 -0
  50. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +1 -0
  51. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +1 -0
  52. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +1 -0
  53. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +1 -0
  54. package/dist/cjs/src/static_dependencies/ethers/fragments.js +1 -0
  55. package/dist/cjs/src/static_dependencies/ethers/index.js +1 -0
  56. package/dist/cjs/src/static_dependencies/ethers/interface.js +1 -0
  57. package/dist/cjs/src/static_dependencies/ethers/typed.js +1 -0
  58. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +1 -0
  59. package/dist/cjs/src/whitebit.js +118 -16
  60. package/dist/cjs/src/woo.js +103 -3
  61. package/js/ccxt.d.ts +9 -3
  62. package/js/ccxt.js +6 -2
  63. package/js/src/abstract/gemini.d.ts +27 -0
  64. package/js/src/abstract/lighter.d.ts +53 -0
  65. package/js/src/abstract/lighter.js +5 -0
  66. package/js/src/ascendex.d.ts +12 -1
  67. package/js/src/ascendex.js +73 -1
  68. package/js/src/base/Exchange.d.ts +29 -14
  69. package/js/src/base/Exchange.js +216 -23
  70. package/js/src/base/functions/generic.js +1 -0
  71. package/js/src/base/functions/io.d.ts +32 -0
  72. package/js/src/base/functions/io.js +131 -0
  73. package/js/src/base/functions.d.ts +1 -0
  74. package/js/src/base/functions.js +1 -0
  75. package/js/src/base/types.d.ts +9 -0
  76. package/js/src/binance.d.ts +27 -1
  77. package/js/src/binance.js +143 -0
  78. package/js/src/bingx.d.ts +113 -108
  79. package/js/src/bingx.js +150 -123
  80. package/js/src/bitmart.js +20 -6
  81. package/js/src/bitmex.d.ts +50 -1
  82. package/js/src/bitmex.js +436 -0
  83. package/js/src/blofin.d.ts +12 -1
  84. package/js/src/blofin.js +86 -1
  85. package/js/src/bybit.d.ts +12 -1
  86. package/js/src/bybit.js +135 -0
  87. package/js/src/coinspot.js +7 -2
  88. package/js/src/delta.d.ts +12 -1
  89. package/js/src/delta.js +367 -0
  90. package/js/src/gate.d.ts +1 -0
  91. package/js/src/gate.js +11 -4
  92. package/js/src/gemini.d.ts +11 -0
  93. package/js/src/gemini.js +76 -1
  94. package/js/src/htx.d.ts +15 -1
  95. package/js/src/htx.js +266 -3
  96. package/js/src/hyperliquid.js +20 -7
  97. package/js/src/independentreserve.js +7 -7
  98. package/js/src/kraken.js +1 -1
  99. package/js/src/krakenfutures.d.ts +1 -1
  100. package/js/src/krakenfutures.js +96 -5
  101. package/js/src/kucoin.d.ts +3 -3
  102. package/js/src/kucoin.js +3 -3
  103. package/js/src/kucoinfutures.d.ts +12 -1
  104. package/js/src/kucoinfutures.js +121 -0
  105. package/js/src/lighter.d.ts +424 -0
  106. package/js/src/lighter.js +2924 -0
  107. package/js/src/mexc.js +9 -2
  108. package/js/src/phemex.d.ts +16 -1
  109. package/js/src/phemex.js +359 -0
  110. package/js/src/poloniex.js +5 -0
  111. package/js/src/pro/binance.js +2 -2
  112. package/js/src/pro/bingx.d.ts +50 -34
  113. package/js/src/pro/bingx.js +249 -36
  114. package/js/src/pro/bitget.d.ts +6 -6
  115. package/js/src/pro/bitget.js +49 -90
  116. package/js/src/pro/bitmart.d.ts +22 -1
  117. package/js/src/pro/bitmart.js +69 -1
  118. package/js/src/pro/blofin.d.ts +12 -1
  119. package/js/src/pro/blofin.js +52 -1
  120. package/js/src/pro/coinbaseinternational.d.ts +2 -2
  121. package/js/src/pro/coinbaseinternational.js +6 -3
  122. package/js/src/pro/defx.js +1 -1
  123. package/js/src/pro/kucoinfutures.js +1 -1
  124. package/js/src/pro/lighter.d.ts +161 -0
  125. package/js/src/pro/lighter.js +780 -0
  126. package/js/src/pro/mexc.d.ts +22 -1
  127. package/js/src/pro/mexc.js +73 -1
  128. package/js/src/pro/okx.d.ts +4 -4
  129. package/js/src/pro/okx.js +7 -4
  130. package/js/src/pro/paradex.d.ts +23 -1
  131. package/js/src/pro/paradex.js +138 -1
  132. package/js/src/pro/woo.d.ts +12 -1
  133. package/js/src/pro/woo.js +43 -0
  134. package/js/src/whitebit.d.ts +2 -1
  135. package/js/src/whitebit.js +118 -16
  136. package/js/src/woo.d.ts +12 -1
  137. package/js/src/woo.js +103 -3
  138. package/package.json +1 -1
package/js/src/bitmart.js CHANGED
@@ -4834,9 +4834,23 @@ export default class bitmart extends Exchange {
4834
4834
  // "timestamp": 1761291544336
4835
4835
  // }
4836
4836
  //
4837
+ // watchFundingRates
4838
+ //
4839
+ // {
4840
+ // "symbol": "BTCUSDT",
4841
+ // "fundingRate": "0.0000561",
4842
+ // "fundingTime": 1770978448000,
4843
+ // "nextFundingRate": "-0.0000195",
4844
+ // "nextFundingTime": 1770998400000,
4845
+ // "funding_upper_limit": "0.0375",
4846
+ // "funding_lower_limit": "-0.0375",
4847
+ // "ts": 1770978448970
4848
+ // }
4849
+ //
4837
4850
  const marketId = this.safeString(contract, 'symbol');
4838
- const timestamp = this.safeInteger(contract, 'timestamp');
4839
- const fundingTimestamp = this.safeInteger(contract, 'funding_time');
4851
+ const timestamp = this.safeInteger2(contract, 'timestamp', 'ts');
4852
+ const fundingTimestamp = this.safeInteger2(contract, 'funding_time', 'fundingTime');
4853
+ const nextFundingTimestamp = this.safeInteger(contract, 'nextFundingTime');
4840
4854
  return {
4841
4855
  'info': contract,
4842
4856
  'symbol': this.safeSymbol(marketId, market),
@@ -4846,12 +4860,12 @@ export default class bitmart extends Exchange {
4846
4860
  'estimatedSettlePrice': undefined,
4847
4861
  'timestamp': timestamp,
4848
4862
  'datetime': this.iso8601(timestamp),
4849
- 'fundingRate': this.safeNumber(contract, 'expected_rate'),
4863
+ 'fundingRate': this.safeNumber2(contract, 'expected_rate', 'fundingRate'),
4850
4864
  'fundingTimestamp': fundingTimestamp,
4851
4865
  'fundingDatetime': this.iso8601(fundingTimestamp),
4852
- 'nextFundingRate': undefined,
4853
- 'nextFundingTimestamp': undefined,
4854
- 'nextFundingDatetime': undefined,
4866
+ 'nextFundingRate': this.safeNumber(contract, 'nextFundingRate'),
4867
+ 'nextFundingTimestamp': nextFundingTimestamp,
4868
+ 'nextFundingDatetime': this.iso8601(nextFundingTimestamp),
4855
4869
  'previousFundingRate': this.safeNumber(contract, 'rate_value'),
4856
4870
  'previousFundingTimestamp': undefined,
4857
4871
  'previousFundingDatetime': undefined,
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bitmex.js';
2
- import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, Liquidation, OrderBook, Balances, Str, Dict, Transaction, Ticker, Tickers, Market, Strings, Currency, Leverage, Leverages, Num, Currencies, int, LedgerEntry, FundingRate, FundingRates, DepositAddress, Position } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, Liquidation, OrderBook, Balances, Str, Dict, Transaction, Ticker, Tickers, Market, Strings, Currency, Leverage, Leverages, Num, Currencies, int, LedgerEntry, FundingRate, FundingRates, DepositAddress, Position, OpenInterests, ADL } from './base/types.js';
3
3
  /**
4
4
  * @class bitmex
5
5
  * @augments Exchange
@@ -368,6 +368,17 @@ export default class bitmex extends Exchange {
368
368
  * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure}
369
369
  */
370
370
  fetchDepositWithdrawFees(codes?: Strings, params?: {}): Promise<any>;
371
+ /**
372
+ * @method
373
+ * @name bitmex#fetchOpenInterests
374
+ * @description Retrieves the open interest for a list of symbols
375
+ * @see https://docs.bitmex.com/api-explorer/get-stats
376
+ * @param {string[]} [symbols] a list of unified CCXT market symbols
377
+ * @param {object} [params] exchange specific parameters
378
+ * @returns {object[]} a list of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
379
+ */
380
+ fetchOpenInterests(symbols?: Strings, params?: {}): Promise<OpenInterests>;
381
+ parseOpenInterest(interest: any, market?: Market): import("./base/types.js").OpenInterest;
371
382
  calculateRateLimiterCost(api: any, method: any, path: any, params: any, config?: {}): any;
372
383
  /**
373
384
  * @method
@@ -384,6 +395,44 @@ export default class bitmex extends Exchange {
384
395
  */
385
396
  fetchLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
386
397
  parseLiquidation(liquidation: any, market?: Market): Liquidation;
398
+ /**
399
+ * @method
400
+ * @name bitmex#fetchPositionsADLRank
401
+ * @description fetches the auto deleveraging rank and risk percentage for a list of symbols
402
+ * @see https://www.bitmex.com/api/explorer/#!/Position/Position_get
403
+ * @param {string[]} [symbols] list of unified market symbols
404
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
405
+ * @returns {object[]} an [auto de leverage structure]{@link https://docs.ccxt.com/?id=auto-de-leverage-structure}
406
+ */
407
+ fetchPositionsADLRank(symbols?: Strings, params?: {}): Promise<ADL[]>;
408
+ parseADLRank(info: Dict, market?: Market): ADL;
409
+ /**
410
+ * @method
411
+ * @name bitmex#fetchSettlementHistory
412
+ * @description fetches historical settlement records
413
+ * @see https://docs.bitmex.com/api-explorer/get-settlements
414
+ * @param {string} symbol unified market symbol of the settlement history
415
+ * @param {int} [since] timestamp in ms
416
+ * @param {int} [limit] number of records
417
+ * @param {object} [params] exchange specific params
418
+ * @param {int} [params.until] timestamp in ms
419
+ *
420
+ * EXCHANGE SPECIFIC PARAMETERS
421
+ * @param {string} [params.filter] generic table filter, send json key/value pairs, such as {"key": "value"}, you can key on individual fields, and do more advanced querying on timestamps, see the timestamp docs for more details, default value = {}
422
+ * @param {string} [params.columns] array of column names to fetch, if omitted, will return all columns, note that this method will always return item keys, even when not specified, so you may receive more columns that you expect
423
+ * @param {int} [params.start] possible values are >= 0 starting point for results, default value = 0
424
+ * @param {boolean} [params.reverse] if true, will sort results newest first, default value = false
425
+ * @returns {object[]} a list of [settlement history objects]{@link https://docs.ccxt.com/?id=settlement-history-structure}
426
+ */
427
+ fetchSettlementHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
428
+ parseSettlements(settlements: any, market?: any, since?: any, limit?: any): any;
429
+ parseSettlement(settlement: any, market?: any): {
430
+ info: any;
431
+ symbol: string;
432
+ price: number;
433
+ timestamp: number;
434
+ datetime: string;
435
+ };
387
436
  handleErrors(code: int, reason: string, url: string, method: string, headers: Dict, body: string, response: any, requestHeaders: any, requestBody: any): any;
388
437
  nonce(): number;
389
438
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
package/js/src/bitmex.js CHANGED
@@ -33,6 +33,9 @@ export default class bitmex extends Exchange {
33
33
  'future': true,
34
34
  'option': false,
35
35
  'addMargin': undefined,
36
+ 'borrowCrossMargin': false,
37
+ 'borrowIsolatedMargin': false,
38
+ 'borrowMargin': false,
36
39
  'cancelAllOrders': true,
37
40
  'cancelAllOrdersAfter': true,
38
41
  'cancelOrder': true,
@@ -45,8 +48,17 @@ export default class bitmex extends Exchange {
45
48
  'createTrailingAmountOrder': true,
46
49
  'createTriggerOrder': true,
47
50
  'editOrder': true,
51
+ 'fetchAllGreeks': false,
48
52
  'fetchBalance': true,
53
+ 'fetchBorrowInterest': false,
54
+ 'fetchBorrowRate': false,
55
+ 'fetchBorrowRateHistories': false,
56
+ 'fetchBorrowRateHistory': false,
57
+ 'fetchBorrowRates': false,
58
+ 'fetchBorrowRatesPerSymbol': false,
49
59
  'fetchClosedOrders': true,
60
+ 'fetchCrossBorrowRate': false,
61
+ 'fetchCrossBorrowRates': false,
50
62
  'fetchCurrencies': true,
51
63
  'fetchDepositAddress': true,
52
64
  'fetchDepositAddresses': false,
@@ -58,7 +70,10 @@ export default class bitmex extends Exchange {
58
70
  'fetchFundingRate': 'emulated',
59
71
  'fetchFundingRateHistory': true,
60
72
  'fetchFundingRates': true,
73
+ 'fetchGreeks': false,
61
74
  'fetchIndexOHLCV': false,
75
+ 'fetchIsolatedBorrowRate': false,
76
+ 'fetchIsolatedBorrowRates': false,
62
77
  'fetchLedger': true,
63
78
  'fetchLeverage': 'emulated',
64
79
  'fetchLeverages': true,
@@ -71,24 +86,34 @@ export default class bitmex extends Exchange {
71
86
  'fetchMyLiquidations': false,
72
87
  'fetchMyTrades': true,
73
88
  'fetchOHLCV': true,
89
+ 'fetchOpenInterest': 'emulated',
90
+ 'fetchOpenInterests': true,
74
91
  'fetchOpenOrders': true,
92
+ 'fetchOption': false,
93
+ 'fetchOptionChain': false,
75
94
  'fetchOrder': true,
76
95
  'fetchOrderBook': true,
77
96
  'fetchOrders': true,
78
97
  'fetchPosition': false,
98
+ 'fetchPositionADLRank': true,
79
99
  'fetchPositionHistory': false,
80
100
  'fetchPositions': true,
101
+ 'fetchPositionsADLRank': true,
81
102
  'fetchPositionsHistory': false,
82
103
  'fetchPositionsRisk': false,
83
104
  'fetchPremiumIndexOHLCV': false,
105
+ 'fetchSettlementHistory': true,
84
106
  'fetchTicker': true,
85
107
  'fetchTickers': true,
86
108
  'fetchTrades': true,
87
109
  'fetchTransactions': 'emulated',
88
110
  'fetchTransfer': false,
89
111
  'fetchTransfers': false,
112
+ 'fetchVolatilityHistory': false,
90
113
  'index': true,
91
114
  'reduceMargin': undefined,
115
+ 'repayCrossMargin': false,
116
+ 'repayIsolatedMargin': false,
92
117
  'sandbox': true,
93
118
  'setLeverage': true,
94
119
  'setMargin': undefined,
@@ -2956,6 +2981,70 @@ export default class bitmex extends Exchange {
2956
2981
  //
2957
2982
  return this.parseDepositWithdrawFees(assets, codes, 'asset');
2958
2983
  }
2984
+ /**
2985
+ * @method
2986
+ * @name bitmex#fetchOpenInterests
2987
+ * @description Retrieves the open interest for a list of symbols
2988
+ * @see https://docs.bitmex.com/api-explorer/get-stats
2989
+ * @param {string[]} [symbols] a list of unified CCXT market symbols
2990
+ * @param {object} [params] exchange specific parameters
2991
+ * @returns {object[]} a list of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
2992
+ */
2993
+ async fetchOpenInterests(symbols = undefined, params = {}) {
2994
+ await this.loadMarkets();
2995
+ const request = {};
2996
+ let response = undefined;
2997
+ response = await this.publicGetStats(this.extend(request, params));
2998
+ //
2999
+ // [
3000
+ // {
3001
+ // currency: 'XBt',
3002
+ // openInterest: '0',
3003
+ // openValue: '323890820079',
3004
+ // rootSymbol: 'Total',
3005
+ // turnover24h: '447088001322',
3006
+ // volume24h: '0'
3007
+ // }
3008
+ // ...
3009
+ // ]
3010
+ //
3011
+ symbols = this.marketSymbols(symbols);
3012
+ return this.parseOpenInterests(response, symbols);
3013
+ }
3014
+ parseOpenInterest(interest, market = undefined) {
3015
+ //
3016
+ // fetchOpenInterest
3017
+ //
3018
+ // {
3019
+ // currency: 'XBt',
3020
+ // openInterest: '0',
3021
+ // openValue: '323890820079',
3022
+ // rootSymbol: 'Total',
3023
+ // turnover24h: '447088001322',
3024
+ // volume24h: '0'
3025
+ // }
3026
+ //
3027
+ const quoteId = this.safeString(interest, 'currency');
3028
+ const baseId = this.safeString(interest, 'rootSymbol');
3029
+ const quoteSymbol = this.safeCurrencyCode(quoteId);
3030
+ const baseSymbol = this.safeCurrencyCode(baseId);
3031
+ let symbol = baseSymbol;
3032
+ if (quoteSymbol !== undefined) {
3033
+ symbol = baseSymbol + '/' + quoteSymbol + ':' + quoteSymbol;
3034
+ }
3035
+ const openInterest = this.safeNumber(interest, 'openInterest');
3036
+ const openValue = this.safeNumber(interest, 'openValue');
3037
+ return this.safeOpenInterest({
3038
+ 'info': interest,
3039
+ 'symbol': symbol,
3040
+ 'baseVolume': openInterest,
3041
+ 'quoteVolume': openValue,
3042
+ 'openInterestAmount': openInterest,
3043
+ 'openInterestValue': openValue,
3044
+ 'timestamp': undefined,
3045
+ 'datetime': undefined,
3046
+ }, market);
3047
+ }
2959
3048
  calculateRateLimiterCost(api, method, path, params, config = {}) {
2960
3049
  const isAuthenticated = this.checkRequiredCredentials(false);
2961
3050
  const cost = this.safeValue(config, 'cost', 1);
@@ -3038,6 +3127,353 @@ export default class bitmex extends Exchange {
3038
3127
  'datetime': undefined,
3039
3128
  });
3040
3129
  }
3130
+ /**
3131
+ * @method
3132
+ * @name bitmex#fetchPositionsADLRank
3133
+ * @description fetches the auto deleveraging rank and risk percentage for a list of symbols
3134
+ * @see https://www.bitmex.com/api/explorer/#!/Position/Position_get
3135
+ * @param {string[]} [symbols] list of unified market symbols
3136
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3137
+ * @returns {object[]} an [auto de leverage structure]{@link https://docs.ccxt.com/?id=auto-de-leverage-structure}
3138
+ */
3139
+ async fetchPositionsADLRank(symbols = undefined, params = {}) {
3140
+ await this.loadMarkets();
3141
+ symbols = this.marketSymbols(symbols, undefined, true, true, true);
3142
+ const response = await this.privateGetPosition(params);
3143
+ //
3144
+ // [
3145
+ // {
3146
+ // "account": 395724,
3147
+ // "symbol": "XBTUSDT",
3148
+ // "strategy": "OneWay",
3149
+ // "currency": "USDt",
3150
+ // "underlying": "XBT",
3151
+ // "quoteCurrency": "USDT",
3152
+ // "commission": 0.0005,
3153
+ // "initMarginReq": 0.01,
3154
+ // "maintMarginReq": 0.005,
3155
+ // "riskLimit": 1000000000000,
3156
+ // "leverage": 100,
3157
+ // "crossMargin": true,
3158
+ // "deleveragePercentile": 1,
3159
+ // "rebalancedPnl": -4319,
3160
+ // "prevRealisedPnl": 0,
3161
+ // "prevUnrealisedPnl": null,
3162
+ // "openingQty": null,
3163
+ // "openOrderBuyQty": 0,
3164
+ // "openOrderBuyCost": 0,
3165
+ // "openOrderBuyPremium": 0,
3166
+ // "openOrderSellQty": 0,
3167
+ // "openOrderSellCost": 0,
3168
+ // "openOrderSellPremium": 0,
3169
+ // "currentQty": 100,
3170
+ // "currentCost": 8639330,
3171
+ // "currentComm": 0,
3172
+ // "realisedCost": 0,
3173
+ // "unrealisedCost": 8639330,
3174
+ // "grossOpenPremium": 0,
3175
+ // "isOpen": true,
3176
+ // "markPrice": 88636.92,
3177
+ // "markValue": 8863692,
3178
+ // "riskValue": 8863692,
3179
+ // "homeNotional": 0.0001,
3180
+ // "foreignNotional": -8.863692,
3181
+ // "posCost": 8639330,
3182
+ // "posCross": 0,
3183
+ // "posComm": 0,
3184
+ // "posLoss": 0,
3185
+ // "posMargin": 44061,
3186
+ // "posMaint": 44061,
3187
+ // "posInit": 0,
3188
+ // "initMargin": 0,
3189
+ // "maintMargin": 44061,
3190
+ // "realisedPnl": 0,
3191
+ // "unrealisedPnl": 224362,
3192
+ // "unrealisedPnlPcnt": 0.026,
3193
+ // "unrealisedRoePcnt": 2.597,
3194
+ // "avgCostPrice": 86393.3,
3195
+ // "avgEntryPrice": 86393.3,
3196
+ // "breakEvenPrice": 86436.5,
3197
+ // "marginCallPrice": null,
3198
+ // "liquidationPrice": 0,
3199
+ // "bankruptPrice": 0,
3200
+ // "timestamp": "2025-12-31T07:55:50.505Z",
3201
+ // "positionReport": {
3202
+ // "account": 395724,
3203
+ // "avgCostPrice": 86393.3,
3204
+ // "avgEntryPrice": 86393.3,
3205
+ // "bankruptPrice": 0,
3206
+ // "breakEvenPrice": 86436.5,
3207
+ // "commission": 0.0005,
3208
+ // "crossMargin": true,
3209
+ // "currency": "USDt",
3210
+ // "currentComm": 0,
3211
+ // "currentCost": 8639330,
3212
+ // "currentQty": 100,
3213
+ // "deleveragePercentile": 1,
3214
+ // "foreignNotional": -8.863692,
3215
+ // "grossOpenPremium": 0,
3216
+ // "homeNotional": 0.0001,
3217
+ // "initMargin": 0,
3218
+ // "initMarginReq": 0.01,
3219
+ // "isOpen": true,
3220
+ // "leverage": 100,
3221
+ // "liquidationPrice": 0,
3222
+ // "maintMargin": 44061,
3223
+ // "maintMarginReq": 0.005,
3224
+ // "markPrice": 88636.92,
3225
+ // "markValue": 8863692,
3226
+ // "openOrderBuyCost": 0,
3227
+ // "openOrderBuyPremium": 0,
3228
+ // "openOrderBuyQty": 0,
3229
+ // "openOrderRealisedPnl": 0,
3230
+ // "openOrderSellCost": 0,
3231
+ // "openOrderSellPremium": 0,
3232
+ // "openOrderSellQty": 0,
3233
+ // "posComm": 0,
3234
+ // "posCost": 8639330,
3235
+ // "posCross": 0,
3236
+ // "posInit": 0,
3237
+ // "posLoss": 0,
3238
+ // "posMaint": 44061,
3239
+ // "posMargin": 44061,
3240
+ // "prevRealisedPnl": 0,
3241
+ // "quoteCurrency": "USDT",
3242
+ // "realisedCost": 0,
3243
+ // "realisedPnl": 0,
3244
+ // "rebalancedPnl": -4319,
3245
+ // "riskLimit": 1000000000000,
3246
+ // "riskValue": 8863692,
3247
+ // "strategy": "OneWay",
3248
+ // "symbol": "XBTUSDT",
3249
+ // "timestamp": "2025-12-31T07:55:50.505Z",
3250
+ // "underlying": "XBT",
3251
+ // "unrealisedCost": 8639330,
3252
+ // "unrealisedPnl": 224362,
3253
+ // "unrealisedPnlPcnt": 0.026,
3254
+ // "unrealisedRoePcnt": 2.597
3255
+ // }
3256
+ // }
3257
+ // ]
3258
+ //
3259
+ return this.parseADLRanks(response, symbols);
3260
+ }
3261
+ parseADLRank(info, market = undefined) {
3262
+ //
3263
+ // fetchPositionsADLRank
3264
+ //
3265
+ // {
3266
+ // "account": 395724,
3267
+ // "symbol": "XBTUSDT",
3268
+ // "strategy": "OneWay",
3269
+ // "currency": "USDt",
3270
+ // "underlying": "XBT",
3271
+ // "quoteCurrency": "USDT",
3272
+ // "commission": 0.0005,
3273
+ // "initMarginReq": 0.01,
3274
+ // "maintMarginReq": 0.005,
3275
+ // "riskLimit": 1000000000000,
3276
+ // "leverage": 100,
3277
+ // "crossMargin": true,
3278
+ // "deleveragePercentile": 1,
3279
+ // "rebalancedPnl": -4319,
3280
+ // "prevRealisedPnl": 0,
3281
+ // "prevUnrealisedPnl": null,
3282
+ // "openingQty": null,
3283
+ // "openOrderBuyQty": 0,
3284
+ // "openOrderBuyCost": 0,
3285
+ // "openOrderBuyPremium": 0,
3286
+ // "openOrderSellQty": 0,
3287
+ // "openOrderSellCost": 0,
3288
+ // "openOrderSellPremium": 0,
3289
+ // "currentQty": 100,
3290
+ // "currentCost": 8639330,
3291
+ // "currentComm": 0,
3292
+ // "realisedCost": 0,
3293
+ // "unrealisedCost": 8639330,
3294
+ // "grossOpenPremium": 0,
3295
+ // "isOpen": true,
3296
+ // "markPrice": 88636.92,
3297
+ // "markValue": 8863692,
3298
+ // "riskValue": 8863692,
3299
+ // "homeNotional": 0.0001,
3300
+ // "foreignNotional": -8.863692,
3301
+ // "posCost": 8639330,
3302
+ // "posCross": 0,
3303
+ // "posComm": 0,
3304
+ // "posLoss": 0,
3305
+ // "posMargin": 44061,
3306
+ // "posMaint": 44061,
3307
+ // "posInit": 0,
3308
+ // "initMargin": 0,
3309
+ // "maintMargin": 44061,
3310
+ // "realisedPnl": 0,
3311
+ // "unrealisedPnl": 224362,
3312
+ // "unrealisedPnlPcnt": 0.026,
3313
+ // "unrealisedRoePcnt": 2.597,
3314
+ // "avgCostPrice": 86393.3,
3315
+ // "avgEntryPrice": 86393.3,
3316
+ // "breakEvenPrice": 86436.5,
3317
+ // "marginCallPrice": null,
3318
+ // "liquidationPrice": 0,
3319
+ // "bankruptPrice": 0,
3320
+ // "timestamp": "2025-12-31T07:55:50.505Z",
3321
+ // "positionReport": {
3322
+ // "account": 395724,
3323
+ // "avgCostPrice": 86393.3,
3324
+ // "avgEntryPrice": 86393.3,
3325
+ // "bankruptPrice": 0,
3326
+ // "breakEvenPrice": 86436.5,
3327
+ // "commission": 0.0005,
3328
+ // "crossMargin": true,
3329
+ // "currency": "USDt",
3330
+ // "currentComm": 0,
3331
+ // "currentCost": 8639330,
3332
+ // "currentQty": 100,
3333
+ // "deleveragePercentile": 1,
3334
+ // "foreignNotional": -8.863692,
3335
+ // "grossOpenPremium": 0,
3336
+ // "homeNotional": 0.0001,
3337
+ // "initMargin": 0,
3338
+ // "initMarginReq": 0.01,
3339
+ // "isOpen": true,
3340
+ // "leverage": 100,
3341
+ // "liquidationPrice": 0,
3342
+ // "maintMargin": 44061,
3343
+ // "maintMarginReq": 0.005,
3344
+ // "markPrice": 88636.92,
3345
+ // "markValue": 8863692,
3346
+ // "openOrderBuyCost": 0,
3347
+ // "openOrderBuyPremium": 0,
3348
+ // "openOrderBuyQty": 0,
3349
+ // "openOrderRealisedPnl": 0,
3350
+ // "openOrderSellCost": 0,
3351
+ // "openOrderSellPremium": 0,
3352
+ // "openOrderSellQty": 0,
3353
+ // "posComm": 0,
3354
+ // "posCost": 8639330,
3355
+ // "posCross": 0,
3356
+ // "posInit": 0,
3357
+ // "posLoss": 0,
3358
+ // "posMaint": 44061,
3359
+ // "posMargin": 44061,
3360
+ // "prevRealisedPnl": 0,
3361
+ // "quoteCurrency": "USDT",
3362
+ // "realisedCost": 0,
3363
+ // "realisedPnl": 0,
3364
+ // "rebalancedPnl": -4319,
3365
+ // "riskLimit": 1000000000000,
3366
+ // "riskValue": 8863692,
3367
+ // "strategy": "OneWay",
3368
+ // "symbol": "XBTUSDT",
3369
+ // "timestamp": "2025-12-31T07:55:50.505Z",
3370
+ // "underlying": "XBT",
3371
+ // "unrealisedCost": 8639330,
3372
+ // "unrealisedPnl": 224362,
3373
+ // "unrealisedPnlPcnt": 0.026,
3374
+ // "unrealisedRoePcnt": 2.597
3375
+ // }
3376
+ // }
3377
+ //
3378
+ const marketId = this.safeString(info, 'symbol');
3379
+ const datetime = this.safeString(info, 'timestamp');
3380
+ return {
3381
+ 'info': info,
3382
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
3383
+ 'rank': this.safeInteger(info, 'deleveragePercentile'),
3384
+ 'rating': undefined,
3385
+ 'percentage': undefined,
3386
+ 'timestamp': this.parse8601(datetime),
3387
+ 'datetime': datetime,
3388
+ };
3389
+ }
3390
+ /**
3391
+ * @method
3392
+ * @name bitmex#fetchSettlementHistory
3393
+ * @description fetches historical settlement records
3394
+ * @see https://docs.bitmex.com/api-explorer/get-settlements
3395
+ * @param {string} symbol unified market symbol of the settlement history
3396
+ * @param {int} [since] timestamp in ms
3397
+ * @param {int} [limit] number of records
3398
+ * @param {object} [params] exchange specific params
3399
+ * @param {int} [params.until] timestamp in ms
3400
+ *
3401
+ * EXCHANGE SPECIFIC PARAMETERS
3402
+ * @param {string} [params.filter] generic table filter, send json key/value pairs, such as {"key": "value"}, you can key on individual fields, and do more advanced querying on timestamps, see the timestamp docs for more details, default value = {}
3403
+ * @param {string} [params.columns] array of column names to fetch, if omitted, will return all columns, note that this method will always return item keys, even when not specified, so you may receive more columns that you expect
3404
+ * @param {int} [params.start] possible values are >= 0 starting point for results, default value = 0
3405
+ * @param {boolean} [params.reverse] if true, will sort results newest first, default value = false
3406
+ * @returns {object[]} a list of [settlement history objects]{@link https://docs.ccxt.com/?id=settlement-history-structure}
3407
+ */
3408
+ async fetchSettlementHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3409
+ await this.loadMarkets();
3410
+ const request = {
3411
+ // symbol string Instrument symbol. Send a bare series (e.g. XBT) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. XBT:quarterly. Timeframes are nearest, daily, weekly, monthly, quarterly, biquarterly, and perpetual. Symbols are case-insensitive.
3412
+ // filter string Generic table filter. Send JSON key/value pairs, such as {"key": "value"}. You can key on individual fields, and do more advanced querying on timestamps. See the Timestamp Docs for more details. Default value: {}
3413
+ // columns string Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect.
3414
+ // count int32 Possible values: >= 1 and <= 500 Number of results to fetch. Must be a positive integer. Default value: 100
3415
+ // start int32 Possible values: >= 0 Starting point for results. Default value: 0
3416
+ // reverse boolean If true, will sort results newest first. Default value: false
3417
+ // startTime string Starting time filter for results.
3418
+ // endTime string Ending time filter for results.
3419
+ };
3420
+ let market = undefined;
3421
+ if (symbol !== undefined) {
3422
+ market = this.market(symbol);
3423
+ request['symbol'] = market['id'];
3424
+ }
3425
+ if (since !== undefined) {
3426
+ request['startTime'] = this.iso8601(since);
3427
+ }
3428
+ if (limit !== undefined) {
3429
+ request['count'] = limit;
3430
+ }
3431
+ const until = this.safeString(params, 'until');
3432
+ if (until !== undefined) {
3433
+ request['endTime'] = this.iso8601(since);
3434
+ params = this.omit(params, 'until');
3435
+ }
3436
+ const response = await this.publicGetSettlement(this.extend(request, params));
3437
+ //
3438
+ // [
3439
+ // {
3440
+ // timestamp: '2025-03-28T12:00:00.000Z',
3441
+ // symbol: 'ETHUSDH25',
3442
+ // settlementType: 'Settlement',
3443
+ // settledPrice: '1897.53'
3444
+ // }
3445
+ // ]
3446
+ //
3447
+ return this.parseSettlements(response, market, since, limit);
3448
+ }
3449
+ parseSettlements(settlements, market = undefined, since = undefined, limit = undefined) {
3450
+ const result = [];
3451
+ for (let i = 0; i < settlements.length; i++) {
3452
+ result.push(this.parseSettlement(settlements[i], market));
3453
+ }
3454
+ const sorted = this.sortBy(result, 'timestamp');
3455
+ const symbol = this.safeString(market, 'symbol');
3456
+ return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
3457
+ }
3458
+ parseSettlement(settlement, market = undefined) {
3459
+ //
3460
+ // {
3461
+ // timestamp: '2025-03-28T12:00:00.000Z',
3462
+ // symbol: 'ETHUSDH25',
3463
+ // settlementType: 'Settlement',
3464
+ // settledPrice: '1897.53'
3465
+ // }
3466
+ //
3467
+ const datetime = this.safeString(settlement, 'timestamp');
3468
+ const marketId = this.safeString(settlement, 'symbol');
3469
+ return {
3470
+ 'info': settlement,
3471
+ 'symbol': this.safeSymbol(marketId, market),
3472
+ 'price': this.safeNumber(settlement, 'settledPrice'),
3473
+ 'timestamp': this.parse8601(datetime),
3474
+ 'datetime': datetime,
3475
+ };
3476
+ }
3041
3477
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3042
3478
  if (response === undefined) {
3043
3479
  return undefined;
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/blofin.js';
2
- import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, Str, Transaction, Ticker, OrderBook, Balances, Tickers, Market, Strings, Currency, Position, TransferEntry, Leverage, Leverages, MarginMode, Num, TradingFeeInterface, Dict, int, LedgerEntry, FundingRate } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, Str, Transaction, Ticker, OrderBook, Balances, Tickers, Market, Strings, Currency, Position, TransferEntry, Leverage, Leverages, MarginMode, Num, TradingFeeInterface, Dict, int, LedgerEntry, FundingRate, ADL } from './base/types.js';
3
3
  /**
4
4
  * @class blofin
5
5
  * @augments Exchange
@@ -429,6 +429,17 @@ export default class blofin extends Exchange {
429
429
  * @returns {object} response from the exchange
430
430
  */
431
431
  setPositionMode(hedged: boolean, symbol?: Str, params?: {}): Promise<any>;
432
+ /**
433
+ * @method
434
+ * @name blofin#fetchPositionsADLRank
435
+ * @description fetches the auto deleveraging rank and risk percentage for a list of symbols
436
+ * @see https://docs.blofin.com/index.html#get-positions
437
+ * @param {string[]} [symbols] a list of unified market symbols
438
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
439
+ * @returns {object[]} an array of [auto de leverage structures]{@link https://docs.ccxt.com/?id=auto-de-leverage-structure}
440
+ */
441
+ fetchPositionsADLRank(symbols?: Strings, params?: {}): Promise<ADL[]>;
442
+ parseADLRank(info: Dict, market?: Market): ADL;
432
443
  handleErrors(httpCode: int, reason: string, url: string, method: string, headers: Dict, body: string, response: any, requestHeaders: any, requestBody: any): any;
433
444
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
434
445
  url: string;