ccxt 4.4.21 → 4.4.22

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 (52) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +4 -4
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/alpaca.js +1 -0
  5. package/dist/cjs/src/base/Exchange.js +21 -0
  6. package/dist/cjs/src/bigone.js +3 -0
  7. package/dist/cjs/src/binance.js +103 -0
  8. package/dist/cjs/src/bitflyer.js +57 -0
  9. package/dist/cjs/src/bitget.js +77 -0
  10. package/dist/cjs/src/bybit.js +78 -0
  11. package/dist/cjs/src/cex.js +1307 -1385
  12. package/dist/cjs/src/cryptocom.js +1 -1
  13. package/dist/cjs/src/gate.js +103 -3
  14. package/dist/cjs/src/htx.js +1 -7
  15. package/dist/cjs/src/hyperliquid.js +10 -8
  16. package/dist/cjs/src/kucoin.js +27 -59
  17. package/dist/cjs/src/okx.js +74 -0
  18. package/js/ccxt.d.ts +3 -3
  19. package/js/ccxt.js +1 -1
  20. package/js/src/abstract/bitflyer.d.ts +1 -0
  21. package/js/src/abstract/bitget.d.ts +3 -0
  22. package/js/src/abstract/cex.d.ts +28 -29
  23. package/js/src/abstract/gate.d.ts +5 -0
  24. package/js/src/abstract/gateio.d.ts +5 -0
  25. package/js/src/abstract/kucoin.d.ts +1 -0
  26. package/js/src/abstract/kucoinfutures.d.ts +1 -0
  27. package/js/src/abstract/okx.d.ts +1 -0
  28. package/js/src/alpaca.js +1 -0
  29. package/js/src/base/Exchange.d.ts +8 -2
  30. package/js/src/base/Exchange.js +21 -0
  31. package/js/src/base/types.d.ts +8 -0
  32. package/js/src/bigone.js +3 -0
  33. package/js/src/binance.d.ts +3 -1
  34. package/js/src/binance.js +103 -0
  35. package/js/src/bitflyer.d.ts +3 -1
  36. package/js/src/bitflyer.js +57 -0
  37. package/js/src/bitget.d.ts +3 -1
  38. package/js/src/bitget.js +77 -0
  39. package/js/src/bybit.d.ts +3 -1
  40. package/js/src/bybit.js +78 -0
  41. package/js/src/cex.d.ts +34 -20
  42. package/js/src/cex.js +1308 -1386
  43. package/js/src/cryptocom.js +1 -1
  44. package/js/src/gate.d.ts +2 -0
  45. package/js/src/gate.js +103 -3
  46. package/js/src/htx.js +1 -7
  47. package/js/src/hyperliquid.js +10 -8
  48. package/js/src/kucoin.d.ts +0 -1
  49. package/js/src/kucoin.js +27 -59
  50. package/js/src/okx.d.ts +3 -1
  51. package/js/src/okx.js +74 -0
  52. package/package.json +1 -1
@@ -1,35 +1,34 @@
1
1
  import { implicitReturnType } from '../base/types.js';
2
2
  import { Exchange as _Exchange } from '../base/Exchange.js';
