ccxt 4.4.20__py2.py3-none-any.whl → 4.4.22__py2.py3-none-any.whl
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.
- ccxt/__init__.py +1 -1
- ccxt/abstract/bitflyer.py +1 -0
- ccxt/abstract/bitget.py +3 -0
- ccxt/abstract/bybit.py +1 -0
- ccxt/abstract/cex.py +28 -29
- ccxt/abstract/gate.py +5 -0
- ccxt/abstract/gateio.py +5 -0
- ccxt/abstract/kucoin.py +2 -0
- ccxt/abstract/kucoinfutures.py +2 -0
- ccxt/abstract/okx.py +4 -0
- ccxt/alpaca.py +1 -0
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/alpaca.py +1 -0
- ccxt/async_support/base/exchange.py +7 -1
- ccxt/async_support/bigone.py +3 -0
- ccxt/async_support/binance.py +96 -10
- ccxt/async_support/bingx.py +5 -1
- ccxt/async_support/bitflyer.py +56 -1
- ccxt/async_support/bitget.py +73 -1
- ccxt/async_support/bybit.py +135 -4
- ccxt/async_support/cex.py +1247 -1326
- ccxt/async_support/cryptocom.py +1 -1
- ccxt/async_support/gate.py +97 -2
- ccxt/async_support/htx.py +27 -7
- ccxt/async_support/hyperliquid.py +15 -12
- ccxt/async_support/kucoin.py +42 -88
- ccxt/async_support/kucoinfutures.py +2 -2
- ccxt/async_support/okx.py +76 -10
- ccxt/base/exchange.py +33 -1
- ccxt/base/types.py +9 -0
- ccxt/bigone.py +3 -0
- ccxt/binance.py +96 -10
- ccxt/bingx.py +5 -1
- ccxt/bitflyer.py +56 -1
- ccxt/bitget.py +73 -1
- ccxt/bybit.py +135 -4
- ccxt/cex.py +1246 -1326
- ccxt/cryptocom.py +1 -1
- ccxt/gate.py +97 -2
- ccxt/htx.py +27 -7
- ccxt/hyperliquid.py +15 -12
- ccxt/kucoin.py +42 -88
- ccxt/kucoinfutures.py +2 -2
- ccxt/okx.py +76 -10
- ccxt/pro/__init__.py +1 -1
- ccxt/test/tests_async.py +4 -4
- ccxt/test/tests_sync.py +4 -4
- {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/METADATA +5 -5
- {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/RECORD +52 -52
- {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/WHEEL +0 -0
- {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/top_level.txt +0 -0
ccxt/async_support/bitget.py
CHANGED
@@ -8,7 +8,7 @@ from ccxt.abstract.bitget import ImplicitAPI
|
|
8
8
|
import asyncio
|
9
9
|
import hashlib
|
10
10
|
import json
|
11
|
-
from ccxt.base.types import Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, FundingHistory, Int, IsolatedBorrowRate, LedgerEntry, Leverage, LeverageTier, Liquidation, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
|
11
|
+
from ccxt.base.types import LongShortRatio, Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, FundingHistory, Int, IsolatedBorrowRate, LedgerEntry, Leverage, LeverageTier, Liquidation, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
|
12
12
|
from typing import List
|
13
13
|
from ccxt.base.errors import ExchangeError
|
14
14
|
from ccxt.base.errors import AuthenticationError
|
@@ -114,6 +114,8 @@ class bitget(Exchange, ImplicitAPI):
|
|
114
114
|
'fetchLeverage': True,
|
115
115
|
'fetchLeverageTiers': False,
|
116
116
|
'fetchLiquidations': False,
|
117
|
+
'fetchLongShortRatio': False,
|
118
|
+
'fetchLongShortRatioHistory': True,
|
117
119
|
'fetchMarginAdjustmentHistory': False,
|
118
120
|
'fetchMarginMode': True,
|
119
121
|
'fetchMarketLeverageTiers': True,
|
@@ -289,6 +291,7 @@ class bitget(Exchange, ImplicitAPI):
|
|
289
291
|
'v2/mix/market/current-fund-rate': 1,
|
290
292
|
'v2/mix/market/contracts': 1,
|
291
293
|
'v2/mix/market/query-position-lever': 2,
|
294
|
+
'v2/mix/market/account-long-short': 20,
|
292
295
|
},
|
293
296
|
},
|
294
297
|
'margin': {
|
@@ -299,6 +302,7 @@ class bitget(Exchange, ImplicitAPI):
|
|
299
302
|
'margin/v1/isolated/public/tierData': 2, # 10 times/1s(IP) => 20/10 = 2
|
300
303
|
'margin/v1/public/currencies': 1, # 20 times/1s(IP) => 20/20 = 1
|
301
304
|
'v2/margin/currencies': 2,
|
305
|
+
'v2/margin/market/long-short-ratio': 20,
|
302
306
|
},
|
303
307
|
},
|
304
308
|
'earn': {
|
@@ -461,6 +465,7 @@ class bitget(Exchange, ImplicitAPI):
|
|
461
465
|
'v2/mix/order/orders-history': 2,
|
462
466
|
'v2/mix/order/orders-plan-pending': 2,
|
463
467
|
'v2/mix/order/orders-plan-history': 2,
|
468
|
+
'v2/mix/market/position-long-short': 20,
|
464
469
|
},
|
465
470
|
'post': {
|
466
471
|
'mix/v1/account/sub-account-contract-assets': 200, # 0.1 times/1s(UID) => 20/0.1 = 200
|
@@ -8273,6 +8278,73 @@ class bitget(Exchange, ImplicitAPI):
|
|
8273
8278
|
first = self.safe_dict(data, 0, {})
|
8274
8279
|
return self.parse_funding_rate(first, market)
|
8275
8280
|
|
8281
|
+
async def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
|
8282
|
+
"""
|
8283
|
+
fetches the long short ratio history for a unified market symbol
|
8284
|
+
:see: https://www.bitget.com/api-doc/common/apidata/Margin-Ls-Ratio
|
8285
|
+
:see: https://www.bitget.com/api-doc/common/apidata/Account-Long-Short
|
8286
|
+
:param str symbol: unified symbol of the market to fetch the long short ratio for
|
8287
|
+
:param str [timeframe]: the period for the ratio
|
8288
|
+
:param int [since]: the earliest time in ms to fetch ratios for
|
8289
|
+
:param int [limit]: the maximum number of long short ratio structures to retrieve
|
8290
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
8291
|
+
:returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
|
8292
|
+
"""
|
8293
|
+
await self.load_markets()
|
8294
|
+
market = self.market(symbol)
|
8295
|
+
request: dict = {
|
8296
|
+
'symbol': market['id'],
|
8297
|
+
}
|
8298
|
+
if timeframe is not None:
|
8299
|
+
request['period'] = timeframe
|
8300
|
+
response = None
|
8301
|
+
if market['swap'] or market['future']:
|
8302
|
+
response = await self.publicMixGetV2MixMarketAccountLongShort(self.extend(request, params))
|
8303
|
+
#
|
8304
|
+
# {
|
8305
|
+
# "code": "00000",
|
8306
|
+
# "msg": "success",
|
8307
|
+
# "requestTime": 1729321233281,
|
8308
|
+
# "data": [
|
8309
|
+
# {
|
8310
|
+
# "longAccountRatio": "0.58",
|
8311
|
+
# "shortAccountRatio": "0.42",
|
8312
|
+
# "longShortAccountRatio": "0.0138",
|
8313
|
+
# "ts": "1729312200000"
|
8314
|
+
# },
|
8315
|
+
# ]
|
8316
|
+
# }
|
8317
|
+
#
|
8318
|
+
else:
|
8319
|
+
response = await self.publicMarginGetV2MarginMarketLongShortRatio(self.extend(request, params))
|
8320
|
+
#
|
8321
|
+
# {
|
8322
|
+
# "code": "00000",
|
8323
|
+
# "msg": "success",
|
8324
|
+
# "requestTime": 1729306974712,
|
8325
|
+
# "data": [
|
8326
|
+
# {
|
8327
|
+
# "longShortRatio": "40.66",
|
8328
|
+
# "ts": "1729306800000"
|
8329
|
+
# },
|
8330
|
+
# ]
|
8331
|
+
# }
|
8332
|
+
#
|
8333
|
+
data = self.safe_list(response, 'data', [])
|
8334
|
+
return self.parse_long_short_ratio_history(data, market)
|
8335
|
+
|
8336
|
+
def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
|
8337
|
+
marketId = self.safe_string(info, 'symbol')
|
8338
|
+
timestamp = self.safe_integer_omit_zero(info, 'ts')
|
8339
|
+
return {
|
8340
|
+
'info': info,
|
8341
|
+
'symbol': self.safe_symbol(marketId, market, None, 'contract'),
|
8342
|
+
'timestamp': timestamp,
|
8343
|
+
'datetime': self.iso8601(timestamp),
|
8344
|
+
'timeframe': None,
|
8345
|
+
'longShortRatio': self.safe_number_2(info, 'longShortRatio', 'longShortAccountRatio'),
|
8346
|
+
}
|
8347
|
+
|
8276
8348
|
def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
8277
8349
|
if not response:
|
8278
8350
|
return None # fallback to default error handler
|
ccxt/async_support/bybit.py
CHANGED
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.bybit import ImplicitAPI
|
8
8
|
import asyncio
|
9
9
|
import hashlib
|
10
|
-
from ccxt.base.types import Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, Greeks, Int, LedgerEntry, Leverage, LeverageTier, LeverageTiers, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, FundingRates, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
|
10
|
+
from ccxt.base.types import LongShortRatio, Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, Greeks, Int, LedgerEntry, Leverage, LeverageTier, LeverageTiers, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, FundingRates, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
|
11
11
|
from typing import List
|
12
12
|
from ccxt.base.errors import ExchangeError
|
13
13
|
from ccxt.base.errors import AuthenticationError
|
@@ -106,6 +106,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
106
106
|
'fetchLedger': True,
|
107
107
|
'fetchLeverage': True,
|
108
108
|
'fetchLeverageTiers': True,
|
109
|
+
'fetchLongShortRatio': False,
|
110
|
+
'fetchLongShortRatioHistory': True,
|
109
111
|
'fetchMarginAdjustmentHistory': False,
|
110
112
|
'fetchMarketLeverageTiers': True,
|
111
113
|
'fetchMarkets': True,
|
@@ -385,6 +387,7 @@ class bybit(Exchange, ImplicitAPI):
|
|
385
387
|
# spot leverage token
|
386
388
|
'v5/spot-lever-token/order-record': 1, # 50/s => cost = 50 / 50 = 1
|
387
389
|
# spot margin trade
|
390
|
+
'v5/spot-margin-trade/interest-rate-history': 5,
|
388
391
|
'v5/spot-margin-trade/state': 5,
|
389
392
|
'v5/spot-cross-margin-trade/loan-info': 1, # 50/s => cost = 50 / 50 = 1
|
390
393
|
'v5/spot-cross-margin-trade/account': 1, # 50/s => cost = 50 / 50 = 1
|
@@ -6776,12 +6779,22 @@ class bybit(Exchange, ImplicitAPI):
|
|
6776
6779
|
# "timestamp": 1666734490778
|
6777
6780
|
# }
|
6778
6781
|
#
|
6782
|
+
# fetchBorrowRateHistory
|
6783
|
+
# {
|
6784
|
+
# "timestamp": 1721469600000,
|
6785
|
+
# "currency": "USDC",
|
6786
|
+
# "hourlyBorrowRate": "0.000014621596",
|
6787
|
+
# "vipLevel": "No VIP"
|
6788
|
+
# }
|
6789
|
+
#
|
6779
6790
|
timestamp = self.safe_integer(info, 'timestamp')
|
6780
|
-
currencyId = self.
|
6791
|
+
currencyId = self.safe_string_2(info, 'coin', 'currency')
|
6792
|
+
hourlyBorrowRate = self.safe_number(info, 'hourlyBorrowRate')
|
6793
|
+
period = 3600000 if (hourlyBorrowRate is not None) else 86400000 # 1h or 1d
|
6781
6794
|
return {
|
6782
6795
|
'currency': self.safe_currency_code(currencyId, currency),
|
6783
|
-
'rate': self.safe_number(info, 'interestRate'),
|
6784
|
-
'period':
|
6796
|
+
'rate': self.safe_number(info, 'interestRate', hourlyBorrowRate),
|
6797
|
+
'period': period, # Daily
|
6785
6798
|
'timestamp': timestamp,
|
6786
6799
|
'datetime': self.iso8601(timestamp),
|
6787
6800
|
'info': info,
|
@@ -6831,6 +6844,53 @@ class bybit(Exchange, ImplicitAPI):
|
|
6831
6844
|
interest = self.parse_borrow_interests(rows, None)
|
6832
6845
|
return self.filter_by_currency_since_limit(interest, code, since, limit)
|
6833
6846
|
|
6847
|
+
async def fetch_borrow_rate_history(self, code: str, since: Int = None, limit: Int = None, params={}):
|
6848
|
+
"""
|
6849
|
+
retrieves a history of a currencies borrow interest rate at specific time slots
|
6850
|
+
:see: https://bybit-exchange.github.io/docs/v5/spot-margin-uta/historical-interest
|
6851
|
+
:param str code: unified currency code
|
6852
|
+
:param int [since]: timestamp for the earliest borrow rate
|
6853
|
+
:param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` to retrieve
|
6854
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
6855
|
+
:param int [params.until]: the latest time in ms to fetch entries for
|
6856
|
+
:returns dict[]: an array of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
|
6857
|
+
"""
|
6858
|
+
await self.load_markets()
|
6859
|
+
currency = self.currency(code)
|
6860
|
+
request: dict = {
|
6861
|
+
'currency': currency['id'],
|
6862
|
+
}
|
6863
|
+
if since is None:
|
6864
|
+
since = self.milliseconds() - 86400000 * 30 # last 30 days
|
6865
|
+
request['startTime'] = since
|
6866
|
+
endTime = self.safe_integer_2(params, 'until', 'endTime')
|
6867
|
+
params = self.omit(params, ['until'])
|
6868
|
+
if endTime is None:
|
6869
|
+
endTime = since + 86400000 * 30 # since + 30 days
|
6870
|
+
request['endTime'] = endTime
|
6871
|
+
response = await self.privateGetV5SpotMarginTradeInterestRateHistory(self.extend(request, params))
|
6872
|
+
#
|
6873
|
+
# {
|
6874
|
+
# "retCode": 0,
|
6875
|
+
# "retMsg": "OK",
|
6876
|
+
# "result": {
|
6877
|
+
# "list": [
|
6878
|
+
# {
|
6879
|
+
# "timestamp": 1721469600000,
|
6880
|
+
# "currency": "USDC",
|
6881
|
+
# "hourlyBorrowRate": "0.000014621596",
|
6882
|
+
# "vipLevel": "No VIP"
|
6883
|
+
# }
|
6884
|
+
# ]
|
6885
|
+
# },
|
6886
|
+
# "retExtInfo": "{}",
|
6887
|
+
# "time": 1721899048991
|
6888
|
+
# }
|
6889
|
+
#
|
6890
|
+
data = self.safe_dict(response, 'result')
|
6891
|
+
rows = self.safe_list(data, 'list', [])
|
6892
|
+
return self.parse_borrow_rate_history(rows, code, since, limit)
|
6893
|
+
|
6834
6894
|
def parse_borrow_interest(self, info: dict, market: Market = None):
|
6835
6895
|
#
|
6836
6896
|
# {
|
@@ -8607,6 +8667,77 @@ class bybit(Exchange, ImplicitAPI):
|
|
8607
8667
|
'fee': None,
|
8608
8668
|
}
|
8609
8669
|
|
8670
|
+
async def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
|
8671
|
+
"""
|
8672
|
+
fetches the long short ratio history for a unified market symbol
|
8673
|
+
:see: https://bybit-exchange.github.io/docs/v5/market/long-short-ratio
|
8674
|
+
:param str symbol: unified symbol of the market to fetch the long short ratio for
|
8675
|
+
:param str [timeframe]: the period for the ratio, default is 24 hours
|
8676
|
+
:param int [since]: the earliest time in ms to fetch ratios for
|
8677
|
+
:param int [limit]: the maximum number of long short ratio structures to retrieve
|
8678
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
8679
|
+
:returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
|
8680
|
+
"""
|
8681
|
+
await self.load_markets()
|
8682
|
+
market = self.market(symbol)
|
8683
|
+
type = None
|
8684
|
+
type, params = self.get_bybit_type('fetchLongShortRatioHistory', market, params)
|
8685
|
+
if type == 'spot' or type == 'option':
|
8686
|
+
raise NotSupported(self.id + ' fetchLongShortRatioHistory() only support linear and inverse markets')
|
8687
|
+
if timeframe is None:
|
8688
|
+
timeframe = '1d'
|
8689
|
+
request: dict = {
|
8690
|
+
'symbol': market['id'],
|
8691
|
+
'period': timeframe,
|
8692
|
+
'category': type,
|
8693
|
+
}
|
8694
|
+
if limit is not None:
|
8695
|
+
request['limit'] = limit
|
8696
|
+
response = await self.publicGetV5MarketAccountRatio(self.extend(request, params))
|
8697
|
+
#
|
8698
|
+
# {
|
8699
|
+
# "retCode": 0,
|
8700
|
+
# "retMsg": "OK",
|
8701
|
+
# "result": {
|
8702
|
+
# "list": [
|
8703
|
+
# {
|
8704
|
+
# "symbol": "BTCUSDT",
|
8705
|
+
# "buyRatio": "0.5707",
|
8706
|
+
# "sellRatio": "0.4293",
|
8707
|
+
# "timestamp": "1729123200000"
|
8708
|
+
# },
|
8709
|
+
# ]
|
8710
|
+
# },
|
8711
|
+
# "retExtInfo": {},
|
8712
|
+
# "time": 1729147842516
|
8713
|
+
# }
|
8714
|
+
#
|
8715
|
+
result = self.safe_dict(response, 'result', {})
|
8716
|
+
data = self.safe_list(result, 'list', [])
|
8717
|
+
return self.parse_long_short_ratio_history(data, market)
|
8718
|
+
|
8719
|
+
def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
|
8720
|
+
#
|
8721
|
+
# {
|
8722
|
+
# "symbol": "BTCUSDT",
|
8723
|
+
# "buyRatio": "0.5707",
|
8724
|
+
# "sellRatio": "0.4293",
|
8725
|
+
# "timestamp": "1729123200000"
|
8726
|
+
# }
|
8727
|
+
#
|
8728
|
+
marketId = self.safe_string(info, 'symbol')
|
8729
|
+
timestamp = self.safe_integer_omit_zero(info, 'timestamp')
|
8730
|
+
longString = self.safe_string(info, 'buyRatio')
|
8731
|
+
shortString = self.safe_string(info, 'sellRatio')
|
8732
|
+
return {
|
8733
|
+
'info': info,
|
8734
|
+
'symbol': self.safe_symbol(marketId, market, None, 'contract'),
|
8735
|
+
'timestamp': timestamp,
|
8736
|
+
'datetime': self.iso8601(timestamp),
|
8737
|
+
'timeframe': None,
|
8738
|
+
'longShortRatio': self.parse_to_numeric(Precise.string_div(longString, shortString)),
|
8739
|
+
}
|
8740
|
+
|
8610
8741
|
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
8611
8742
|
url = self.implode_hostname(self.urls['api'][api]) + '/' + path
|
8612
8743
|
if api == 'public':
|