ccxt 4.4.22__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.
Files changed (60) hide show
  1. ccxt/__init__.py +3 -1
  2. ccxt/abstract/binance.py +64 -43
  3. ccxt/abstract/binancecoinm.py +64 -43
  4. ccxt/abstract/binanceus.py +64 -43
  5. ccxt/abstract/binanceusdm.py +64 -43
  6. ccxt/abstract/coincatch.py +94 -0
  7. ccxt/abstract/kucoin.py +1 -0
  8. ccxt/abstract/kucoinfutures.py +1 -0
  9. ccxt/async_support/__init__.py +3 -1
  10. ccxt/async_support/base/exchange.py +1 -1
  11. ccxt/async_support/binance.py +87 -62
  12. ccxt/async_support/bitfinex.py +4 -0
  13. ccxt/async_support/bitflyer.py +1 -0
  14. ccxt/async_support/bitrue.py +3 -0
  15. ccxt/async_support/bybit.py +39 -6
  16. ccxt/async_support/cex.py +4 -0
  17. ccxt/async_support/coinbase.py +1 -1
  18. ccxt/async_support/coinbaseexchange.py +3 -0
  19. ccxt/async_support/coincatch.py +4955 -0
  20. ccxt/async_support/coinex.py +60 -1
  21. ccxt/async_support/gate.py +177 -59
  22. ccxt/async_support/hyperliquid.py +1 -1
  23. ccxt/async_support/kucoin.py +15 -8
  24. ccxt/async_support/latoken.py +6 -0
  25. ccxt/async_support/mexc.py +1 -1
  26. ccxt/async_support/oceanex.py +2 -0
  27. ccxt/async_support/okcoin.py +1 -0
  28. ccxt/async_support/poloniex.py +5 -0
  29. ccxt/async_support/yobit.py +1 -1
  30. ccxt/base/exchange.py +5 -4
  31. ccxt/binance.py +87 -62
  32. ccxt/bitfinex.py +4 -0
  33. ccxt/bitflyer.py +1 -0
  34. ccxt/bitrue.py +3 -0
  35. ccxt/bybit.py +39 -6
  36. ccxt/cex.py +4 -0
  37. ccxt/coinbase.py +1 -1
  38. ccxt/coinbaseexchange.py +3 -0
  39. ccxt/coincatch.py +4955 -0
  40. ccxt/coinex.py +60 -1
  41. ccxt/gate.py +177 -59
  42. ccxt/hyperliquid.py +1 -1
  43. ccxt/kucoin.py +15 -8
  44. ccxt/latoken.py +6 -0
  45. ccxt/mexc.py +1 -1
  46. ccxt/oceanex.py +2 -0
  47. ccxt/okcoin.py +1 -0
  48. ccxt/poloniex.py +5 -0
  49. ccxt/pro/__init__.py +3 -1
  50. ccxt/pro/coincatch.py +1429 -0
  51. ccxt/pro/kucoin.py +2 -1
  52. ccxt/pro/onetrading.py +2 -1
  53. ccxt/test/tests_async.py +29 -6
  54. ccxt/test/tests_sync.py +29 -6
  55. ccxt/yobit.py +1 -1
  56. {ccxt-4.4.22.dist-info → ccxt-4.4.24.dist-info}/METADATA +7 -6
  57. {ccxt-4.4.22.dist-info → ccxt-4.4.24.dist-info}/RECORD +60 -56
  58. {ccxt-4.4.22.dist-info → ccxt-4.4.24.dist-info}/LICENSE.txt +0 -0
  59. {ccxt-4.4.22.dist-info → ccxt-4.4.24.dist-info}/WHEEL +0 -0
  60. {ccxt-4.4.22.dist-info → ccxt-4.4.24.dist-info}/top_level.txt +0 -0
@@ -59,6 +59,8 @@ class coinex(Exchange, ImplicitAPI):
59
59
  'cancelAllOrders': True,
60
60
  'cancelOrder': True,
61
61
  'cancelOrders': True,
62
+ 'closeAllPositions': False,
63
+ 'closePosition': True,
62
64
  'createDepositAddress': True,
63
65
  'createMarketBuyOrderWithCost': True,
64
66
  'createMarketOrderWithCost': False,
@@ -1730,7 +1732,7 @@ class coinex(Exchange, ImplicitAPI):
1730
1732
  # "stop_id": 117180138153
1731
1733
  # }
1732
1734
  #
1733
- # Swap createOrder, createOrders, editOrder, cancelOrders, cancelOrder, fetchOpenOrders, fetchClosedOrders
1735
+ # Swap createOrder, createOrders, editOrder, cancelOrders, cancelOrder, fetchOpenOrders, fetchClosedOrders, closePosition
1734
1736
  #
1735
1737
  # {
1736
1738
  # "amount": "0.0001",
@@ -5364,6 +5366,63 @@ class coinex(Exchange, ImplicitAPI):
5364
5366
  positions = self.parse_positions(records)
5365
5367
  return self.filter_by_symbol_since_limit(positions, symbol, since, limit)
5366
5368
 