3
3
  interface Exchange {
4
- publicGetCurrencyProfile(params?: {}): Promise<implicitReturnType>;
5
- publicGetCurrencyLimits(params?: {}): Promise<implicitReturnType>;
6
- publicGetLastPricePair(params?: {}): Promise<implicitReturnType>;
7
- publicGetLastPricesCurrencies(params?: {}): Promise<implicitReturnType>;
8
- publicGetOhlcvHdYyyymmddPair(params?: {}): Promise<implicitReturnType>;
9
- publicGetOrderBookPair(params?: {}): Promise<implicitReturnType>;
10
- publicGetTickerPair(params?: {}): Promise<implicitReturnType>;
11
- publicGetTickersCurrencies(params?: {}): Promise<implicitReturnType>;
12
- publicGetTradeHistoryPair(params?: {}): Promise<implicitReturnType>;
13
- publicPostConvertPair(params?: {}): Promise<implicitReturnType>;
14
- publicPostPriceStatsPair(params?: {}): Promise<implicitReturnType>;
15
- privatePostActiveOrdersStatus(params?: {}): Promise<implicitReturnType>;
16
- privatePostArchivedOrdersPair(params?: {}): Promise<implicitReturnType>;
17
- privatePostBalance(params?: {}): Promise<implicitReturnType>;
18
- privatePostCancelOrder(params?: {}): Promise<implicitReturnType>;
19
- privatePostCancelOrdersPair(params?: {}): Promise<implicitReturnType>;
20
- privatePostCancelReplaceOrderPair(params?: {}): Promise<implicitReturnType>;
21
- privatePostClosePositionPair(params?: {}): Promise<implicitReturnType>;
22
- privatePostGetAddress(params?: {}): Promise<implicitReturnType>;
23
- privatePostGetCryptoAddress(params?: {}): Promise<implicitReturnType>;
24
- privatePostGetMyfee(params?: {}): Promise<implicitReturnType>;
25
- privatePostGetOrder(params?: {}): Promise<implicitReturnType>;
26
- privatePostGetOrderTx(params?: {}): Promise<implicitReturnType>;
27
- privatePostOpenOrdersPair(params?: {}): Promise<implicitReturnType>;
28
- privatePostOpenOrders(params?: {}): Promise<implicitReturnType>;
29
- privatePostOpenPositionPair(params?: {}): Promise<implicitReturnType>;
30
- privatePostOpenPositionsPair(params?: {}): Promise<implicitReturnType>;
31
- privatePostPlaceOrderPair(params?: {}): Promise<implicitReturnType>;
32
- privatePostRawTxHistory(params?: {}): Promise<implicitReturnType>;
4
+ publicPostGetServerTime(params?: {}): Promise<implicitReturnType>;
5
+ publicPostGetPairsInfo(params?: {}): Promise<implicitReturnType>;
6
+ publicPostGetCurrenciesInfo(params?: {}): Promise<implicitReturnType>;
7
+ publicPostGetProcessingInfo(params?: {}): Promise<implicitReturnType>;
8
+ publicPostGetTicker(params?: {}): Promise<implicitReturnType>;
9
+ publicPostGetTradeHistory(params?: {}): Promise<implicitReturnType>;
10
+ publicPostGetOrderBook(params?: {}): Promise<implicitReturnType>;
11
+ publicPostGetCandles(params?: {}): Promise<implicitReturnType>;
12
+ privatePostGetMyCurrentFee(params?: {}): Promise<implicitReturnType>;
13
+ privatePostGetFeeStrategy(params?: {}): Promise<implicitReturnType>;
14
+ privatePostGetMyVolume(params?: {}): Promise<implicitReturnType>;
15
+ privatePostDoCreateAccount(params?: {}): Promise<implicitReturnType>;
16
+ privatePostGetMyAccountStatusV3(params?: {}): Promise<implicitReturnType>;
17
+ privatePostGetMyWalletBalance(params?: {}): Promise<implicitReturnType>;
18
+ privatePostGetMyOrders(params?: {}): Promise<implicitReturnType>;
19
+ privatePostDoMyNewOrder(params?: {}): Promise<implicitReturnType>;
20
+ privatePostDoCancelMyOrder(params?: {}): Promise<implicitReturnType>;
21
+ privatePostDoCancelAllOrders(params?: {}): Promise<implicitReturnType>;
22
+ privatePostGetOrderBook(params?: {}): Promise<implicitReturnType>;
23
+ privatePostGetCandles(params?: {}): Promise<implicitReturnType>;
24
+ privatePostGetTradeHistory(params?: {}): Promise<implicitReturnType>;
25
+ privatePostGetMyTransactionHistory(params?: {}): Promise<implicitReturnType>;
26
+ privatePostGetMyFundingHistory(params?: {}): Promise<implicitReturnType>;
27
+ privatePostDoMyInternalTransfer(params?: {}): Promise<implicitReturnType>;
28
+ privatePostGetProcessingInfo(params?: {}): Promise<implicitReturnType>;
29
+ privatePostGetDepositAddress(params?: {}): Promise<implicitReturnType>;
30
+ privatePostDoDepositFundsFromWallet(params?: {}): Promise<implicitReturnType>;
31
+ privatePostDoWithdrawalFundsToWallet(params?: {}): Promise<implicitReturnType>;
33
32
  }
34
33
  declare abstract class Exchange extends _Exchange {
35
34
  }
