ccxt 4.4.23__py2.py3-none-any.whl → 4.4.24__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/binance.py +1 -1
- ccxt/abstract/binancecoinm.py +1 -1
- ccxt/abstract/binanceus.py +1 -1
- ccxt/abstract/binanceusdm.py +1 -1
- ccxt/abstract/kucoin.py +1 -0
- ccxt/abstract/kucoinfutures.py +1 -0
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/base/exchange.py +1 -1
- ccxt/async_support/binance.py +1 -1
- ccxt/async_support/bybit.py +37 -4
- ccxt/async_support/coincatch.py +1 -1
- ccxt/async_support/gate.py +177 -59
- ccxt/async_support/hyperliquid.py +1 -1
- ccxt/async_support/kucoin.py +15 -8
- ccxt/async_support/yobit.py +1 -1
- ccxt/base/exchange.py +5 -4
- ccxt/binance.py +1 -1
- ccxt/bybit.py +37 -4
- ccxt/coincatch.py +1 -1
- ccxt/gate.py +177 -59
- ccxt/hyperliquid.py +1 -1
- ccxt/kucoin.py +15 -8
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/kucoin.py +2 -1
- ccxt/pro/onetrading.py +2 -1
- ccxt/test/tests_async.py +14 -5
- ccxt/test/tests_sync.py +14 -5
- ccxt/yobit.py +1 -1
- ccxt-4.4.24.dist-info/METADATA +636 -0
- {ccxt-4.4.23.dist-info → ccxt-4.4.24.dist-info}/RECORD +34 -34
- ccxt-4.4.23.dist-info/METADATA +0 -636
- {ccxt-4.4.23.dist-info → ccxt-4.4.24.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.23.dist-info → ccxt-4.4.24.dist-info}/WHEEL +0 -0
- {ccxt-4.4.23.dist-info → ccxt-4.4.24.dist-info}/top_level.txt +0 -0
ccxt/async_support/gate.py
CHANGED
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.gate import ImplicitAPI
|
8
8
|
import asyncio
|
9
9
|
import hashlib
|
10
|
-
from ccxt.base.types import Balances, Currencies, Currency, DepositAddress, FundingHistory, Greeks, Int, LedgerEntry, Leverage, Leverages, LeverageTier, LeverageTiers, MarginModification, 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 Balances, Bool, Currencies, Currency, DepositAddress, FundingHistory, Greeks, Int, LedgerEntry, Leverage, Leverages, LeverageTier, LeverageTiers, MarginModification, 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
|
@@ -118,6 +118,7 @@ class gate(Exchange, ImplicitAPI):
|
|
118
118
|
'createTriggerOrder': True,
|
119
119
|
'editOrder': True,
|
120
120
|
'fetchBalance': True,
|
121
|
+
'fetchBorrowInterest': True,
|
121
122
|
'fetchBorrowRateHistories': False,
|
122
123
|
'fetchBorrowRateHistory': False,
|
123
124
|
'fetchClosedOrders': True,
|
@@ -1523,7 +1524,7 @@ class gate(Exchange, ImplicitAPI):
|
|
1523
1524
|
request['currency_pair'] = market['id'] # Should always be set for non-stop
|
1524
1525
|
return [request, query]
|
1525
1526
|
|
1526
|
-
def multi_order_spot_prepare_request(self, market=None,
|
1527
|
+
def multi_order_spot_prepare_request(self, market=None, trigger=False, params={}):
|
1527
1528
|
"""
|
1528
1529
|
* @ignore
|
1529
1530
|
Fills request params currency_pair, market and account where applicable for spot order methods like fetchOpenOrders, cancelAllOrders
|
@@ -1532,12 +1533,12 @@ class gate(Exchange, ImplicitAPI):
|
|
1532
1533
|
:param dict [params]: request parameters
|
1533
1534
|
:returns: the api request object, and the new params object with non-needed parameters removed
|
1534
1535
|
"""
|
1535
|
-
marginMode, query = self.get_margin_mode(
|
1536
|
+
marginMode, query = self.get_margin_mode(trigger, params)
|
1536
1537
|
request: dict = {
|
1537
1538
|
'account': marginMode,
|
1538
1539
|
}
|
1539
1540
|
if market is not None:
|
1540
|
-
if
|
1541
|
+
if trigger:
|
1541
1542
|
# gate spot and margin stop orders use the term market instead of currency_pair, and normal instead of spot. Neither parameter is used when fetching/cancelling a single order. They are used for creating a single stop order, but createOrder does not call self method
|
1542
1543
|
request['market'] = market['id']
|
1543
1544
|
else:
|
@@ -1567,6 +1568,10 @@ class gate(Exchange, ImplicitAPI):
|
|
1567
1568
|
marginMode = 'normal'
|
1568
1569
|
if marginMode == 'cross_margin':
|
1569
1570
|
raise BadRequest(self.id + ' getMarginMode() does not support stop orders for cross margin')
|
1571
|
+
isUnifiedAccount = False
|
1572
|
+
isUnifiedAccount, params = self.handle_option_and_params(params, 'getMarginMode', 'unifiedAccount')
|
1573
|
+
if isUnifiedAccount:
|
1574
|
+
marginMode = 'unified'
|
1570
1575
|
return [marginMode, params]
|
1571
1576
|
|
1572
1577
|
def get_settlement_currencies(self, type, method):
|
@@ -3203,10 +3208,12 @@ class gate(Exchange, ImplicitAPI):
|
|
3203
3208
|
:param int [params.offset]: *contract only* list offset, starting from 0
|
3204
3209
|
:param str [params.last_id]: *contract only* specify list staring point using the id of last record in previous list-query results
|
3205
3210
|
:param int [params.count_total]: *contract only* whether to return total number matched, default to 0(no return)
|
3206
|
-
:param
|
3211
|
+
:param bool [params.unifiedAccount]: set to True for fetching trades in a unified account
|
3212
|
+
:param bool [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
3207
3213
|
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
3208
3214
|
"""
|
3209
3215
|
await self.load_markets()
|
3216
|
+
await self.load_unified_status()
|
3210
3217
|
paginate = False
|
3211
3218
|
paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
|
3212
3219
|
if paginate:
|
@@ -3724,9 +3731,11 @@ class gate(Exchange, ImplicitAPI):
|
|
3724
3731
|
:param bool [params.auto_size]: *contract only* Set side to close dual-mode position, close_long closes the long side, while close_short the short one, size also needs to be set to 0
|
3725
3732
|
:param int [params.price_type]: *contract only* 0 latest deal price, 1 mark price, 2 index price
|
3726
3733
|
:param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
|
3734
|
+
:param bool [params.unifiedAccount]: set to True for creating an order in the unified account
|
3727
3735
|
:returns dict|None: `An order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
3728
3736
|
"""
|
3729
3737
|
await self.load_markets()
|
3738
|
+
await self.load_unified_status()
|
3730
3739
|
market = self.market(symbol)
|
3731
3740
|
trigger = self.safe_value(params, 'trigger')
|
3732
3741
|
triggerPrice = self.safe_value_2(params, 'triggerPrice', 'stopPrice')
|
@@ -3861,6 +3870,7 @@ class gate(Exchange, ImplicitAPI):
|
|
3861
3870
|
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
3862
3871
|
"""
|
3863
3872
|
await self.load_markets()
|
3873
|
+
await self.load_unified_status()
|
3864
3874
|
ordersRequests = self.create_orders_request(orders, params)
|
3865
3875
|
firstOrder = orders[0]
|
3866
3876
|
market = self.market(firstOrder['symbol'])
|
@@ -3948,7 +3958,7 @@ class gate(Exchange, ImplicitAPI):
|
|
3948
3958
|
# 'text': clientOrderId, # 't-abcdef1234567890',
|
3949
3959
|
'currency_pair': market['id'], # filled in prepareRequest above
|
3950
3960
|
'type': type,
|
3951
|
-
'account': marginMode, #
|
3961
|
+
'account': marginMode, # spot, margin, cross_margin, unified
|
3952
3962
|
'side': side,
|
3953
3963
|
# 'time_in_force': 'gtc', # gtc, ioc, poc PendingOrCancelled == postOnly order
|
3954
3964
|
# 'iceberg': 0, # amount to display for the iceberg order, null or 0 for normal orders, set to -1 to hide the order completely
|
@@ -4089,9 +4099,11 @@ class gate(Exchange, ImplicitAPI):
|
|
4089
4099
|
:param str symbol: unified symbol of the market to create an order in
|
4090
4100
|
:param float cost: how much you want to trade in units of the quote currency
|
4091
4101
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4102
|
+
:param bool [params.unifiedAccount]: set to True for creating a unified account order
|
4092
4103
|
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
4093
4104
|
"""
|
4094
4105
|
await self.load_markets()
|
4106
|
+
await self.load_unified_status()
|
4095
4107
|
market = self.market(symbol)
|
4096
4108
|
if not market['spot']:
|
4097
4109
|
raise NotSupported(self.id + ' createMarketBuyOrderWithCost() supports spot orders only')
|
@@ -4100,8 +4112,13 @@ class gate(Exchange, ImplicitAPI):
|
|
4100
4112
|
|
4101
4113
|
def edit_order_request(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
|
4102
4114
|
market = self.market(symbol)
|
4103
|
-
marketType
|
4115
|
+
marketType = None
|
4116
|
+
marketType, params = self.handle_market_type_and_params('editOrder', market, params)
|
4104
4117
|
account = self.convert_type_to_account(marketType)
|
4118
|
+
isUnifiedAccount = False
|
4119
|
+
isUnifiedAccount, params = self.handle_option_and_params(params, 'editOrder', 'unifiedAccount')
|
4120
|
+
if isUnifiedAccount:
|
4121
|
+
account = 'unified'
|
4105
4122
|
isLimitOrder = (type == 'limit')
|
4106
4123
|
if account == 'spot':
|
4107
4124
|
if not isLimitOrder:
|
@@ -4124,7 +4141,7 @@ class gate(Exchange, ImplicitAPI):
|
|
4124
4141
|
request['price'] = self.price_to_precision(symbol, price)
|
4125
4142
|
if not market['spot']:
|
4126
4143
|
request['settle'] = market['settleId']
|
4127
|
-
return self.extend(request,
|
4144
|
+
return self.extend(request, params)
|
4128
4145
|
|
4129
4146
|
async def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
|
4130
4147
|
"""
|
@@ -4138,9 +4155,11 @@ class gate(Exchange, ImplicitAPI):
|
|
4138
4155
|
:param float amount: how much of the currency you want to trade in units of the base currency
|
4139
4156
|
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
4140
4157
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4158
|
+
:param bool [params.unifiedAccount]: set to True for editing an order in a unified account
|
4141
4159
|
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
4142
4160
|
"""
|
4143
4161
|
await self.load_markets()
|
4162
|
+
await self.load_unified_status()
|
4144
4163
|
market = self.market(symbol)
|
4145
4164
|
extendedRequest = self.edit_order_request(id, symbol, type, side, amount, price, params)
|
4146
4165
|
response = None
|
@@ -4393,19 +4412,19 @@ class gate(Exchange, ImplicitAPI):
|
|
4393
4412
|
# Everything below self(above return) is related to fees
|
4394
4413
|
fees = []
|
4395
4414
|
gtFee = self.safe_string(order, 'gt_fee')
|
4396
|
-
if gtFee:
|
4415
|
+
if gtFee is not None:
|
4397
4416
|
fees.append({
|
4398
4417
|
'currency': 'GT',
|
4399
4418
|
'cost': gtFee,
|
4400
4419
|
})
|
4401
4420
|
fee = self.safe_string(order, 'fee')
|
4402
|
-
if fee:
|
4421
|
+
if fee is not None:
|
4403
4422
|
fees.append({
|
4404
4423
|
'currency': self.safe_currency_code(self.safe_string(order, 'fee_currency')),
|
4405
4424
|
'cost': fee,
|
4406
4425
|
})
|
4407
4426
|
rebate = self.safe_string(order, 'rebated_fee')
|
4408
|
-
if rebate:
|
4427
|
+
if rebate is not None:
|
4409
4428
|
fees.append({
|
4410
4429
|
'currency': self.safe_currency_code(self.safe_string(order, 'rebated_fee_currency')),
|
4411
4430
|
'cost': Precise.string_neg(rebate),
|
@@ -4482,9 +4501,11 @@ class gate(Exchange, ImplicitAPI):
|
|
4482
4501
|
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
|
4483
4502
|
:param str [params.type]: 'spot', 'swap', or 'future', if not provided self.options['defaultMarginMode'] is used
|
4484
4503
|
:param str [params.settle]: 'btc' or 'usdt' - settle currency for perpetual swap and future - market settle currency is used if symbol is not None, default="usdt" for swap and "btc" for future
|
4504
|
+
:param bool [params.unifiedAccount]: set to True for fetching a unified account order
|
4485
4505
|
:returns: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
4486
4506
|
"""
|
4487
4507
|
await self.load_markets()
|
4508
|
+
await self.load_unified_status()
|
4488
4509
|
market = None if (symbol is None) else self.market(symbol)
|
4489
4510
|
result = self.handle_market_type_and_params('fetchOrder', market, params)
|
4490
4511
|
type = self.safe_string(result, 0)
|
@@ -4524,6 +4545,7 @@ class gate(Exchange, ImplicitAPI):
|
|
4524
4545
|
:param bool [params.stop]: True for fetching stop orders
|
4525
4546
|
:param str [params.type]: spot, margin, swap or future, if not provided self.options['defaultType'] is used
|
4526
4547
|
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for type='margin', if not provided self.options['defaultMarginMode'] is used
|
4548
|
+
:param bool [params.unifiedAccount]: set to True for fetching unified account orders
|
4527
4549
|
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
4528
4550
|
"""
|
4529
4551
|
return await self.fetch_orders_by_status('open', symbol, since, limit, params)
|
@@ -4547,9 +4569,11 @@ class gate(Exchange, ImplicitAPI):
|
|
4547
4569
|
:param str [params.type]: spot, swap or future, if not provided self.options['defaultType'] is used
|
4548
4570
|
:param str [params.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
|
4549
4571
|
:param boolean [params.historical]: *swap only* True for using historical endpoint
|
4572
|
+
:param bool [params.unifiedAccount]: set to True for fetching unified account orders
|
4550
4573
|
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
4551
4574
|
"""
|
4552
4575
|
await self.load_markets()
|
4576
|
+
await self.load_unified_status()
|
4553
4577
|
until = self.safe_integer(params, 'until')
|
4554
4578
|
market = None
|
4555
4579
|
if symbol is not None:
|
@@ -4579,13 +4603,15 @@ class gate(Exchange, ImplicitAPI):
|
|
4579
4603
|
if symbol is not None:
|
4580
4604
|
market = self.market(symbol)
|
4581
4605
|
symbol = market['symbol']
|
4582
|
-
|
4583
|
-
params = self.
|
4606
|
+
trigger: Bool = None
|
4607
|
+
trigger, params = self.handle_param_bool_2(params, 'trigger', 'stop')
|
4584
4608
|
type: Str = None
|
4585
4609
|
type, params = self.handle_market_type_and_params('fetchOrdersByStatus', market, params)
|
4586
4610
|
spot = (type == 'spot') or (type == 'margin')
|
4587
4611
|
request: dict = {}
|
4588
|
-
request, params = self.multi_order_spot_prepare_request(market,
|
4612
|
+
request, params = self.multi_order_spot_prepare_request(market, trigger, params) if spot else self.prepare_request(market, type, params)
|
4613
|
+
if spot and trigger:
|
4614
|
+
request = self.omit(request, 'account')
|
4589
4615
|
if status == 'closed':
|
4590
4616
|
status = 'finished'
|
4591
4617
|
request['status'] = status
|
@@ -4605,33 +4631,35 @@ class gate(Exchange, ImplicitAPI):
|
|
4605
4631
|
|
4606
4632
|
async def fetch_orders_by_status(self, status, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
4607
4633
|
await self.load_markets()
|
4634
|
+
await self.load_unified_status()
|
4608
4635
|
market = None
|
4609
4636
|
if symbol is not None:
|
4610
4637
|
market = self.market(symbol)
|
4611
4638
|
symbol = market['symbol']
|
4612
|
-
|
4613
|
-
|
4639
|
+
# don't omit here, omits done in prepareOrdersByStatusRequest
|
4640
|
+
trigger: Bool = self.safe_bool_2(params, 'trigger', 'stop')
|
4614
4641
|
res = self.handle_market_type_and_params('fetchOrdersByStatus', market, params)
|
4615
4642
|
type = self.safe_string(res, 0)
|
4616
|
-
params['type'] = type
|
4617
4643
|
request, requestParams = self.prepare_orders_by_status_request(status, symbol, since, limit, params)
|
4618
4644
|
spot = (type == 'spot') or (type == 'margin')
|
4619
|
-
|
4645
|
+
openStatus = (status == 'open')
|
4646
|
+
openSpotOrders = spot and openStatus and not trigger
|
4620
4647
|
response = None
|
4621
|
-
if
|
4622
|
-
if
|
4623
|
-
|
4624
|
-
|
4625
|
-
|
4648
|
+
if spot:
|
4649
|
+
if not trigger:
|
4650
|
+
if openStatus:
|
4651
|
+
response = await self.privateSpotGetOpenOrders(self.extend(request, requestParams))
|
4652
|
+
else:
|
4653
|
+
response = await self.privateSpotGetOrders(self.extend(request, requestParams))
|
4626
4654
|
else:
|
4627
|
-
response = await self.
|
4655
|
+
response = await self.privateSpotGetPriceOrders(self.extend(request, requestParams))
|
4628
4656
|
elif type == 'swap':
|
4629
|
-
if
|
4657
|
+
if trigger:
|
4630
4658
|
response = await self.privateFuturesGetSettlePriceOrders(self.extend(request, requestParams))
|
4631
4659
|
else:
|
4632
4660
|
response = await self.privateFuturesGetSettleOrders(self.extend(request, requestParams))
|
4633
4661
|
elif type == 'future':
|
4634
|
-
if
|
4662
|
+
if trigger:
|
4635
4663
|
response = await self.privateDeliveryGetSettlePriceOrders(self.extend(request, requestParams))
|
4636
4664
|
else:
|
4637
4665
|
response = await self.privateDeliveryGetSettleOrders(self.extend(request, requestParams))
|
@@ -4805,9 +4833,11 @@ class gate(Exchange, ImplicitAPI):
|
|
4805
4833
|
:param str symbol: Unified market symbol
|
4806
4834
|
:param dict [params]: Parameters specified by the exchange api
|
4807
4835
|
:param bool [params.stop]: True if the order to be cancelled is a trigger order
|
4836
|
+
:param bool [params.unifiedAccount]: set to True for canceling unified account orders
|
4808
4837
|
:returns: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
4809
4838
|
"""
|
4810
4839
|
await self.load_markets()
|
4840
|
+
await self.load_unified_status()
|
4811
4841
|
market = None if (symbol is None) else self.market(symbol)
|
4812
4842
|
stop = self.safe_bool_n(params, ['is_stop_order', 'stop', 'trigger'], False)
|
4813
4843
|
params = self.omit(params, ['is_stop_order', 'stop', 'trigger'])
|
@@ -4925,9 +4955,11 @@ class gate(Exchange, ImplicitAPI):
|
|
4925
4955
|
:param str[] ids: order ids
|
4926
4956
|
:param str symbol: unified symbol of the market the order was made in
|
4927
4957
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4958
|
+
:param bool [params.unifiedAccount]: set to True for canceling unified account orders
|
4928
4959
|
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
4929
4960
|
"""
|
4930
4961
|
await self.load_markets()
|
4962
|
+
await self.load_unified_status()
|
4931
4963
|
market = None
|
4932
4964
|
if symbol is not None:
|
4933
4965
|
market = self.market(symbol)
|
@@ -4964,9 +4996,11 @@ class gate(Exchange, ImplicitAPI):
|
|
4964
4996
|
:param CancellationRequest[] orders: list of order ids with symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
|
4965
4997
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
4966
4998
|
:param str[] [params.clientOrderIds]: client order ids
|
4999
|
+
:param bool [params.unifiedAccount]: set to True for canceling unified account orders
|
4967
5000
|
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
4968
5001
|
"""
|
4969
5002
|
await self.load_markets()
|
5003
|
+
await self.load_unified_status()
|
4970
5004
|
ordersRequests = []
|
4971
5005
|
for i in range(0, len(orders)):
|
4972
5006
|
order = orders[i]
|
@@ -5000,9 +5034,11 @@ class gate(Exchange, ImplicitAPI):
|
|
5000
5034
|
:see: https://www.gate.io/docs/developers/apiv4/en/#cancel-all-open-orders-matched-3
|
5001
5035
|
:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
|
5002
5036
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5037
|
+
:param bool [params.unifiedAccount]: set to True for canceling unified account orders
|
5003
5038
|
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
5004
5039
|
"""
|
5005
5040
|
await self.load_markets()
|
5041
|
+
await self.load_unified_status()
|
5006
5042
|
market = None if (symbol is None) else self.market(symbol)
|
5007
5043
|
stop = self.safe_bool_2(params, 'stop', 'trigger')
|
5008
5044
|
params = self.omit(params, ['stop', 'trigger'])
|
@@ -5749,38 +5785,48 @@ class gate(Exchange, ImplicitAPI):
|
|
5749
5785
|
"""
|
5750
5786
|
repay cross margin borrowed margin and interest
|
5751
5787
|
:see: https://www.gate.io/docs/developers/apiv4/en/#cross-margin-repayments
|
5788
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#borrow-or-repay
|
5752
5789
|
:param str code: unified currency code of the currency to repay
|
5753
5790
|
:param float amount: the amount to repay
|
5754
5791
|
:param str symbol: unified market symbol, required for isolated margin
|
5755
5792
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5756
5793
|
:param str [params.mode]: 'all' or 'partial' payment mode, extra parameter required for isolated margin
|
5757
5794
|
:param str [params.id]: '34267567' loan id, extra parameter required for isolated margin
|
5795
|
+
:param boolean [params.unifiedAccount]: set to True for repaying in the unified account
|
5758
5796
|
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
|
5759
5797
|
"""
|
5760
5798
|
await self.load_markets()
|
5799
|
+
await self.load_unified_status()
|
5761
5800
|
currency = self.currency(code)
|
5762
5801
|
request: dict = {
|
5763
5802
|
'currency': currency['id'].upper(), # todo: currencies have network-junctions
|
5764
5803
|
'amount': self.currency_to_precision(code, amount),
|
5765
5804
|
}
|
5766
|
-
|
5767
|
-
|
5768
|
-
|
5769
|
-
|
5770
|
-
|
5771
|
-
|
5772
|
-
|
5773
|
-
|
5774
|
-
|
5775
|
-
|
5776
|
-
|
5777
|
-
|
5778
|
-
|
5779
|
-
|
5780
|
-
|
5781
|
-
|
5782
|
-
|
5783
|
-
|
5805
|
+
isUnifiedAccount = False
|
5806
|
+
isUnifiedAccount, params = self.handle_option_and_params(params, 'repayCrossMargin', 'unifiedAccount')
|
5807
|
+
response = None
|
5808
|
+
if isUnifiedAccount:
|
5809
|
+
request['type'] = 'repay'
|
5810
|
+
response = await self.privateUnifiedPostLoans(self.extend(request, params))
|
5811
|
+
else:
|
5812
|
+
response = await self.privateMarginPostCrossRepayments(self.extend(request, params))
|
5813
|
+
response = self.safe_dict(response, 0)
|
5814
|
+
#
|
5815
|
+
# [
|
5816
|
+
# {
|
5817
|
+
# "id": "17",
|
5818
|
+
# "create_time": 1620381696159,
|
5819
|
+
# "update_time": 1620381696159,
|
5820
|
+
# "currency": "EOS",
|
5821
|
+
# "amount": "110.553635",
|
5822
|
+
# "text": "web",
|
5823
|
+
# "status": 2,
|
5824
|
+
# "repaid": "110.506649705159",
|
5825
|
+
# "repaid_interest": "0.046985294841",
|
5826
|
+
# "unpaid_interest": "0.0000074393366667"
|
5827
|
+
# }
|
5828
|
+
# ]
|
5829
|
+
#
|
5784
5830
|
return self.parse_margin_loan(response, currency)
|
5785
5831
|
|
5786
5832
|
async def borrow_isolated_margin(self, symbol: str, code: str, amount: float, params={}):
|
@@ -5830,34 +5876,44 @@ class gate(Exchange, ImplicitAPI):
|
|
5830
5876
|
"""
|
5831
5877
|
create a loan to borrow margin
|
5832
5878
|
:see: https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
|
5879
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#borrow-or-repay
|
5833
5880
|
:param str code: unified currency code of the currency to borrow
|
5834
5881
|
:param float amount: the amount to borrow
|
5835
5882
|
:param str symbol: unified market symbol, required for isolated margin
|
5836
5883
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5837
5884
|
:param str [params.rate]: '0.0002' or '0.002' extra parameter required for isolated margin
|
5885
|
+
:param boolean [params.unifiedAccount]: set to True for borrowing in the unified account
|
5838
5886
|
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
|
5839
5887
|
"""
|
5840
5888
|
await self.load_markets()
|
5889
|
+
await self.load_unified_status()
|
5841
5890
|
currency = self.currency(code)
|
5842
5891
|
request: dict = {
|
5843
5892
|
'currency': currency['id'].upper(), # todo: currencies have network-junctions
|
5844
5893
|
'amount': self.currency_to_precision(code, amount),
|
5845
5894
|
}
|
5846
|
-
|
5847
|
-
|
5848
|
-
|
5849
|
-
|
5850
|
-
|
5851
|
-
|
5852
|
-
|
5853
|
-
|
5854
|
-
|
5855
|
-
|
5856
|
-
|
5857
|
-
|
5858
|
-
|
5859
|
-
|
5860
|
-
|
5895
|
+
isUnifiedAccount = False
|
5896
|
+
isUnifiedAccount, params = self.handle_option_and_params(params, 'borrowCrossMargin', 'unifiedAccount')
|
5897
|
+
response = None
|
5898
|
+
if isUnifiedAccount:
|
5899
|
+
request['type'] = 'borrow'
|
5900
|
+
response = await self.privateUnifiedPostLoans(self.extend(request, params))
|
5901
|
+
else:
|
5902
|
+
response = await self.privateMarginPostCrossLoans(self.extend(request, params))
|
5903
|
+
#
|
5904
|
+
# {
|
5905
|
+
# "id": "17",
|
5906
|
+
# "create_time": 1620381696159,
|
5907
|
+
# "update_time": 1620381696159,
|
5908
|
+
# "currency": "EOS",
|
5909
|
+
# "amount": "110.553635",
|
5910
|
+
# "text": "web",
|
5911
|
+
# "status": 2,
|
5912
|
+
# "repaid": "110.506649705159",
|
5913
|
+
# "repaid_interest": "0.046985294841",
|
5914
|
+
# "unpaid_interest": "0.0000074393366667"
|
5915
|
+
# }
|
5916
|
+
#
|
5861
5917
|
return self.parse_margin_loan(response, currency)
|
5862
5918
|
|
5863
5919
|
def parse_margin_loan(self, info, currency: Currency = None):
|
@@ -5913,6 +5969,68 @@ class gate(Exchange, ImplicitAPI):
|
|
5913
5969
|
'info': info,
|
5914
5970
|
}
|
5915
5971
|
|
5972
|
+
async def fetch_borrow_interest(self, code: Str = None, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
5973
|
+
"""
|
5974
|
+
fetch the interest owed by the user for borrowing currency for margin trading
|
5975
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#list-interest-records
|
5976
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#interest-records-for-the-cross-margin-account
|
5977
|
+
:see: https://www.gate.io/docs/developers/apiv4/en/#list-interest-records-2
|
5978
|
+
:param str [code]: unified currency code
|
5979
|
+
:param str [symbol]: unified market symbol when fetching interest in isolated markets
|
5980
|
+
:param int [since]: the earliest time in ms to fetch borrow interest for
|
5981
|
+
:param int [limit]: the maximum number of structures to retrieve
|
5982
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
5983
|
+
:param boolean [params.unifiedAccount]: set to True for fetching borrow interest in the unified account
|
5984
|
+
:returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
|
5985
|
+
"""
|
5986
|
+
await self.load_markets()
|
5987
|
+
await self.load_unified_status()
|
5988
|
+
isUnifiedAccount = False
|
5989
|
+
isUnifiedAccount, params = self.handle_option_and_params(params, 'fetchBorrowInterest', 'unifiedAccount')
|
5990
|
+
request: dict = {}
|
5991
|
+
request, params = self.handle_until_option('to', request, params)
|
5992
|
+
currency = None
|
5993
|
+
if code is not None:
|
5994
|
+
currency = self.currency(code)
|
5995
|
+
request['currency'] = currency['id']
|
5996
|
+
market = None
|
5997
|
+
if symbol is not None:
|
5998
|
+
market = self.market(symbol)
|
5999
|
+
if since is not None:
|
6000
|
+
request['from'] = since
|
6001
|
+
if limit is not None:
|
6002
|
+
request['limit'] = limit
|
6003
|
+
response = None
|
6004
|
+
marginMode = None
|
6005
|
+
marginMode, params = self.handle_margin_mode_and_params('fetchBorrowInterest', params, 'cross')
|
6006
|
+
if isUnifiedAccount:
|
6007
|
+
response = await self.privateUnifiedGetInterestRecords(self.extend(request, params))
|
6008
|
+
elif marginMode == 'isolated':
|
6009
|
+
if market is not None:
|
6010
|
+
request['currency_pair'] = market['id']
|
6011
|
+
response = await self.privateMarginGetUniInterestRecords(self.extend(request, params))
|
6012
|
+
elif marginMode == 'cross':
|
6013
|
+
response = await self.privateMarginGetCrossInterestRecords(self.extend(request, params))
|
6014
|
+
interest = self.parse_borrow_interests(response, market)
|
6015
|
+
return self.filter_by_currency_since_limit(interest, code, since, limit)
|
6016
|
+
|
6017
|
+
def parse_borrow_interest(self, info: dict, market: Market = None):
|
6018
|
+
marketId = self.safe_string(info, 'currency_pair')
|
6019
|
+
market = self.safe_market(marketId, market)
|
6020
|
+
marginMode = 'isolated' if (marketId is not None) else 'cross'
|
6021
|
+
timestamp = self.safe_integer(info, 'create_time')
|
6022
|
+
return {
|
6023
|
+
'info': info,
|
6024
|
+
'timestamp': timestamp,
|
6025
|
+
'datetime': self.iso8601(timestamp),
|
6026
|
+
'symbol': self.safe_string(market, 'symbol'),
|
6027
|
+
'currency': self.safe_currency_code(self.safe_string(info, 'currency')),
|
6028
|
+
'marginMode': marginMode,
|
6029
|
+
'interest': self.safe_number(info, 'interest'),
|
6030
|
+
'interestRate': self.safe_number(info, 'actual_rate'),
|
6031
|
+
'amountBorrowed': None,
|
6032
|
+
}
|
6033
|
+
|
5916
6034
|
def sign(self, path, api=[], method='GET', params={}, headers=None, body=None):
|
5917
6035
|
authentication = api[0] # public, private
|
5918
6036
|
type = api[1] # spot, margin, future, delivery
|
@@ -2139,7 +2139,7 @@ class hyperliquid(Exchange, ImplicitAPI):
|
|
2139
2139
|
'notional': self.safe_number(entry, 'positionValue'),
|
2140
2140
|
'leverage': self.safe_number(leverage, 'value'),
|
2141
2141
|
'collateral': self.safe_number(entry, 'marginUsed'),
|
2142
|
-
'initialMargin': initialMargin,
|
2142
|
+
'initialMargin': self.parse_number(initialMargin),
|
2143
2143
|
'maintenanceMargin': None,
|
2144
2144
|
'initialMarginPercentage': None,
|
2145
2145
|
'maintenanceMarginPercentage': None,
|
ccxt/async_support/kucoin.py
CHANGED
@@ -223,6 +223,7 @@ class kucoin(Exchange, ImplicitAPI):
|
|
223
223
|
'market/orderbook/level{level}': 3, # 3SW
|
224
224
|
'market/orderbook/level2': 3, # 3SW
|
225
225
|
'market/orderbook/level3': 3, # 3SW
|
226
|
+
'hf/accounts/opened': 2, #
|
226
227
|
'hf/orders/active': 2, # 2SW
|
227
228
|
'hf/orders/active/symbols': 2, # 2SW
|
228
229
|
'hf/margin/order/active/symbols': 2, # 2SW
|
@@ -652,7 +653,7 @@ class kucoin(Exchange, ImplicitAPI):
|
|
652
653
|
'FUD': 'FTX Users\' Debt',
|
653
654
|
},
|
654
655
|
'options': {
|
655
|
-
'hf':
|
656
|
+
'hf': None, # would be auto set to `true/false` after first load
|
656
657
|
'version': 'v1',
|
657
658
|
'symbolSeparator': '-',
|
658
659
|
'fetchMyTradesMethod': 'private_get_fills',
|
@@ -1084,7 +1085,8 @@ class kucoin(Exchange, ImplicitAPI):
|
|
1084
1085
|
# "enableTrading": True
|
1085
1086
|
# },
|
1086
1087
|
#
|
1087
|
-
|
1088
|
+
credentialsSet = self.check_required_credentials(False)
|
1089
|
+
requestMarginables = credentialsSet and self.safe_bool(params, 'marginables', True)
|
1088
1090
|
if requestMarginables:
|
1089
1091
|
promises.append(self.privateGetMarginSymbols(params)) # cross margin symbols
|
1090
1092
|
#
|
@@ -1147,6 +1149,9 @@ class kucoin(Exchange, ImplicitAPI):
|
|
1147
1149
|
# "makerCoefficient": "1" # Maker Fee Coefficient
|
1148
1150
|
# }
|
1149
1151
|
#
|
1152
|
+
if credentialsSet:
|
1153
|
+
# load migration status for account
|
1154
|
+
promises.append(self.load_migration_status())
|
1150
1155
|
responses = await asyncio.gather(*promises)
|
1151
1156
|
symbolsData = self.safe_list(responses[0], 'data')
|
1152
1157
|
crossData = self.safe_dict(responses[1], 'data', {}) if requestMarginables else {}
|
@@ -1233,14 +1238,16 @@ class kucoin(Exchange, ImplicitAPI):
|
|
1233
1238
|
return result
|
1234
1239
|
|
1235
1240
|
async def load_migration_status(self, force: bool = False):
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
+
"""
|
1242
|
+
loads the migration status for the account(hf or not)
|
1243
|
+
:see: https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/get-user-type
|
1244
|
+
"""
|
1245
|
+
if not ('hf' in self.options) or (self.options['hf'] is None) or force:
|
1246
|
+
result: dict = await self.privateGetHfAccountsOpened()
|
1247
|
+
self.options['hf'] = self.safe_bool(result, 'data')
|
1241
1248
|
|
1242
1249
|
def handle_hf_and_params(self, params={}):
|
1243
|
-
migrated: Bool = self.
|
1250
|
+
migrated: Bool = self.safe_bool(self.options, 'hf', False)
|
1244
1251
|
loadedHf: Bool = None
|
1245
1252
|
if migrated is not None:
|
1246
1253
|
if migrated:
|
ccxt/async_support/yobit.py
CHANGED
@@ -1125,7 +1125,7 @@ class yobit(Exchange, ImplicitAPI):
|
|
1125
1125
|
ids = list(trades.keys())
|
1126
1126
|
result = []
|
1127
1127
|
for i in range(0, len(ids)):
|
1128
|
-
id = ids
|
1128
|
+
id = self.safe_string(ids, i)
|
1129
1129
|
trade = self.parse_trade(self.extend(trades[id], {
|
1130
1130
|
'trade_id': id,
|
1131
1131
|
}), market)
|
ccxt/base/exchange.py
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
|
-
__version__ = '4.4.
|
7
|
+
__version__ = '4.4.24'
|
8
8
|
|
9
9
|
# -----------------------------------------------------------------------------
|
10
10
|
|
@@ -3001,9 +3001,10 @@ class Exchange(object):
|
|
3001
3001
|
isTriggerOrSLTpOrder = ((self.safe_string(order, 'triggerPrice') is not None or (self.safe_string(order, 'stopLossPrice') is not None)) or (self.safe_string(order, 'takeProfitPrice') is not None))
|
3002
3002
|
if parseFilled or parseCost or shouldParseFees:
|
3003
3003
|
rawTrades = self.safe_value(order, 'trades', trades)
|
3004
|
-
oldNumber = self.number
|
3004
|
+
# oldNumber = self.number
|
3005
3005
|
# we parse trades here!
|
3006
|
-
self
|
3006
|
+
# i don't think self is needed anymore
|
3007
|
+
# self.number = str
|
3007
3008
|
firstTrade = self.safe_value(rawTrades, 0)
|
3008
3009
|
# parse trades if they haven't already been parsed
|
3009
3010
|
tradesAreParsed = ((firstTrade is not None) and ('info' in firstTrade) and ('id' in firstTrade))
|
@@ -3011,7 +3012,7 @@ class Exchange(object):
|
|
3011
3012
|
trades = self.parse_trades(rawTrades, market)
|
3012
3013
|
else:
|
3013
3014
|
trades = rawTrades
|
3014
|
-
self.number = oldNumber
|
3015
|
+
# self.number = oldNumber; why parse trades if you read the value using `safeString` ?
|
3015
3016
|
tradesLength = 0
|
3016
3017
|
isArray = isinstance(trades, list)
|
3017
3018
|
if isArray:
|
ccxt/binance.py
CHANGED
@@ -1117,7 +1117,7 @@ class binance(Exchange, ImplicitAPI):
|
|
1117
1117
|
'cm/adlQuantile': 5,
|
1118
1118
|
'um/trade/asyn': 300,
|
1119
1119
|
'um/trade/asyn/id': 2,
|
1120
|
-
'um/order/asyn
|
1120
|
+
'um/order/asyn': 300,
|
1121
1121
|
'um/order/asyn/id': 2,
|
1122
1122
|
'um/income/asyn': 300,
|
1123
1123
|
'um/income/asyn/id': 2,
|