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/okx.py
CHANGED
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.okx import ImplicitAPI
|
8
8
|
import asyncio
|
9
9
|
import hashlib
|
10
|
-
from ccxt.base.types import Account, Balances, Conversion, CrossBorrowRate, CrossBorrowRates, Currencies, Currency, DepositAddress, Greeks, Int, LedgerEntry, Leverage, LeverageTier, MarginModification, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, Trade, TradingFeeInterface, Transaction, TransferEntry
|
10
|
+
from ccxt.base.types import Account, LongShortRatio, Balances, Conversion, CrossBorrowRate, CrossBorrowRates, Currencies, Currency, DepositAddress, Greeks, Int, LedgerEntry, Leverage, LeverageTier, MarginModification, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, Trade, TradingFeeInterface, Transaction, TransferEntry
|
11
11
|
from typing import List
|
12
12
|
from typing import Any
|
13
13
|
from ccxt.base.errors import ExchangeError
|
@@ -18,6 +18,7 @@ from ccxt.base.errors import AccountSuspended
|
|
18
18
|
from ccxt.base.errors import ArgumentsRequired
|
19
19
|
from ccxt.base.errors import BadRequest
|
20
20
|
from ccxt.base.errors import BadSymbol
|
21
|
+
from ccxt.base.errors import OperationRejected
|
21
22
|
from ccxt.base.errors import ManualInteractionNeeded
|
22
23
|
from ccxt.base.errors import InsufficientFunds
|
23
24
|
from ccxt.base.errors import InvalidAddress
|
@@ -119,6 +120,8 @@ class okx(Exchange, ImplicitAPI):
|
|
119
120
|
'fetchLedgerEntry': None,
|
120
121
|
'fetchLeverage': True,
|
121
122
|
'fetchLeverageTiers': False,
|
123
|
+
'fetchLongShortRatio': False,
|
124
|
+
'fetchLongShortRatioHistory': True,
|
122
125
|
'fetchMarginAdjustmentHistory': True,
|
123
126
|
'fetchMarketLeverageTiers': True,
|
124
127
|
'fetchMarkets': True,
|
@@ -261,6 +264,7 @@ class okx(Exchange, ImplicitAPI):
|
|
261
264
|
'rubik/stat/margin/loan-ratio': 4,
|
262
265
|
# long/short
|
263
266
|
'rubik/stat/contracts/long-short-account-ratio': 4,
|
267
|
+
'rubik/stat/contracts/long-short-account-ratio-contract': 4,
|
264
268
|
'rubik/stat/contracts/open-interest-volume': 4,
|
265
269
|
'rubik/stat/option/open-interest-volume': 4,
|
266
270
|
# put/call
|
@@ -379,6 +383,9 @@ class okx(Exchange, ImplicitAPI):
|
|
379
383
|
'account/fixed-loan/borrowing-limit': 4,
|
380
384
|
'account/fixed-loan/borrowing-quote': 5,
|
381
385
|
'account/fixed-loan/borrowing-orders-list': 5,
|
386
|
+
'account/spot-manual-borrow-repay': 10,
|
387
|
+
'account/set-auto-repay': 4,
|
388
|
+
'account/spot-borrow-repay-history': 4,
|
382
389
|
# subaccount
|
383
390
|
'users/subaccount/list': 10,
|
384
391
|
'account/subaccount/balances': 10 / 3,
|
@@ -910,6 +917,11 @@ class okx(Exchange, ImplicitAPI):
|
|
910
917
|
'59301': ExchangeError, # Margin adjustment failed for exceeding the max limit
|
911
918
|
'59313': ExchangeError, # Unable to repay. You haven't borrowed any {ccy} {ccyPair} in Quick margin mode.
|
912
919
|
'59401': ExchangeError, # Holdings already reached the limit
|
920
|
+
'59410': OperationRejected, # You can only borrow self crypto if it supports borrowing and borrowing is enabled.
|
921
|
+
'59411': InsufficientFunds, # Manual borrowing failed. Your account's free margin is insufficient
|
922
|
+
'59412': OperationRejected, # Manual borrowing failed. The amount exceeds your borrowing limit.
|
923
|
+
'59413': OperationRejected, # You didn't borrow self crypto. No repayment needed.
|
924
|
+
'59414': BadRequest, # Manual borrowing failed. The minimum borrowing limit is {param0}.needed.
|
913
925
|
'59500': ExchangeError, # Only the APIKey of the main account has permission
|
914
926
|
'59501': ExchangeError, # Only 50 APIKeys can be created per account
|
915
927
|
'59502': ExchangeError, # Note name cannot be duplicate with the currently created APIKey note name
|
@@ -6231,15 +6243,6 @@ class okx(Exchange, ImplicitAPI):
|
|
6231
6243
|
borrowRateHistories[code] = self.filter_by_currency_since_limit(borrowRateHistories[code], code, since, limit)
|
6232
6244
|
return borrowRateHistories
|
6233
6245
|
|
6234
|
-
def parse_borrow_rate_history(self, response, code, since, limit):
|
6235
|
-
result = []
|
6236
|
-
for i in range(0, len(response)):
|
6237
|
-
item = response[i]
|
6238
|
-
borrowRate = self.parse_borrow_rate(item)
|
6239
|
-
result.append(borrowRate)
|
6240
|
-
sorted = self.sort_by(result, 'timestamp')
|
6241
|
-
return self.filter_by_currency_since_limit(sorted, code, since, limit)
|
6242
|
-
|
6243
6246
|
async def fetch_borrow_rate_histories(self, codes=None, since: Int = None, limit: Int = None, params={}):
|
6244
6247
|
"""
|
6245
6248
|
retrieves a history of a multiple currencies borrow interest rate at specific time slots, returns all currencies if no symbols passed, default is None
|
@@ -7930,3 +7933,66 @@ class okx(Exchange, ImplicitAPI):
|
|
7930
7933
|
data = self.safe_list(response, 'data')
|
7931
7934
|
positions = self.parse_positions(data, symbols, params)
|
7932
7935
|
return self.filter_by_since_limit(positions, since, limit)
|
7936
|
+
|
7937
|
+
async def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
|
7938
|
+
"""
|
7939
|
+
fetches the long short ratio history for a unified market symbol
|
7940
|
+
:see: https://www.okx.com/docs-v5/en/#trading-statistics-rest-api-get-contract-long-short-ratio
|
7941
|
+
:param str symbol: unified symbol of the market to fetch the long short ratio for
|
7942
|
+
:param str [timeframe]: the period for the ratio
|
7943
|
+
:param int [since]: the earliest time in ms to fetch ratios for
|
7944
|
+
:param int [limit]: the maximum number of long short ratio structures to retrieve
|
7945
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
7946
|
+
:param int [params.until]: timestamp in ms of the latest ratio to fetch
|
7947
|
+
:returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
|
7948
|
+
"""
|
7949
|
+
await self.load_markets()
|
7950
|
+
market = self.market(symbol)
|
7951
|
+
request: dict = {
|
7952
|
+
'instId': market['id'],
|
7953
|
+
}
|
7954
|
+
until = self.safe_string_2(params, 'until', 'end')
|
7955
|
+
params = self.omit(params, 'until')
|
7956
|
+
if until is not None:
|
7957
|
+
request['end'] = until
|
7958
|
+
if timeframe is not None:
|
7959
|
+
request['period'] = timeframe
|
7960
|
+
if since is not None:
|
7961
|
+
request['begin'] = since
|
7962
|
+
if limit is not None:
|
7963
|
+
request['limit'] = limit
|
7964
|
+
response = await self.publicGetRubikStatContractsLongShortAccountRatioContract(self.extend(request, params))
|
7965
|
+
#
|
7966
|
+
# {
|
7967
|
+
# "code": "0",
|
7968
|
+
# "data": [
|
7969
|
+
# ["1729323600000", "0.9398602814619824"],
|
7970
|
+
# ["1729323300000", "0.9398602814619824"],
|
7971
|
+
# ["1729323000000", "0.9398602814619824"],
|
7972
|
+
# ],
|
7973
|
+
# "msg": ""
|
7974
|
+
# }
|
7975
|
+
#
|
7976
|
+
data = self.safe_list(response, 'data', [])
|
7977
|
+
result = []
|
7978
|
+
for i in range(0, len(data)):
|
7979
|
+
entry = data[i]
|
7980
|
+
result.append({
|
7981
|
+
'timestamp': self.safe_string(entry, 0),
|
7982
|
+
'longShortRatio': self.safe_string(entry, 1),
|
7983
|
+
})
|
7984
|
+
return self.parse_long_short_ratio_history(result, market)
|
7985
|
+
|
7986
|
+
def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
|
7987
|
+
timestamp = self.safe_integer(info, 'timestamp')
|
7988
|
+
symbol = None
|
7989
|
+
if market is not None:
|
7990
|
+
symbol = market['symbol']
|
7991
|
+
return {
|
7992
|
+
'info': info,
|
7993
|
+
'symbol': symbol,
|
7994
|
+
'timestamp': timestamp,
|
7995
|
+
'datetime': self.iso8601(timestamp),
|
7996
|
+
'timeframe': None,
|
7997
|
+
'longShortRatio': self.safe_number(info, 'longShortRatio'),
|
7998
|
+
}
|
ccxt/base/exchange.py
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
|
-
__version__ = '4.4.
|
7
|
+
__version__ = '4.4.22'
|
8
8
|
|
9
9
|
# -----------------------------------------------------------------------------
|
10
10
|
|
@@ -1910,6 +1910,8 @@ class Exchange(object):
|
|
1910
1910
|
'fetchLeverages': None,
|
1911
1911
|
'fetchLeverageTiers': None,
|
1912
1912
|
'fetchLiquidations': None,
|
1913
|
+
'fetchLongShortRatio': None,
|
1914
|
+
'fetchLongShortRatioHistory': None,
|
1913
1915
|
'fetchMarginMode': None,
|
1914
1916
|
'fetchMarginModes': None,
|
1915
1917
|
'fetchMarketLeverageTiers': None,
|
@@ -2621,6 +2623,12 @@ class Exchange(object):
|
|
2621
2623
|
def set_margin(self, symbol: str, amount: float, params={}):
|
2622
2624
|
raise NotSupported(self.id + ' setMargin() is not supported yet')
|
2623
2625
|
|
2626
|
+
def fetch_long_short_ratio(self, symbol: str, timeframe: Str = None, params={}):
|
2627
|
+
raise NotSupported(self.id + ' fetchLongShortRatio() is not supported yet')
|
2628
|
+
|
2629
|
+
def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}):
|
2630
|
+
raise NotSupported(self.id + ' fetchLongShortRatioHistory() is not supported yet')
|
2631
|
+
|
2624
2632
|
def fetch_margin_adjustment_history(self, symbol: Str = None, type: Str = None, since: Num = None, limit: Num = None, params={}):
|
2625
2633
|
"""
|
2626
2634
|
fetches the history of margin added or reduced from contract isolated positions
|
@@ -5445,6 +5453,18 @@ class Exchange(object):
|
|
5445
5453
|
interests.append(self.parse_borrow_interest(row, market))
|
5446
5454
|
return interests
|
5447
5455
|
|
5456
|
+
def parse_borrow_rate(self, info, currency: Currency = None):
|
5457
|
+
raise NotSupported(self.id + ' parseBorrowRate() is not supported yet')
|
5458
|
+
|
5459
|
+
def parse_borrow_rate_history(self, response, code: Str, since: Int, limit: Int):
|
5460
|
+
result = []
|
5461
|
+
for i in range(0, len(response)):
|
5462
|
+
item = response[i]
|
5463
|
+
borrowRate = self.parse_borrow_rate(item)
|
5464
|
+
result.append(borrowRate)
|
5465
|
+
sorted = self.sort_by(result, 'timestamp')
|
5466
|
+
return self.filter_by_currency_since_limit(sorted, code, since, limit)
|
5467
|
+
|
5448
5468
|
def parse_isolated_borrow_rates(self, info: Any):
|
5449
5469
|
result = {}
|
5450
5470
|
for i in range(0, len(info)):
|
@@ -5477,6 +5497,18 @@ class Exchange(object):
|
|
5477
5497
|
result[parsed['symbol']] = parsed
|
5478
5498
|
return result
|
5479
5499
|
|
5500
|
+
def parse_long_short_ratio(self, info: dict, market: Market = None):
|
5501
|
+
raise NotSupported(self.id + ' parseLongShortRatio() is not supported yet')
|
5502
|
+
|
5503
|
+
def parse_long_short_ratio_history(self, response, market=None, since: Int = None, limit: Int = None):
|
5504
|
+
rates = []
|
5505
|
+
for i in range(0, len(response)):
|
5506
|
+
entry = response[i]
|
5507
|
+
rates.append(self.parse_long_short_ratio(entry, market))
|
5508
|
+
sorted = self.sort_by(rates, 'timestamp')
|
5509
|
+
symbol = None if (market is None) else market['symbol']
|
5510
|
+
return self.filter_by_symbol_since_limit(sorted, symbol, since, limit)
|
5511
|
+
|
5480
5512
|
def handle_trigger_and_params(self, params):
|
5481
5513
|
isTrigger = self.safe_bool_2(params, 'trigger', 'stop')
|
5482
5514
|
if isTrigger:
|
ccxt/base/types.py
CHANGED
@@ -533,6 +533,15 @@ class DepositAddress:
|
|
533
533
|
tag: Optional[Str]
|
534
534
|
|
535
535
|
|
536
|
+
class LongShortRatio:
|
537
|
+
info: Any
|
538
|
+
symbol: Str
|
539
|
+
timestamp: Optional[Int]
|
540
|
+
datetime: Optional[Str]
|
541
|
+
timeframe: Optional[Str]
|
542
|
+
longShortRatio: float
|
543
|
+
|
544
|
+
|
536
545
|
FundingRates = Dict[Str, FundingRate]
|
537
546
|
LastPrices = Dict[Str, LastPrice]
|
538
547
|
Currencies = Dict[Str, CurrencyInterface]
|
ccxt/bigone.py
CHANGED
@@ -54,7 +54,10 @@ class bigone(Exchange, ImplicitAPI):
|
|
54
54
|
'fetchDepositAddresses': False,
|
55
55
|
'fetchDepositAddressesByNetwork': False,
|
56
56
|
'fetchDeposits': True,
|
57
|
+
'fetchFundingHistory': False,
|
57
58
|
'fetchFundingRate': False,
|
59
|
+
'fetchFundingRateHistory': False,
|
60
|
+
'fetchFundingRates': False,
|
58
61
|
'fetchMarkets': True,
|
59
62
|
'fetchMyTrades': True,
|
60
63
|
'fetchOHLCV': True,
|
ccxt/binance.py
CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.binance import ImplicitAPI
|
8
8
|
import hashlib
|
9
9
|
import json
|
10
|
-
from ccxt.base.types import Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, Greeks, Int, IsolatedBorrowRate, IsolatedBorrowRates, LedgerEntry, Leverage, Leverages, LeverageTier, LeverageTiers, MarginMode, MarginModes, MarginModification, Market, MarketInterface, Num, Option, Order, OrderBook, OrderRequest, OrderSide, OrderType, 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, IsolatedBorrowRate, IsolatedBorrowRates, LedgerEntry, Leverage, Leverages, LeverageTier, LeverageTiers, MarginMode, MarginModes, MarginModification, Market, MarketInterface, Num, Option, Order, OrderBook, OrderRequest, OrderSide, OrderType, 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
|
@@ -128,6 +128,8 @@ class binance(Exchange, ImplicitAPI):
|
|
128
128
|
'fetchLeverages': True,
|
129
129
|
'fetchLeverageTiers': True,
|
130
130
|
'fetchLiquidations': False,
|
131
|
+
'fetchLongShortRatio': False,
|
132
|
+
'fetchLongShortRatioHistory': True,
|
131
133
|
'fetchMarginAdjustmentHistory': True,
|
132
134
|
'fetchMarginMode': 'emulated',
|
133
135
|
'fetchMarginModes': True,
|
@@ -11137,15 +11139,6 @@ class binance(Exchange, ImplicitAPI):
|
|
11137
11139
|
#
|
11138
11140
|
return self.parse_borrow_rate_history(response, code, since, limit)
|
11139
11141
|
|
11140
|
-
def parse_borrow_rate_history(self, response, code, since, limit):
|
11141
|
-
result = []
|
11142
|
-
for i in range(0, len(response)):
|
11143
|
-
item = response[i]
|
11144
|
-
borrowRate = self.parse_borrow_rate(item)
|
11145
|
-
result.append(borrowRate)
|
11146
|
-
sorted = self.sort_by(result, 'timestamp')
|
11147
|
-
return self.filter_by_currency_since_limit(sorted, code, since, limit)
|
11148
|
-
|
11149
11142
|
def parse_borrow_rate(self, info, currency: Currency = None):
|
11150
11143
|
#
|
11151
11144
|
# {
|
@@ -12709,3 +12702,96 @@ class binance(Exchange, ImplicitAPI):
|
|
12709
12702
|
#
|
12710
12703
|
result = self.parse_funding_rates(response, market)
|
12711
12704
|
return self.filter_by_array(result, 'symbol', symbols)
|
12705
|
+
|
12706
|
+
def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
|
12707
|
+
"""
|
12708
|
+
fetches the long short ratio history for a unified market symbol
|
12709
|
+
:see: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio
|
12710
|
+
:see: https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Long-Short-Ratio
|
12711
|
+
:param str symbol: unified symbol of the market to fetch the long short ratio for
|
12712
|
+
:param str [timeframe]: the period for the ratio, default is 24 hours
|
12713
|
+
:param int [since]: the earliest time in ms to fetch ratios for
|
12714
|
+
:param int [limit]: the maximum number of long short ratio structures to retrieve
|
12715
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
12716
|
+
:param int [params.until]: timestamp in ms of the latest ratio to fetch
|
12717
|
+
:returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
|
12718
|
+
"""
|
12719
|
+
self.load_markets()
|
12720
|
+
market = self.market(symbol)
|
12721
|
+
if timeframe is None:
|
12722
|
+
timeframe = '1d'
|
12723
|
+
request: dict = {
|
12724
|
+
'period': timeframe,
|
12725
|
+
}
|
12726
|
+
request, params = self.handle_until_option('endTime', request, params)
|
12727
|
+
if since is not None:
|
12728
|
+
request['startTime'] = since
|
12729
|
+
if limit is not None:
|
12730
|
+
request['limit'] = limit
|
12731
|
+
subType = None
|
12732
|
+
subType, params = self.handle_sub_type_and_params('fetchLongShortRatioHistory', market, params)
|
12733
|
+
response = None
|
12734
|
+
if subType == 'linear':
|
12735
|
+
request['symbol'] = market['id']
|
12736
|
+
response = self.fapiDataGetGlobalLongShortAccountRatio(self.extend(request, params))
|
12737
|
+
#
|
12738
|
+
# [
|
12739
|
+
# {
|
12740
|
+
# "symbol": "BTCUSDT",
|
12741
|
+
# "longAccount": "0.4558",
|
12742
|
+
# "longShortRatio": "0.8376",
|
12743
|
+
# "shortAccount": "0.5442",
|
12744
|
+
# "timestamp": 1726790400000
|
12745
|
+
# },
|
12746
|
+
# ]
|
12747
|
+
#
|
12748
|
+
elif subType == 'inverse':
|
12749
|
+
request['pair'] = market['info']['pair']
|
12750
|
+
response = self.dapiDataGetGlobalLongShortAccountRatio(self.extend(request, params))
|
12751
|
+
#
|
12752
|
+
# [
|
12753
|
+
# {
|
12754
|
+
# "longAccount": "0.7262",
|
12755
|
+
# "longShortRatio": "2.6523",
|
12756
|
+
# "shortAccount": "0.2738",
|
12757
|
+
# "pair": "BTCUSD",
|
12758
|
+
# "timestamp": 1726790400000
|
12759
|
+
# },
|
12760
|
+
# ]
|
12761
|
+
#
|
12762
|
+
else:
|
12763
|
+
raise BadRequest(self.id + ' fetchLongShortRatioHistory() supports linear and inverse subTypes only')
|
12764
|
+
return self.parse_long_short_ratio_history(response, market)
|
12765
|
+
|
12766
|
+
def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
|
12767
|
+
#
|
12768
|
+
# linear
|
12769
|
+
#
|
12770
|
+
# {
|
12771
|
+
# "symbol": "BTCUSDT",
|
12772
|
+
# "longAccount": "0.4558",
|
12773
|
+
# "longShortRatio": "0.8376",
|
12774
|
+
# "shortAccount": "0.5442",
|
12775
|
+
# "timestamp": 1726790400000
|
12776
|
+
# }
|
12777
|
+
#
|
12778
|
+
# inverse
|
12779
|
+
#
|
12780
|
+
# {
|
12781
|
+
# "longAccount": "0.7262",
|
12782
|
+
# "longShortRatio": "2.6523",
|
12783
|
+
# "shortAccount": "0.2738",
|
12784
|
+
# "pair": "BTCUSD",
|
12785
|
+
# "timestamp": 1726790400000
|
12786
|
+
# }
|
12787
|
+
#
|
12788
|
+
marketId = self.safe_string(info, 'symbol')
|
12789
|
+
timestamp = self.safe_integer_omit_zero(info, 'timestamp')
|
12790
|
+
return {
|
12791
|
+
'info': info,
|
12792
|
+
'symbol': self.safe_symbol(marketId, market, None, 'contract'),
|
12793
|
+
'timestamp': timestamp,
|
12794
|
+
'datetime': self.iso8601(timestamp),
|
12795
|
+
'timeframe': None,
|
12796
|
+
'longShortRatio': self.safe_number(info, 'longShortRatio'),
|
12797
|
+
}
|
ccxt/bingx.py
CHANGED
@@ -4980,7 +4980,7 @@ class bingx(Exchange, ImplicitAPI):
|
|
4980
4980
|
def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
|
4981
4981
|
"""
|
4982
4982
|
make a withdrawal
|
4983
|
-
:see: https://bingx-api.github.io/docs/#/
|
4983
|
+
:see: https://bingx-api.github.io/docs/#/en-us/spot/wallet-api.html#Withdraw
|
4984
4984
|
:param str code: unified currency code
|
4985
4985
|
:param float amount: the amount to withdraw
|
4986
4986
|
:param str address: the address to withdraw to
|
@@ -4989,6 +4989,8 @@ class bingx(Exchange, ImplicitAPI):
|
|
4989
4989
|
:param int [params.walletType]: 1 fund account, 2 standard account, 3 perpetual account
|
4990
4990
|
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
|
4991
4991
|
"""
|
4992
|
+
tag, params = self.handle_withdraw_tag_and_params(tag, params)
|
4993
|
+
self.check_address(address)
|
4992
4994
|
self.load_markets()
|
4993
4995
|
currency = self.currency(code)
|
4994
4996
|
walletType = self.safe_integer(params, 'walletType')
|
@@ -5005,6 +5007,8 @@ class bingx(Exchange, ImplicitAPI):
|
|
5005
5007
|
network = self.safe_string_upper(params, 'network')
|
5006
5008
|
if network is not None:
|
5007
5009
|
request['network'] = self.network_code_to_id(network)
|
5010
|
+
if tag is not None:
|
5011
|
+
request['addressTag'] = tag
|
5008
5012
|
params = self.omit(params, ['walletType', 'network'])
|
5009
5013
|
response = self.walletsV1PrivatePostCapitalWithdrawApply(self.extend(request, params))
|
5010
5014
|
data = self.safe_value(response, 'data')
|
ccxt/bitflyer.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
from ccxt.base.exchange import Exchange
|
7
7
|
from ccxt.abstract.bitflyer import ImplicitAPI
|
8
8
|
import hashlib
|
9
|
-
from ccxt.base.types import Balances, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Trade, TradingFeeInterface, Transaction
|
9
|
+
from ccxt.base.types import Balances, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, FundingRate, Trade, TradingFeeInterface, Transaction
|
10
10
|
from typing import List
|
11
11
|
from ccxt.base.errors import ExchangeError
|
12
12
|
from ccxt.base.errors import ArgumentsRequired
|
@@ -39,6 +39,8 @@ class bitflyer(Exchange, ImplicitAPI):
|
|
39
39
|
'fetchBalance': True,
|
40
40
|
'fetchClosedOrders': 'emulated',
|
41
41
|
'fetchDeposits': True,
|
42
|
+
'fetchFundingRate': True,
|
43
|
+
'fetchFundingRateHistory': False,
|
42
44
|
'fetchMarginMode': False,
|
43
45
|
'fetchMarkets': True,
|
44
46
|
'fetchMyTrades': True,
|
@@ -78,6 +80,7 @@ class bitflyer(Exchange, ImplicitAPI):
|
|
78
80
|
'gethealth',
|
79
81
|
'getboardstate',
|
80
82
|
'getchats',
|
83
|
+
'getfundingrate',
|
81
84
|
],
|
82
85
|
},
|
83
86
|
'private': {
|
@@ -963,6 +966,58 @@ class bitflyer(Exchange, ImplicitAPI):
|
|
963
966
|
'fee': fee,
|
964
967
|
}
|
965
968
|
|
969
|
+
def fetch_funding_rate(self, symbol: str, params={}) -> FundingRate:
|
970
|
+
"""
|
971
|
+
fetch the current funding rate
|
972
|
+
:see: https://lightning.bitflyer.com/docs#funding-rate
|
973
|
+
:param str symbol: unified market symbol
|
974
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
975
|
+
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
|
976
|
+
"""
|
977
|
+
self.load_markets()
|
978
|
+
market = self.market(symbol)
|
979
|
+
request: dict = {
|
980
|
+
'product_code': market['id'],
|
981
|
+
}
|
982
|
+
response = self.publicGetGetfundingrate(self.extend(request, params))
|
983
|
+
#
|
984
|
+
# {
|
985
|
+
# "current_funding_rate": -0.003750000000
|
986
|
+
# "next_funding_rate_settledate": "2024-04-15T13:00:00"
|
987
|
+
# }
|
988
|
+
#
|
989
|
+
return self.parse_funding_rate(response, market)
|
990
|
+
|
991
|
+
def parse_funding_rate(self, contract, market: Market = None) -> FundingRate:
|
992
|
+
#
|
993
|
+
# {
|
994
|
+
# "current_funding_rate": -0.003750000000
|
995
|
+
# "next_funding_rate_settledate": "2024-04-15T13:00:00"
|
996
|
+
# }
|
997
|
+
#
|
998
|
+
nextFundingDatetime = self.safe_string(contract, 'next_funding_rate_settledate')
|
999
|
+
nextFundingTimestamp = self.parse8601(nextFundingDatetime)
|
1000
|
+
return {
|
1001
|
+
'info': contract,
|
1002
|
+
'symbol': self.safe_string(market, 'symbol'),
|
1003
|
+
'markPrice': None,
|
1004
|
+
'indexPrice': None,
|
1005
|
+
'interestRate': None,
|
1006
|
+
'estimatedSettlePrice': None,
|
1007
|
+
'timestamp': None,
|
1008
|
+
'datetime': None,
|
1009
|
+
'fundingRate': None,
|
1010
|
+
'fundingTimestamp': None,
|
1011
|
+
'fundingDatetime': None,
|
1012
|
+
'nextFundingRate': self.safe_number(contract, 'current_funding_rate'),
|
1013
|
+
'nextFundingTimestamp': nextFundingTimestamp,
|
1014
|
+
'nextFundingDatetime': self.iso8601(nextFundingTimestamp),
|
1015
|
+
'previousFundingRate': None,
|
1016
|
+
'previousFundingTimestamp': None,
|
1017
|
+
'previousFundingDatetime': None,
|
1018
|
+
'interval': None,
|
1019
|
+
}
|
1020
|
+
|
966
1021
|
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
967
1022
|
request = '/' + self.version + '/'
|
968
1023
|
if api == 'private':
|
ccxt/bitget.py
CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.bitget import ImplicitAPI
|
8
8
|
import hashlib
|
9
9
|
import json
|
10
|
-
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
|
10
|
+
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
|
11
11
|
from typing import List
|
12
12
|
from ccxt.base.errors import ExchangeError
|
13
13
|
from ccxt.base.errors import AuthenticationError
|
@@ -113,6 +113,8 @@ class bitget(Exchange, ImplicitAPI):
|
|
113
113
|
'fetchLeverage': True,
|
114
114
|
'fetchLeverageTiers': False,
|
115
115
|
'fetchLiquidations': False,
|
116
|
+
'fetchLongShortRatio': False,
|
117
|
+
'fetchLongShortRatioHistory': True,
|
116
118
|
'fetchMarginAdjustmentHistory': False,
|
117
119
|
'fetchMarginMode': True,
|
118
120
|
'fetchMarketLeverageTiers': True,
|
@@ -288,6 +290,7 @@ class bitget(Exchange, ImplicitAPI):
|
|
288
290
|
'v2/mix/market/current-fund-rate': 1,
|
289
291
|
'v2/mix/market/contracts': 1,
|
290
292
|
'v2/mix/market/query-position-lever': 2,
|
293
|
+
'v2/mix/market/account-long-short': 20,
|
291
294
|
},
|
292
295
|
},
|
293
296
|
'margin': {
|
@@ -298,6 +301,7 @@ class bitget(Exchange, ImplicitAPI):
|
|
298
301
|
'margin/v1/isolated/public/tierData': 2, # 10 times/1s(IP) => 20/10 = 2
|
299
302
|
'margin/v1/public/currencies': 1, # 20 times/1s(IP) => 20/20 = 1
|
300
303
|
'v2/margin/currencies': 2,
|
304
|
+
'v2/margin/market/long-short-ratio': 20,
|
301
305
|
},
|
302
306
|
},
|
303
307
|
'earn': {
|
@@ -460,6 +464,7 @@ class bitget(Exchange, ImplicitAPI):
|
|
460
464
|
'v2/mix/order/orders-history': 2,
|
461
465
|
'v2/mix/order/orders-plan-pending': 2,
|
462
466
|
'v2/mix/order/orders-plan-history': 2,
|
467
|
+
'v2/mix/market/position-long-short': 20,
|
463
468
|
},
|
464
469
|
'post': {
|
465
470
|
'mix/v1/account/sub-account-contract-assets': 200, # 0.1 times/1s(UID) => 20/0.1 = 200
|
@@ -8272,6 +8277,73 @@ class bitget(Exchange, ImplicitAPI):
|
|
8272
8277
|
first = self.safe_dict(data, 0, {})
|
8273
8278
|
return self.parse_funding_rate(first, market)
|
8274
8279
|
|
8280
|
+
def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
|
8281
|
+
"""
|
8282
|
+
fetches the long short ratio history for a unified market symbol
|
8283
|
+
:see: https://www.bitget.com/api-doc/common/apidata/Margin-Ls-Ratio
|
8284
|
+
:see: https://www.bitget.com/api-doc/common/apidata/Account-Long-Short
|
8285
|
+
:param str symbol: unified symbol of the market to fetch the long short ratio for
|
8286
|
+
:param str [timeframe]: the period for the ratio
|
8287
|
+
:param int [since]: the earliest time in ms to fetch ratios for
|
8288
|
+
:param int [limit]: the maximum number of long short ratio structures to retrieve
|
8289
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
8290
|
+
:returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
|
8291
|
+
"""
|
8292
|
+
self.load_markets()
|
8293
|
+
market = self.market(symbol)
|
8294
|
+
request: dict = {
|
8295
|
+
'symbol': market['id'],
|
8296
|
+
}
|
8297
|
+
if timeframe is not None:
|
8298
|
+
request['period'] = timeframe
|
8299
|
+
response = None
|
8300
|
+
if market['swap'] or market['future']:
|
8301
|
+
response = self.publicMixGetV2MixMarketAccountLongShort(self.extend(request, params))
|
8302
|
+
#
|
8303
|
+
# {
|
8304
|
+
# "code": "00000",
|
8305
|
+
# "msg": "success",
|
8306
|
+
# "requestTime": 1729321233281,
|
8307
|
+
# "data": [
|
8308
|
+
# {
|
8309
|
+
# "longAccountRatio": "0.58",
|
8310
|
+
# "shortAccountRatio": "0.42",
|
8311
|
+
# "longShortAccountRatio": "0.0138",
|
8312
|
+
# "ts": "1729312200000"
|
8313
|
+
# },
|
8314
|
+
# ]
|
8315
|
+
# }
|
8316
|
+
#
|
8317
|
+
else:
|
8318
|
+
response = self.publicMarginGetV2MarginMarketLongShortRatio(self.extend(request, params))
|
8319
|
+
#
|
8320
|
+
# {
|
8321
|
+
# "code": "00000",
|
8322
|
+
# "msg": "success",
|
8323
|
+
# "requestTime": 1729306974712,
|
8324
|
+
# "data": [
|
8325
|
+
# {
|
8326
|
+
# "longShortRatio": "40.66",
|
8327
|
+
# "ts": "1729306800000"
|
8328
|
+
# },
|
8329
|
+
# ]
|
8330
|
+
# }
|
8331
|
+
#
|
8332
|
+
data = self.safe_list(response, 'data', [])
|
8333
|
+
return self.parse_long_short_ratio_history(data, market)
|
8334
|
+
|
8335
|
+
def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
|
8336
|
+
marketId = self.safe_string(info, 'symbol')
|
8337
|
+
timestamp = self.safe_integer_omit_zero(info, 'ts')
|
8338
|
+
return {
|
8339
|
+
'info': info,
|
8340
|
+
'symbol': self.safe_symbol(marketId, market, None, 'contract'),
|
8341
|
+
'timestamp': timestamp,
|
8342
|
+
'datetime': self.iso8601(timestamp),
|
8343
|
+
'timeframe': None,
|
8344
|
+
'longShortRatio': self.safe_number_2(info, 'longShortRatio', 'longShortAccountRatio'),
|
8345
|
+
}
|
8346
|
+
|
8275
8347
|
def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
8276
8348
|
if not response:
|
8277
8349
|
return None # fallback to default error handler
|