@@ -91,8 +91,13 @@ interface Exchange {
91
91
  privateUnifiedGetInterestRecords(params?: {}): Promise<implicitReturnType>;
92
92
  privateUnifiedGetEstimateRate(params?: {}): Promise<implicitReturnType>;
93
93
  privateUnifiedGetCurrencyDiscountTiers(params?: {}): Promise<implicitReturnType>;
94
+ privateUnifiedGetRiskUnits(params?: {}): Promise<implicitReturnType>;
95
+ privateUnifiedGetUnifiedMode(params?: {}): Promise<implicitReturnType>;
96
+ privateUnifiedGetLoanMarginTiers(params?: {}): Promise<implicitReturnType>;
94
97
  privateUnifiedPostAccountMode(params?: {}): Promise<implicitReturnType>;
95
98
  privateUnifiedPostLoans(params?: {}): Promise<implicitReturnType>;
99
+ privateUnifiedPostPortfolioCalculator(params?: {}): Promise<implicitReturnType>;
100
+ privateUnifiedPutUnifiedMode(params?: {}): Promise<implicitReturnType>;
96
101
  privateSpotGetFee(params?: {}): Promise<implicitReturnType>;
97
102
  privateSpotGetBatchFee(params?: {}): Promise<implicitReturnType>;
98
103
  privateSpotGetAccounts(params?: {}): Promise<implicitReturnType>;
@@ -91,8 +91,13 @@ interface gate {
91
91
  privateUnifiedGetInterestRecords(params?: {}): Promise<implicitReturnType>;
92
92
  privateUnifiedGetEstimateRate(params?: {}): Promise<implicitReturnType>;
93
93
  privateUnifiedGetCurrencyDiscountTiers(params?: {}): Promise<implicitReturnType>;
94
+ privateUnifiedGetRiskUnits(params?: {}): Promise<implicitReturnType>;
95
+ privateUnifiedGetUnifiedMode(params?: {}): Promise<implicitReturnType>;
96
+ privateUnifiedGetLoanMarginTiers(params?: {}): Promise<implicitReturnType>;
94
97
  privateUnifiedPostAccountMode(params?: {}): Promise<implicitReturnType>;
95
98
  privateUnifiedPostLoans(params?: {}): Promise<implicitReturnType>;
99
+ privateUnifiedPostPortfolioCalculator(params?: {}): Promise<implicitReturnType>;
100
+ privateUnifiedPutUnifiedMode(params?: {}): Promise<implicitReturnType>;
96
101
  privateSpotGetFee(params?: {}): Promise<implicitReturnType>;
97
102
  privateSpotGetBatchFee(params?: {}): Promise<implicitReturnType>;
98
103
  privateSpotGetAccounts(params?: {}): Promise<implicitReturnType>;
@@ -123,6 +123,7 @@ interface Exchange {
123
123
  privatePostLendPurchaseUpdate(params?: {}): Promise<implicitReturnType>;
124
124
  privatePostBulletPrivate(params?: {}): Promise<implicitReturnType>;
125
125
  privatePostPositionUpdateUserLeverage(params?: {}): Promise<implicitReturnType>;
126
+ privatePostDepositAddressCreate(params?: {}): Promise<implicitReturnType>;
126
127
  privateDeleteSubApiKey(params?: {}): Promise<implicitReturnType>;
127
128
  privateDeleteWithdrawalsWithdrawalId(params?: {}): Promise<implicitReturnType>;
128
129
  privateDeleteHfOrdersOrderId(params?: {}): Promise<implicitReturnType>;
@@ -123,6 +123,7 @@ interface kucoin {
123
123
  privatePostLendPurchaseUpdate(params?: {}): Promise<implicitReturnType>;
124
124
  privatePostBulletPrivate(params?: {}): Promise<implicitReturnType>;
125
125
  privatePostPositionUpdateUserLeverage(params?: {}): Promise<implicitReturnType>;
126
+ privatePostDepositAddressCreate(params?: {}): Promise<implicitReturnType>;
126
127
  privateDeleteSubApiKey(params?: {}): Promise<implicitReturnType>;
127
128
  privateDeleteWithdrawalsWithdrawalId(params?: {}): Promise<implicitReturnType>;
128
129
  privateDeleteHfOrdersOrderId(params?: {}): Promise<implicitReturnType>;
@@ -47,6 +47,7 @@ interface Exchange {
47
47
  publicGetRubikStatTakerVolume(params?: {}): Promise<implicitReturnType>;
48
48
  publicGetRubikStatMarginLoanRatio(params?: {}): Promise<implicitReturnType>;
49
49
  publicGetRubikStatContractsLongShortAccountRatio(params?: {}): Promise<implicitReturnType>;
50
+ publicGetRubikStatContractsLongShortAccountRatioContract(params?: {}): Promise<implicitReturnType>;
50
51
  publicGetRubikStatContractsOpenInterestVolume(params?: {}): Promise<implicitReturnType>;
51
52
  publicGetRubikStatOptionOpenInterestVolume(params?: {}): Promise<implicitReturnType>;
52
53
  publicGetRubikStatOptionOpenInterestVolumeRatio(params?: {}): Promise<implicitReturnType>;
package/js/src/alpaca.js CHANGED
@@ -63,6 +63,7 @@ export default class alpaca extends Exchange {
63
63
  'fetchDepositsWithdrawals': false,
64
64
  'fetchFundingHistory': false,
65
65
  'fetchFundingRate': false,
66
+ 'fetchFundingRateHistory': false,
66
67
  'fetchFundingRates': false,
67
68
  'fetchL1OrderBook': true,
68
69
  'fetchL2OrderBook': false,
@@ -3,8 +3,8 @@ import { // eslint-disable-line object-curly-newline
3
3
  ExchangeError, AuthenticationError, DDoSProtection, RequestTimeout, ExchangeNotAvailable, RateLimitExceeded } from "./errors.js";
4
4
  import WsClient from './ws/WsClient.js';
5
5
  import { OrderBook as WsOrderBook, IndexedOrderBook, CountedOrderBook } from './ws/OrderBook.js';
6
- import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CancellationRequest, IsolatedBorrowRate, IsolatedBorrowRates, CrossBorrowRates, CrossBorrowRate, Dict, FundingRates, LeverageTiers, Bool, int, DepositAddress } from './types.js';
7
- export type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, Bool, OrderType, OrderSide, Position, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, CrossBorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, Conversion, DepositAddress } from './types.js';
6
+ import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CancellationRequest, IsolatedBorrowRate, IsolatedBorrowRates, CrossBorrowRates, CrossBorrowRate, Dict, FundingRates, LeverageTiers, Bool, int, DepositAddress, LongShortRatio } from './types.js';
7
+ export type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, Bool, OrderType, OrderSide, Position, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, CrossBorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, Conversion, DepositAddress, LongShortRatio } from './types.js';
8
8
  import { ArrayCache, ArrayCacheByTimestamp } from './ws/Cache.js';
9
9
  import { OrderBook as Ob } from './ws/OrderBook.js';
10
10
  import Client from './ws/Client.js';
@@ -514,6 +514,8 @@ export default class Exchange {
514
514
  fetchLeverages: any;
515
515
  fetchLeverageTiers: any;
516
516
  fetchLiquidations: any;
517
+ fetchLongShortRatio: any;
518
+ fetchLongShortRatioHistory: any;
517
519
  fetchMarginMode: any;
518
520
  fetchMarginModes: any;
519
521
  fetchMarketLeverageTiers: any;
@@ -792,6 +794,8 @@ export default class Exchange {
792
794
  addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
793
795
  reduceMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
794
796
  setMargin(symbol: string, amount: number, params?: {}): Promise<{}>;
797
+ fetchLongShortRatio(symbol: string, timeframe?: Str, params?: {}): Promise<LongShortRatio>;
798
+ fetchLongShortRatioHistory(symbol?: Str, timeframe?: Str, since?: Int, limit?: Int, params?: {}): Promise<LongShortRatio[]>;
795
799
  fetchMarginAdjustmentHistory(symbol?: Str, type?: Str, since?: Num, limit?: Num, params?: {}): Promise<MarginModification[]>;
796
800
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<{}>;
797
801
  fetchDepositAddressesByNetwork(code: string, params?: {}): Promise<DepositAddress[]>;
@@ -1101,6 +1105,8 @@ export default class Exchange {
1101
1105
  safeSymbol(marketId: Str, market?: Market, delimiter?: Str, marketType?: Str): string;
1102
1106
  parseFundingRate(contract: string, market?: Market): FundingRate;
1103
1107
  parseFundingRates(response: any, market?: Market): FundingRates;
1108
+ parseLongShortRatio(info: Dict, market?: Market): LongShortRatio;
1109
+ parseLongShortRatioHistory(response: any, market?: any, since?: Int, limit?: Int): LongShortRatio[];
1104
1110
  handleTriggerAndParams(params: any): any[];
1105
1111
  isTriggerOrder(params: any): any[];
1106
1112
  isPostOnly(isMarketOrder: boolean, exchangeSpecificParam: any, params?: {}): boolean;
@@ -1402,6 +1402,8 @@ export default class Exchange {
1402
1402
  'fetchLeverages': undefined,
1403
1403
  'fetchLeverageTiers': undefined,
1404
1404
  'fetchLiquidations': undefined,
1405
+ 'fetchLongShortRatio': undefined,
1406
+ 'fetchLongShortRatioHistory': undefined,
1405
1407
  'fetchMarginMode': undefined,
1406
1408
  'fetchMarginModes': undefined,
1407
1409
  'fetchMarketLeverageTiers': undefined,
@@ -2195,6 +2197,12 @@ export default class Exchange {
2195
2197
  async setMargin(symbol, amount, params = {}) {
2196
2198
  throw new NotSupported(this.id + ' setMargin() is not supported yet');
2197
2199
  }
2200
+ async fetchLongShortRatio(symbol, timeframe = undefined, params = {}) {
2201
+ throw new NotSupported(this.id + ' fetchLongShortRatio() is not supported yet');
2202
+ }
2203
+ async fetchLongShortRatioHistory(symbol = undefined, timeframe = undefined, since = undefined, limit = undefined, params = {}) {
2204
+ throw new NotSupported(this.id + ' fetchLongShortRatioHistory() is not supported yet');
2205
+ }
2198
2206
  async fetchMarginAdjustmentHistory(symbol = undefined, type = undefined, since = undefined, limit = undefined, params = {}) {
2199
2207
  /**
2200
2208
  * @method
@@ -5555,6 +5563,19 @@ export default class Exchange {
5555
5563
  }
5556
5564
  return result;
5557
5565
  }
5566
+ parseLongShortRatio(info, market = undefined) {
5567
+ throw new NotSupported(this.id + ' parseLongShortRatio() is not supported yet');
5568
+ }
5569
+ parseLongShortRatioHistory(response, market = undefined, since = undefined, limit = undefined) {
5570
+ const rates = [];
5571
+ for (let i = 0; i < response.length; i++) {
5572
+ const entry = response[i];
5573
+ rates.push(this.parseLongShortRatio(entry, market));
5574
+ }
5575
+ const sorted = this.sortBy(rates, 'timestamp');
5576
+ const symbol = (market === undefined) ? undefined : market['symbol'];
5577
+ return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
5578
+ }
5558
5579
  handleTriggerAndParams(params) {
5559
5580
  const isTrigger = this.safeBool2(params, 'trigger', 'stop');
5560
5581
  if (isTrigger) {
@@ -505,6 +505,14 @@ export interface Leverage {
505
505
  longLeverage: number;
506
506
  shortLeverage: number;
507
507
  }
508
+ export interface LongShortRatio {
509
+ info: any;
510
+ symbol: string;
511
+ timestamp?: number;
512
+ datetime?: string;
513
+ timeframe?: string;
514
+ longShortRatio: number;
515
+ }
508
516
  export interface MarginModification {
509
517
  'info': any;
510
518
  'symbol': string;
package/js/src/bigone.js CHANGED
@@ -48,7 +48,10 @@ export default class bigone extends Exchange {
48
48
  'fetchDepositAddresses': false,
49
49
  'fetchDepositAddressesByNetwork': false,
50
50
  'fetchDeposits': true,
51
+ 'fetchFundingHistory': false,
51
52
  'fetchFundingRate': false,
53
+ 'fetchFundingRateHistory': false,
54
+ 'fetchFundingRates': false,
52
55
  'fetchMarkets': true,
53
56
  'fetchMyTrades': true,
54
57
  'fetchOHLCV': true,
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/binance.js';
2
- import type { TransferEntry, Int, OrderSide, Balances, OrderType, Trade, OHLCV, Order, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, Str, Transaction, Ticker, OrderBook, Tickers, Market, Greeks, Strings, Currency, MarketInterface, MarginMode, MarginModes, Leverage, Leverages, Num, Option, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CrossBorrowRate, IsolatedBorrowRates, IsolatedBorrowRate, Dict, LeverageTier, LeverageTiers, int, LedgerEntry, FundingRate, FundingRates, DepositAddress } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, Balances, OrderType, Trade, OHLCV, Order, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, Str, Transaction, Ticker, OrderBook, Tickers, Market, Greeks, Strings, Currency, MarketInterface, MarginMode, MarginModes, Leverage, Leverages, Num, Option, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CrossBorrowRate, IsolatedBorrowRates, IsolatedBorrowRate, Dict, LeverageTier, LeverageTiers, int, LedgerEntry, FundingRate, FundingRates, DepositAddress, LongShortRatio } from './base/types.js';
3
3
  /**
4
4
  * @class binance
5
5
  * @augments Exchange
@@ -329,4 +329,6 @@ export default class binance extends Exchange {
329
329
  fetchConvertTradeHistory(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Conversion[]>;
330
330
  parseConversion(conversion: Dict, fromCurrency?: Currency, toCurrency?: Currency): Conversion;
331
331
  fetchFundingIntervals(symbols?: Strings, params?: {}): Promise<FundingRates>;
332
+ fetchLongShortRatioHistory(symbol?: Str, timeframe?: Str, since?: Int, limit?: Int, params?: {}): Promise<LongShortRatio[]>;
333
+ parseLongShortRatio(info: Dict, market?: Market): LongShortRatio;
332
334
  }
package/js/src/binance.js CHANGED
@@ -108,6 +108,8 @@ export default class binance extends Exchange {
108
108
  'fetchLeverages': true,
109
109
  'fetchLeverageTiers': true,
110
110
  'fetchLiquidations': false,
111
+ 'fetchLongShortRatio': false,
112
+ 'fetchLongShortRatioHistory': true,
111
113
  'fetchMarginAdjustmentHistory': true,
112
114
  'fetchMarginMode': 'emulated',
113
115
  'fetchMarginModes': true,
@@ -13821,4 +13823,105 @@ export default class binance extends Exchange {
13821
13823
  const result = this.parseFundingRates(response, market);
13822
13824
  return this.filterByArray(result, 'symbol', symbols);
13823
13825
  }
13826
+ async fetchLongShortRatioHistory(symbol = undefined, timeframe = undefined, since = undefined, limit = undefined, params = {}) {
13827
+ /**
13828
+ * @method
13829
+ * @name binance#fetchLongShortRatioHistory
13830
+ * @description fetches the long short ratio history for a unified market symbol
13831
+ * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio
13832
+ * @see https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Long-Short-Ratio
13833
+ * @param {string} symbol unified symbol of the market to fetch the long short ratio for
13834
+ * @param {string} [timeframe] the period for the ratio, default is 24 hours
13835
+ * @param {int} [since] the earliest time in ms to fetch ratios for
13836
+ * @param {int} [limit] the maximum number of long short ratio structures to retrieve
13837
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
13838
+ * @param {int} [params.until] timestamp in ms of the latest ratio to fetch
13839
+ * @returns {object[]} an array of [long short ratio structures]{@link https://docs.ccxt.com/#/?id=long-short-ratio-structure}
13840
+ */
13841
+ await this.loadMarkets();
13842
+ const market = this.market(symbol);
13843
+ if (timeframe === undefined) {
13844
+ timeframe = '1d';
13845
+ }
13846
+ let request = {
13847
+ 'period': timeframe,
13848
+ };
13849
+ [request, params] = this.handleUntilOption('endTime', request, params);
13850
+ if (since !== undefined) {
13851
+ request['startTime'] = since;
13852
+ }
13853
+ if (limit !== undefined) {
13854
+ request['limit'] = limit;
13855
+ }
13856
+ let subType = undefined;
13857
+ [subType, params] = this.handleSubTypeAndParams('fetchLongShortRatioHistory', market, params);
13858
+ let response = undefined;
13859
+ if (subType === 'linear') {
13860
+ request['symbol'] = market['id'];
13861
+ response = await this.fapiDataGetGlobalLongShortAccountRatio(this.extend(request, params));
13862
+ //
13863
+ // [
13864
+ // {
13865
+ // "symbol": "BTCUSDT",
13866
+ // "longAccount": "0.4558",
13867
+ // "longShortRatio": "0.8376",
13868
+ // "shortAccount": "0.5442",
13869
+ // "timestamp": 1726790400000
13870
+ // },
13871
+ // ]
13872
+ //
13873
+ }
13874
+ else if (subType === 'inverse') {
13875
+ request['pair'] = market['info']['pair'];
13876
+ response = await this.dapiDataGetGlobalLongShortAccountRatio(this.extend(request, params));
13877
+ //
13878
+ // [
13879
+ // {
13880
+ // "longAccount": "0.7262",
13881
+ // "longShortRatio": "2.6523",
13882
+ // "shortAccount": "0.2738",
13883
+ // "pair": "BTCUSD",
13884
+ // "timestamp": 1726790400000
13885
+ // },
13886
+ // ]
13887
+ //
13888
+ }
13889
+ else {
13890
+ throw new BadRequest(this.id + ' fetchLongShortRatioHistory() supports linear and inverse subTypes only');
13891
+ }
13892
+ return this.parseLongShortRatioHistory(response, market);
13893
+ }
13894
+ parseLongShortRatio(info, market = undefined) {
13895
+ //
13896
+ // linear
13897
+ //
13898
+ // {
13899
+ // "symbol": "BTCUSDT",
13900
+ // "longAccount": "0.4558",
13901
+ // "longShortRatio": "0.8376",
13902
+ // "shortAccount": "0.5442",
13903
+ // "timestamp": 1726790400000
13904
+ // }
13905
+ //
13906
+ // inverse
13907
+ //
13908
+ // {
13909
+ // "longAccount": "0.7262",
13910
+ // "longShortRatio": "2.6523",
13911
+ // "shortAccount": "0.2738",
13912
+ // "pair": "BTCUSD",
13913
+ // "timestamp": 1726790400000
13914
+ // }
13915
+ //
13916
+ const marketId = this.safeString(info, 'symbol');
13917
+ const timestamp = this.safeIntegerOmitZero(info, 'timestamp');
13918
+ return {
13919
+ 'info': info,
13920
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
13921
+ 'timestamp': timestamp,
13922
+ 'datetime': this.iso8601(timestamp),
13923
+ 'timeframe': undefined,
13924
+ 'longShortRatio': this.safeNumber(info, 'longShortRatio'),
13925
+ };
13926
+ }
13824
13927
  }
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bitflyer.js';
2
- import type { Balances, Currency, Dict, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Trade, TradingFeeInterface, Transaction, int } from './base/types.js';
2
+ import type { Balances, Currency, Dict, FundingRate, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Trade, TradingFeeInterface, Transaction, int } from './base/types.js';
3
3
  /**
4
4
  * @class bitflyer
5
5
  * @augments Exchange
@@ -33,6 +33,8 @@ export default class bitflyer extends Exchange {
33
33
  parseDepositStatus(status: any): string;
34
34
  parseWithdrawalStatus(status: any): string;
35
35
  parseTransaction(transaction: Dict, currency?: Currency): Transaction;
36
+ fetchFundingRate(symbol: string, params?: {}): Promise<FundingRate>;
37
+ parseFundingRate(contract: any, market?: Market): FundingRate;
36
38
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
37
39
  url: string;
38
40
  method: string;
@@ -37,6 +37,8 @@ export default class bitflyer extends Exchange {
37
37
  'fetchBalance': true,
38
38
  'fetchClosedOrders': 'emulated',
39
39
  'fetchDeposits': true,
40
+ 'fetchFundingRate': true,
41
+ 'fetchFundingRateHistory': false,
40
42
  'fetchMarginMode': false,
41
43
  'fetchMarkets': true,
42
44
  'fetchMyTrades': true,
@@ -76,6 +78,7 @@ export default class bitflyer extends Exchange {
76
78
  'gethealth',
77
79
  'getboardstate',
78
80
  'getchats',
81
+ 'getfundingrate',
79
82
  ],
80
83
  },
81
84
  'private': {
@@ -1026,6 +1029,60 @@ export default class bitflyer extends Exchange {
1026
1029
  'fee': fee,
1027
1030
  };
1028
1031
  }
1032
+ async fetchFundingRate(symbol, params = {}) {
1033
+ /**
1034
+ * @method
1035
+ * @name bitflyer#fetchFundingRate
1036
+ * @description fetch the current funding rate
1037
+ * @see https://lightning.bitflyer.com/docs#funding-rate
1038
+ * @param {string} symbol unified market symbol
1039
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1040
+ * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
1041
+ */
1042
+ await this.loadMarkets();
1043
+ const market = this.market(symbol);
1044
+ const request = {
1045
+ 'product_code': market['id'],
1046
+ };
1047
+ const response = await this.publicGetGetfundingrate(this.extend(request, params));
1048
+ //
1049
+ // {
1050
+ // "current_funding_rate": -0.003750000000
1051
+ // "next_funding_rate_settledate": "2024-04-15T13:00:00"
1052
+ // }
1053
+ //
1054
+ return this.parseFundingRate(response, market);
1055
+ }
1056
+ parseFundingRate(contract, market = undefined) {
1057
+ //
1058
+ // {
1059
+ // "current_funding_rate": -0.003750000000
1060
+ // "next_funding_rate_settledate": "2024-04-15T13:00:00"
1061
+ // }
1062
+ //
1063
+ const nextFundingDatetime = this.safeString(contract, 'next_funding_rate_settledate');
1064
+ const nextFundingTimestamp = this.parse8601(nextFundingDatetime);
1065
+ return {
1066
+ 'info': contract,
1067
+ 'symbol': this.safeString(market, 'symbol'),
1068
+ 'markPrice': undefined,
1069
+ 'indexPrice': undefined,
1070
+ 'interestRate': undefined,
1071
+ 'estimatedSettlePrice': undefined,
1072
+ 'timestamp': undefined,
1073
+ 'datetime': undefined,
1074
+ 'fundingRate': undefined,
1075
+ 'fundingTimestamp': undefined,
1076
+ 'fundingDatetime': undefined,
1077
+ 'nextFundingRate': this.safeNumber(contract, 'current_funding_rate'),
1078
+ 'nextFundingTimestamp': nextFundingTimestamp,
1079
+ 'nextFundingDatetime': this.iso8601(nextFundingTimestamp),
1080
+ 'previousFundingRate': undefined,
1081
+ 'previousFundingTimestamp': undefined,
1082
+ 'previousFundingDatetime': undefined,
1083
+ 'interval': undefined,
1084
+ };
1085
+ }
1029
1086
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1030
1087
  let request = '/' + this.version + '/';
1031
1088
  if (api === 'private') {
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bitget.js';
2
- import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Liquidation, TransferEntry, Leverage, MarginMode, Num, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CrossBorrowRate, IsolatedBorrowRate, Dict, LeverageTier, int, LedgerEntry, FundingRate, DepositAddress } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Market, Strings, Currency, Position, Liquidation, TransferEntry, Leverage, MarginMode, Num, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CrossBorrowRate, IsolatedBorrowRate, Dict, LeverageTier, int, LedgerEntry, FundingRate, DepositAddress, LongShortRatio } from './base/types.js';
3
3
  /**
4
4
  * @class bitget
5
5
  * @augments Exchange
@@ -177,6 +177,8 @@ export default class bitget extends Exchange {
177
177
  parseConversion(conversion: Dict, fromCurrency?: Currency, toCurrency?: Currency): Conversion;
178
178
  fetchConvertCurrencies(params?: {}): Promise<Currencies>;
179
179
  fetchFundingInterval(symbol: string, params?: {}): Promise<FundingRate>;
180
+ fetchLongShortRatioHistory(symbol?: Str, timeframe?: Str, since?: Int, limit?: Int, params?: {}): Promise<LongShortRatio[]>;
181
+ parseLongShortRatio(info: Dict, market?: Market): LongShortRatio;
180
182
  handleErrors(code: int, reason: string, url: string, method: string, headers: Dict, body: string, response: any, requestHeaders: any, requestBody: any): any;
181
183
  nonce(): number;
182
184
  sign(path: any, api?: any[], method?: string, params?: {}, headers?: any, body?: any): {
package/js/src/bitget.js CHANGED
@@ -95,6 +95,8 @@ export default class bitget extends Exchange {
95
95
  'fetchLeverage': true,
96
96
  'fetchLeverageTiers': false,
97
97
  'fetchLiquidations': false,
98
+ 'fetchLongShortRatio': false,
99
+ 'fetchLongShortRatioHistory': true,
98
100
  'fetchMarginAdjustmentHistory': false,
99
101
  'fetchMarginMode': true,
100
102
  'fetchMarketLeverageTiers': true,
@@ -270,6 +272,7 @@ export default class bitget extends Exchange {
270
272
  'v2/mix/market/current-fund-rate': 1,
271
273
  'v2/mix/market/contracts': 1,
272
274
  'v2/mix/market/query-position-lever': 2,
275
+ 'v2/mix/market/account-long-short': 20,
273
276
  },
274
277
  },
275
278
  'margin': {
@@ -280,6 +283,7 @@ export default class bitget extends Exchange {
280
283
  'margin/v1/isolated/public/tierData': 2,
281
284
  'margin/v1/public/currencies': 1,
282
285
  'v2/margin/currencies': 2,
286
+ 'v2/margin/market/long-short-ratio': 20,
283
287
  },
284
288
  },
285
289
  'earn': {
@@ -442,6 +446,7 @@ export default class bitget extends Exchange {
442
446
  'v2/mix/order/orders-history': 2,
443
447
  'v2/mix/order/orders-plan-pending': 2,
444
448
  'v2/mix/order/orders-plan-history': 2,
449
+ 'v2/mix/market/position-long-short': 20,
445
450
  },
446
451
  'post': {
447
452
  'mix/v1/account/sub-account-contract-assets': 200,
@@ -8903,6 +8908,78 @@ export default class bitget extends Exchange {
8903
8908
  const first = this.safeDict(data, 0, {});
8904
8909
  return this.parseFundingRate(first, market);
8905
8910
  }
8911
+ async fetchLongShortRatioHistory(symbol = undefined, timeframe = undefined, since = undefined, limit = undefined, params = {}) {
8912
+ /**
8913
+ * @method
8914
+ * @name bitget#fetchLongShortRatioHistory
8915
+ * @description fetches the long short ratio history for a unified market symbol
8916
+ * @see https://www.bitget.com/api-doc/common/apidata/Margin-Ls-Ratio
8917
+ * @see https://www.bitget.com/api-doc/common/apidata/Account-Long-Short
8918
+ * @param {string} symbol unified symbol of the market to fetch the long short ratio for
8919
+ * @param {string} [timeframe] the period for the ratio
8920
+ * @param {int} [since] the earliest time in ms to fetch ratios for
8921
+ * @param {int} [limit] the maximum number of long short ratio structures to retrieve
8922
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
8923
+ * @returns {object[]} an array of [long short ratio structures]{@link https://docs.ccxt.com/#/?id=long-short-ratio-structure}
8924
+ */
8925
+ await this.loadMarkets();
8926
+ const market = this.market(symbol);
8927
+ const request = {
8928
+ 'symbol': market['id'],
8929
+ };
8930
+ if (timeframe !== undefined) {
8931
+ request['period'] = timeframe;
8932
+ }
8933
+ let response = undefined;
8934
+ if (market['swap'] || market['future']) {
8935
+ response = await this.publicMixGetV2MixMarketAccountLongShort(this.extend(request, params));
8936
+ //
8937
+ // {
8938
+ // "code": "00000",
8939
+ // "msg": "success",
8940
+ // "requestTime": 1729321233281,
8941
+ // "data": [
8942
+ // {
8943
+ // "longAccountRatio": "0.58",
8944
+ // "shortAccountRatio": "0.42",
8945
+ // "longShortAccountRatio": "0.0138",
8946
+ // "ts": "1729312200000"
8947
+ // },
8948
+ // ]
8949
+ // }
8950
+ //
8951
+ }
8952
+ else {
8953
+ response = await this.publicMarginGetV2MarginMarketLongShortRatio(this.extend(request, params));
8954
+ //
8955
+ // {
8956
+ // "code": "00000",
8957
+ // "msg": "success",
8958
+ // "requestTime": 1729306974712,
8959
+ // "data": [
8960
+ // {
8961
+ // "longShortRatio": "40.66",
8962
+ // "ts": "1729306800000"
8963
+ // },
8964
+ // ]
8965
+ // }
8966
+ //
8967
+ }
8968
+ const data = this.safeList(response, 'data', []);
8969
+ return this.parseLongShortRatioHistory(data, market);
8970
+ }
8971
+ parseLongShortRatio(info, market = undefined) {
8972
+ const marketId = this.safeString(info, 'symbol');
8973
+ const timestamp = this.safeIntegerOmitZero(info, 'ts');
8974
+ return {
8975
+ 'info': info,
8976
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
8977
+ 'timestamp': timestamp,
8978
+ 'datetime': this.iso8601(timestamp),
8979
+ 'timeframe': undefined,
8980
+ 'longShortRatio': this.safeNumber2(info, 'longShortRatio', 'longShortAccountRatio'),
8981
+ };
8982
+ }
8906
8983
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
8907
8984
  if (!response) {
8908
8985
  return undefined; // fallback to default error handler
package/js/src/bybit.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bybit.js';
2
- import type { Int, OrderSide, OrderType, Trade, Order, OHLCV, FundingRateHistory, OpenInterest, OrderRequest, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Greeks, Strings, Market, Currency, MarketInterface, TransferEntry, Liquidation, Leverage, Num, FundingHistory, Option, OptionChain, TradingFeeInterface, Currencies, TradingFees, CancellationRequest, Position, CrossBorrowRate, Dict, LeverageTier, LeverageTiers, int, LedgerEntry, Conversion, FundingRate, FundingRates, DepositAddress } from './base/types.js';
2
+ import type { Int, OrderSide, OrderType, Trade, Order, OHLCV, FundingRateHistory, OpenInterest, OrderRequest, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Greeks, Strings, Market, Currency, MarketInterface, TransferEntry, Liquidation, Leverage, Num, FundingHistory, Option, OptionChain, TradingFeeInterface, Currencies, TradingFees, CancellationRequest, Position, CrossBorrowRate, Dict, LeverageTier, LeverageTiers, int, LedgerEntry, Conversion, FundingRate, FundingRates, DepositAddress, LongShortRatio } from './base/types.js';
3
3
  /**
4
4
  * @class bybit
5
5
  * @augments Exchange
@@ -181,6 +181,8 @@ export default class bybit extends Exchange {
181
181
  fetchConvertTrade(id: string, code?: Str, params?: {}): Promise<Conversion>;
182
182
  fetchConvertTradeHistory(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Conversion[]>;
183
183
  parseConversion(conversion: Dict, fromCurrency?: Currency, toCurrency?: Currency): Conversion;
184
+ fetchLongShortRatioHistory(symbol?: Str, timeframe?: Str, since?: Int, limit?: Int, params?: {}): Promise<LongShortRatio[]>;
185
+ parseLongShortRatio(info: Dict, market?: Market): LongShortRatio;
184
186
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
185
187
  url: string;
186
188
  method: string;