5369
+ async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
5370
+ """
5371
+ closes an open position for a market
5372
+ :see: https://docs.coinex.com/api/v2/futures/position/http/close-position
5373
+ :param str symbol: unified CCXT market symbol
5374
+ :param str [side]: buy or sell, not used by coinex
5375
+ :param dict [params]: extra parameters specific to the exchange API endpoint
5376
+ :param str params['type']: required by coinex, one of: limit, market, maker_only, ioc or fok, default is *market*
5377
+ :param str [params.price]: the price to fulfill the order, ignored in market orders
5378
+ :param str [params.amount]: the amount to trade in units of the base currency
5379
+ :param str [params.clientOrderId]: the client id of the order
5380
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
5381
+ """
5382
+ await self.load_markets()
5383
+ market = self.market(symbol)
5384
+ type = self.safe_string(params, 'type', 'market')
5385
+ request: dict = {
5386
+ 'market': market['id'],
5387
+ 'market_type': 'FUTURES',
5388
+ 'type': type,
5389
+ }
5390
+ clientOrderId = self.safe_string_2(params, 'client_id', 'clientOrderId')
5391
+ if clientOrderId is not None:
5392
+ request['client_id'] = clientOrderId
5393
+ params = self.omit(params, 'clientOrderId')
5394
+ response = await self.v2PrivatePostFuturesClosePosition(self.extend(request, params))
5395
+ #
5396
+ # {
5397
+ # "code": 0,
5398
+ # "data": {
5399
+ # "amount": "0.0001",
5400
+ # "client_id": "",
5401
+ # "created_at": 1729666043969,
5402
+ # "fee": "0.00335858",
5403
+ # "fee_ccy": "USDT",
5404
+ # "filled_amount": "0.0001",
5405
+ # "filled_value": "6.717179",
5406
+ # "last_filled_amount": "0.0001",
5407
+ # "last_filled_price": "67171.79",
5408
+ # "maker_fee_rate": "0",
5409
+ # "market": "BTCUSDT",
5410
+ # "market_type": "FUTURES",
5411
+ # "order_id": 155477479761,
5412
+ # "price": "0",
5413
+ # "realized_pnl": "-0.001823",
5414
+ # "side": "sell",
5415
+ # "taker_fee_rate": "0.0005",
5416
+ # "type": "market",
5417
+ # "unfilled_amount": "0",
5418
+ # "updated_at": 1729666043969
5419
+ # },
5420
+ # "message": "OK"
5421
+ # }
5422
+ #
5423
+ data = self.safe_dict(response, 'data', {})
5424
+ return self.parse_order(data, market)
5425
+
5367
5426
  def handle_margin_mode_and_params(self, methodName, params={}, defaultValue=None):
5368
5427
  """
5369
5428
  * @ignore
@@ -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, stop=False, params={}):
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(stop, params)
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 stop:
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 boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
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, # 'spot', 'margin', 'cross_margin'
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, query = self.handle_market_type_and_params('editOrder', market, params)
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, query)
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
- stop = self.safe_bool_2(params, 'stop', 'trigger')
4583
- params = self.omit(params, ['stop', 'trigger'])
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, stop, params) if spot else self.prepare_request(market, type, params)
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
- stop = self.safe_bool_2(params, 'stop', 'trigger')
4613
- params = self.omit(params, ['trigger', 'stop'])
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
- openSpotOrders = spot and (status == 'open') and not stop
4645
+ openStatus = (status == 'open')
4646
+ openSpotOrders = spot and openStatus and not trigger
4620
4647
  response = None
4621
- if type == 'spot' or type == 'margin':
4622
- if openSpotOrders:
4623
- response = await self.privateSpotGetOpenOrders(self.extend(request, requestParams))
4624
- elif stop:
4625
- response = await self.privateSpotGetPriceOrders(self.extend(request, requestParams))
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.privateSpotGetOrders(self.extend(request, requestParams))
4655
+ response = await self.privateSpotGetPriceOrders(self.extend(request, requestParams))
4628
4656
  elif type == 'swap':
4629
- if stop:
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 stop:
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
- response = await self.privateMarginPostCrossRepayments(self.extend(request, params))
5767
- #
5768
- # [
5769
- # {
5770
- # "id": "17",
5771
- # "create_time": 1620381696159,
5772
- # "update_time": 1620381696159,
5773
- # "currency": "EOS",
5774
- # "amount": "110.553635",
5775
- # "text": "web",
5776
- # "status": 2,
5777
- # "repaid": "110.506649705159",
5778
- # "repaid_interest": "0.046985294841",
5779
- # "unpaid_interest": "0.0000074393366667"
5780
- # }
5781
- # ]
5782
- #
5783
- response = self.safe_value(response, 0)
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
- response = await self.privateMarginPostCrossLoans(self.extend(request, params))
5847
- #
5848
- # {
5849
- # "id": "17",
5850
- # "create_time": 1620381696159,
5851
- # "update_time": 1620381696159,
5852
- # "currency": "EOS",
5853
- # "amount": "110.553635",
5854
- # "text": "web",
5855
- # "status": 2,
5856
- # "repaid": "110.506649705159",
5857
- # "repaid_interest": "0.046985294841",
5858
- # "unpaid_interest": "0.0000074393366667"
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,