ccxt 4.3.20__py2.py3-none-any.whl → 4.3.21__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.

Potentially problematic release.


This version of ccxt might be problematic. Click here for more details.

@@ -5679,7 +5679,7 @@ class gate(Exchange, ImplicitAPI):
5679
5679
  raise NotSupported(self.id + ' modifyMarginHelper() not support self market type')
5680
5680
  return self.parse_margin_modification(response, market)
5681
5681
 
5682
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
5682
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
5683
5683
  #
5684
5684
  # {
5685
5685
  # "value": "11.9257",
@@ -3057,7 +3057,7 @@ class hitbtc(Exchange, ImplicitAPI):
3057
3057
  'type': type,
3058
3058
  })
3059
3059
 
3060
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
3060
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
3061
3061
  #
3062
3062
  # addMargin/reduceMargin
3063
3063
  #
@@ -1545,14 +1545,17 @@ class hyperliquid(Exchange, ImplicitAPI):
1545
1545
  :param int [limit]: the maximum number of open orders structures to retrieve
1546
1546
  :param dict [params]: extra parameters specific to the exchange API endpoint
1547
1547
  :param str [params.user]: user address, will default to self.walletAddress if not provided
1548
+ :param str [params.method]: 'openOrders' or 'frontendOpenOrders' default is 'frontendOpenOrders'
1548
1549
  :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1549
1550
  """
1550
1551
  userAddress = None
1551
1552
  userAddress, params = self.handle_public_address('fetchOpenOrders', params)
1553
+ method = None
1554
+ method, params = self.handle_option_and_params(params, 'fetchOpenOrders', 'method', 'frontendOpenOrders')
1552
1555
  await self.load_markets()
1553
1556
  market = self.safe_market(symbol)
1554
1557
  request = {
1555
- 'type': 'openOrders',
1558
+ 'type': method,
1556
1559
  'user': userAddress,
1557
1560
  }
1558
1561
  response = await self.publicPostInfo(self.extend(request, params))
@@ -1726,6 +1729,25 @@ class hyperliquid(Exchange, ImplicitAPI):
1726
1729
  # "oid":6195281425
1727
1730
  # }
1728
1731
  # }
1732
+ # frontendOrder
1733
+ # {
1734
+ # "children": [],
1735
+ # "cloid": null,
1736
+ # "coin": "BLUR",
1737
+ # "isPositionTpsl": False,
1738
+ # "isTrigger": True,
1739
+ # "limitPx": "0.5",
1740
+ # "oid": 8670487141,
1741
+ # "orderType": "Stop Limit",
1742
+ # "origSz": "20.0",
1743
+ # "reduceOnly": False,
1744
+ # "side": "B",
1745
+ # "sz": "20.0",
1746
+ # "tif": null,
1747
+ # "timestamp": 1715523663687,
1748
+ # "triggerCondition": "Price above 0.6",
1749
+ # "triggerPx": "0.6"
1750
+ # }
1729
1751
  #
1730
1752
  entry = self.safe_dict_n(order, ['order', 'resting', 'filled'])
1731
1753
  if entry is None:
@@ -1756,7 +1778,7 @@ class hyperliquid(Exchange, ImplicitAPI):
1756
1778
  'lastTradeTimestamp': None,
1757
1779
  'lastUpdateTimestamp': None,
1758
1780
  'symbol': symbol,
1759
- 'type': self.safe_string_lower(entry, 'orderType'),
1781
+ 'type': self.parse_order_type(self.safe_string_lower(entry, 'orderType')),
1760
1782
  'timeInForce': self.safe_string_upper(entry, 'tif'),
1761
1783
  'postOnly': None,
1762
1784
  'reduceOnly': self.safe_bool(entry, 'reduceOnly'),
@@ -2191,7 +2213,7 @@ class hyperliquid(Exchange, ImplicitAPI):
2191
2213
  'code': self.safe_string(response, 'status'),
2192
2214
  })
2193
2215
 
2194
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
2216
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
2195
2217
  #
2196
2218
  # {
2197
2219
  # 'type': 'default'
ccxt/async_support/okx.py CHANGED
@@ -270,6 +270,9 @@ class okx(Exchange, ImplicitAPI):
270
270
  'sprd/books': 1 / 2,
271
271
  'sprd/ticker': 1,
272
272
  'sprd/public-trades': 1 / 5,
273
+ 'market/sprd-ticker': 2,
274
+ 'market/sprd-candles': 2,
275
+ 'market/sprd-history-candles': 2,
273
276
  'tradingBot/grid/ai-param': 1,
274
277
  'tradingBot/grid/min-investment': 1,
275
278
  'tradingBot/public/rsi-back-testing': 1,
@@ -6236,7 +6239,7 @@ class okx(Exchange, ImplicitAPI):
6236
6239
  'status': 'ok' if (errorCode == '0') else 'failed',
6237
6240
  })
6238
6241
 
6239
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
6242
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
6240
6243
  #
6241
6244
  # addMargin/reduceMargin
6242
6245
  #
@@ -3790,7 +3790,7 @@ class phemex(Exchange, ImplicitAPI):
3790
3790
  }
3791
3791
  return self.safe_string(statuses, status, status)
3792
3792
 
3793
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
3793
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
3794
3794
  #
3795
3795
  # {
3796
3796
  # "code": 0,
ccxt/base/exchange.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.3.20'
7
+ __version__ = '4.3.21'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -5854,7 +5854,7 @@ class Exchange(object):
5854
5854
  """
5855
5855
  raise NotSupported(self.id + ' fetchPositionsHistory() is not supported yet')
5856
5856
 
5857
- def parse_margin_modification(self, data, market: Market = None):
5857
+ def parse_margin_modification(self, data: dict, market: Market = None):
5858
5858
  raise NotSupported(self.id + ' parseMarginModification() is not supported yet')
5859
5859
 
5860
5860
  def parse_margin_modifications(self, response: List[object], symbols: List[str] = None, symbolKey: Str = None, marketType: MarketType = None):
ccxt/binance.py CHANGED
@@ -153,7 +153,7 @@ class binance(Exchange, ImplicitAPI):
153
153
  'fetchPositions': True,
154
154
  'fetchPositionsHistory': False,
155
155
  'fetchPositionsRisk': True,
156
- 'fetchPremiumIndexOHLCV': False,
156
+ 'fetchPremiumIndexOHLCV': True,
157
157
  'fetchSettlementHistory': True,
158
158
  'fetchStatus': True,
159
159
  'fetchTicker': True,
@@ -802,6 +802,7 @@ class binance(Exchange, ImplicitAPI):
802
802
  'continuousKlines': {'cost': 1, 'byLimit': [[99, 1], [499, 2], [1000, 5], [10000, 10]]},
803
803
  'markPriceKlines': {'cost': 1, 'byLimit': [[99, 1], [499, 2], [1000, 5], [10000, 10]]},
804
804
  'indexPriceKlines': {'cost': 1, 'byLimit': [[99, 1], [499, 2], [1000, 5], [10000, 10]]},
805
+ 'premiumIndexKlines': {'cost': 1, 'byLimit': [[99, 1], [499, 2], [1000, 5], [10000, 10]]},
805
806
  'fundingRate': 1,
806
807
  'fundingInfo': 1,
807
808
  'premiumIndex': 1,
@@ -4155,6 +4156,11 @@ class binance(Exchange, ImplicitAPI):
4155
4156
  response = self.dapiPublicGetIndexPriceKlines(self.extend(request, params))
4156
4157
  else:
4157
4158
  response = self.fapiPublicGetIndexPriceKlines(self.extend(request, params))
4159
+ elif price == 'premiumIndex':
4160
+ if market['inverse']:
4161
+ response = self.dapiPublicGetPremiumIndexKlines(self.extend(request, params))
4162
+ else:
4163
+ response = self.fapiPublicGetPremiumIndexKlines(self.extend(request, params))
4158
4164
  elif market['linear']:
4159
4165
  response = self.fapiPublicGetKlines(self.extend(request, params))
4160
4166
  elif market['inverse']:
@@ -10356,7 +10362,7 @@ class binance(Exchange, ImplicitAPI):
10356
10362
  'code': code,
10357
10363
  })
10358
10364
 
10359
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
10365
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
10360
10366
  #
10361
10367
  # add/reduce margin
10362
10368
  #
ccxt/bingx.py CHANGED
@@ -3436,7 +3436,7 @@ class bingx(Exchange, ImplicitAPI):
3436
3436
  #
3437
3437
  return self.parse_margin_modification(response, market)
3438
3438
 
3439
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
3439
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
3440
3440
  #
3441
3441
  # {
3442
3442
  # "code": 0,
ccxt/bitget.py CHANGED
@@ -6478,7 +6478,7 @@ class bitget(Exchange, ImplicitAPI):
6478
6478
  'type': type,
6479
6479
  })
6480
6480
 
6481
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
6481
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
6482
6482
  #
6483
6483
  # addMargin/reduceMargin
6484
6484
  #
ccxt/bitmex.py CHANGED
@@ -253,6 +253,7 @@ class bitmex(Exchange, ImplicitAPI):
253
253
  'orderQty is invalid': InvalidOrder,
254
254
  'Invalid price': InvalidOrder,
255
255
  'Invalid stopPx for ordType': InvalidOrder,
256
+ 'Account is restricted': PermissionDenied, # {"error":{"message":"Account is restricted","name":"HTTPError"}}
256
257
  },
257
258
  'broad': {
258
259
  'Signature not valid': AuthenticationError,
ccxt/coinex.py CHANGED
@@ -307,7 +307,7 @@ class coinex(Exchange, ImplicitAPI):
307
307
  'v2': {
308
308
  'public': {
309
309
  'get': {
310
- 'maintain-info': 1,
310
+ 'maintain/info': 1,
311
311
  'ping': 1,
312
312
  'time': 1,
313
313
  'spot/market': 1,
@@ -3987,160 +3987,127 @@ class coinex(Exchange, ImplicitAPI):
3987
3987
  def modify_margin_helper(self, symbol: str, amount, addOrReduce, params={}):
3988
3988
  self.load_markets()
3989
3989
  market = self.market(symbol)
3990
+ rawAmount = self.amount_to_precision(symbol, amount)
3991
+ requestAmount = rawAmount
3992
+ if addOrReduce == 'reduce':
3993
+ requestAmount = Precise.string_neg(rawAmount)
3990
3994
  request = {
3991
3995
  'market': market['id'],
3992
- 'amount': self.amount_to_precision(symbol, amount),
3993
- 'type': addOrReduce,
3996
+ 'market_type': 'FUTURES',
3997
+ 'amount': requestAmount,
3994
3998
  }
3995
- response = self.v1PerpetualPrivatePostPositionAdjustMargin(self.extend(request, params))
3999
+ response = self.v2PrivatePostFuturesAdjustPositionMargin(self.extend(request, params))
3996
4000
  #
3997
4001
  # {
3998
4002
  # "code": 0,
3999
4003
  # "data": {
4000
- # "adl_sort": 1,
4001
- # "adl_sort_val": "0.00004320",
4002
- # "amount": "0.0005",
4003
- # "amount_max": "0.0005",
4004
- # "amount_max_margin": "6.57352000000000000000",
4005
- # "bkr_price": "16294.08000000000000011090",
4006
- # "bkr_price_imply": "0.00000000000000000000",
4007
- # "close_left": "0.0005",
4008
- # "create_time": 1651202571.320778,
4009
- # "deal_all": "19.72000000000000000000",
4010
- # "deal_asset_fee": "0.00000000000000000000",
4011
- # "fee_asset": "",
4012
- # "finish_type": 1,
4013
- # "first_price": "39441.12",
4014
- # "insurance": "0.00000000000000000000",
4015
- # "latest_price": "39441.12",
4004
+ # "adl_level": 1,
4005
+ # "ath_margin_size": "2.034928",
4006
+ # "ath_position_amount": "0.0001",
4007
+ # "avg_entry_price": "61047.84",
4008
+ # "bkr_price": "30698.5600000000000004142",
4009
+ # "close_avbl": "0.0001",
4010
+ # "cml_position_value": "6.104784",
4011
+ # "created_at": 1715488472908,
4016
4012
  # "leverage": "3",
4017
- # "liq_amount": "0.00000000000000000000",
4018
- # "liq_order_price": "0",
4019
- # "liq_order_time": 0,
4020
- # "liq_price": "16491.28560000000000011090",
4021
- # "liq_price_imply": "0.00000000000000000000",
4022
- # "liq_profit": "0.00000000000000000000",
4023
- # "liq_time": 0,
4024
- # "mainten_margin": "0.005",
4025
- # "mainten_margin_amount": "0.09860280000000000000",
4026
- # "maker_fee": "0.00000000000000000000",
4027
- # "margin_amount": "11.57352000000000000000",
4013
+ # "liq_price": "30852.82412060301507579316",
4014
+ # "maintenance_margin_rate": "0.005",
4015
+ # "maintenance_margin_value": "0.03051465",
4016
+ # "margin_avbl": "3.034928",
4017
+ # "margin_mode": "isolated",
4028
4018
  # "market": "BTCUSDT",
4029
- # "open_margin": "0.58687582908396110455",
4030
- # "open_margin_imply": "0.00000000000000000000",
4031
- # "open_price": "39441.12000000000000000000",
4032
- # "open_val": "19.72056000000000000000",
4033
- # "open_val_max": "19.72056000000000000000",
4034
- # "position_id": 65171206,
4035
- # "profit_clearing": "-0.00986028000000000000",
4036
- # "profit_real": "-0.00986028000000000000",
4037
- # "profit_unreal": "0.00",
4038
- # "side": 2,
4039
- # "stop_loss_price": "0.00000000000000000000",
4040
- # "stop_loss_type": 0,
4041
- # "s ys": 0,
4042
- # "take_profit_price": "0.00000000000000000000",
4043
- # "take_profit_type": 0,
4044
- # "taker_fee": "0.00000000000000000000",
4045
- # "total": 3464,
4046
- # "type": 1,
4047
- # "update_time": 1651202638.911212,
4048
- # "user_id": 3620173
4019
+ # "market_type": "FUTURES",
4020
+ # "max_position_value": "6.104784",
4021
+ # "open_interest": "0.0001",
4022
+ # "position_id": 306458800,
4023
+ # "position_margin_rate": "0.49713929272518077625",
4024
+ # "realized_pnl": "-0.003052392",
4025
+ # "settle_price": "61047.84",
4026
+ # "settle_value": "6.104784",
4027
+ # "side": "long",
4028
+ # "stop_loss_price": "0",
4029
+ # "stop_loss_type": "",
4030
+ # "take_profit_price": "0",
4031
+ # "take_profit_type": "",
4032
+ # "unrealized_pnl": "0",
4033
+ # "updated_at": 1715488805563
4049
4034
  # },
4050
- # "message":"OK"
4035
+ # "message": "OK"
4051
4036
  # }
4052
4037
  #
4053
4038
  data = self.safe_dict(response, 'data')
4054
- status = self.safe_string(response, 'message')
4039
+ status = self.safe_string_lower(response, 'message')
4040
+ type = 'reduce' if (addOrReduce == 'reduce') else 'add'
4055
4041
  return self.extend(self.parse_margin_modification(data, market), {
4042
+ 'type': type,
4056
4043
  'amount': self.parse_number(amount),
4057
4044
  'status': status,
4058
4045
  })
4059
4046
 
4060
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
4047
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
4061
4048
  #
4062
4049
  # addMargin/reduceMargin
4063
4050
  #
4064
- # {
4065
- # "adl_sort": 1,
4066
- # "adl_sort_val": "0.00004320",
4067
- # "amount": "0.0005",
4068
- # "amount_max": "0.0005",
4069
- # "amount_max_margin": "6.57352000000000000000",
4070
- # "bkr_price": "16294.08000000000000011090",
4071
- # "bkr_price_imply": "0.00000000000000000000",
4072
- # "close_left": "0.0005",
4073
- # "create_time": 1651202571.320778,
4074
- # "deal_all": "19.72000000000000000000",
4075
- # "deal_asset_fee": "0.00000000000000000000",
4076
- # "fee_asset": "",
4077
- # "finish_type": 1,
4078
- # "first_price": "39441.12",
4079
- # "insurance": "0.00000000000000000000",
4080
- # "latest_price": "39441.12",
4081
- # "leverage": "3",
4082
- # "liq_amount": "0.00000000000000000000",
4083
- # "liq_order_price": "0",
4084
- # "liq_order_time": 0,
4085
- # "liq_price": "16491.28560000000000011090",
4086
- # "liq_price_imply": "0.00000000000000000000",
4087
- # "liq_profit": "0.00000000000000000000",
4088
- # "liq_time": 0,
4089
- # "mainten_margin": "0.005",
4090
- # "mainten_margin_amount": "0.09860280000000000000",
4091
- # "maker_fee": "0.00000000000000000000",
4092
- # "margin_amount": "11.57352000000000000000",
4093
- # "market": "BTCUSDT",
4094
- # "open_margin": "0.58687582908396110455",
4095
- # "open_margin_imply": "0.00000000000000000000",
4096
- # "open_price": "39441.12000000000000000000",
4097
- # "open_val": "19.72056000000000000000",
4098
- # "open_val_max": "19.72056000000000000000",
4099
- # "position_id": 65171206,
4100
- # "profit_clearing": "-0.00986028000000000000",
4101
- # "profit_real": "-0.00986028000000000000",
4102
- # "profit_unreal": "0.00",
4103
- # "side": 2,
4104
- # "stop_loss_price": "0.00000000000000000000",
4105
- # "stop_loss_type": 0,
4106
- # "sy s": 0,
4107
- # "take_profit_price": "0.00000000000000000000",
4108
- # "take_profit_type": 0,
4109
- # "taker_fee": "0.00000000000000000000",
4110
- # "total": 3464,
4111
- # "type": 1,
4112
- # "update_time": 1651202638.911212,
4113
- # "user_id": 3620173
4114
- # }
4051
+ # {
4052
+ # "adl_level": 1,
4053
+ # "ath_margin_size": "2.034928",
4054
+ # "ath_position_amount": "0.0001",
4055
+ # "avg_entry_price": "61047.84",
4056
+ # "bkr_price": "30698.5600000000000004142",
4057
+ # "close_avbl": "0.0001",
4058
+ # "cml_position_value": "6.104784",
4059
+ # "created_at": 1715488472908,
4060
+ # "leverage": "3",
4061
+ # "liq_price": "30852.82412060301507579316",
4062
+ # "maintenance_margin_rate": "0.005",
4063
+ # "maintenance_margin_value": "0.03051465",
4064
+ # "margin_avbl": "3.034928",
4065
+ # "margin_mode": "isolated",
4066
+ # "market": "BTCUSDT",
4067
+ # "market_type": "FUTURES",
4068
+ # "max_position_value": "6.104784",
4069
+ # "open_interest": "0.0001",
4070
+ # "position_id": 306458800,
4071
+ # "position_margin_rate": "0.49713929272518077625",
4072
+ # "realized_pnl": "-0.003052392",
4073
+ # "settle_price": "61047.84",
4074
+ # "settle_value": "6.104784",
4075
+ # "side": "long",
4076
+ # "stop_loss_price": "0",
4077
+ # "stop_loss_type": "",
4078
+ # "take_profit_price": "0",
4079
+ # "take_profit_type": "",
4080
+ # "unrealized_pnl": "0",
4081
+ # "updated_at": 1715488805563
4082
+ # }
4115
4083
  #
4116
4084
  # fetchMarginAdjustmentHistory
4117
4085
  #
4118
- # {
4119
- # bkr_price: '0',
4120
- # leverage: '3',
4121
- # liq_price: '0',
4122
- # margin_amount: '5.33236666666666666666',
4123
- # margin_change: '3',
4124
- # market: 'XRPUSDT',
4125
- # position_amount: '11',
4126
- # position_id: '297155652',
4127
- # position_type: '2',
4128
- # settle_price: '0.6361',
4129
- # time: '1711050906.382891',
4130
- # type: '1',
4131
- # user_id: '3685860'
4132
- # }
4086
+ # {
4087
+ # "bkr_pirce": "24698.56000000000000005224",
4088
+ # "created_at": 1715489978697,
4089
+ # "leverage": "3",
4090
+ # "liq_price": "24822.67336683417085432386",
4091
+ # "margin_avbl": "3.634928",
4092
+ # "margin_change": "-1.5",
4093
+ # "margin_mode": "isolated",
4094
+ # "market": "BTCUSDT",
4095
+ # "market_type": "FUTURES",
4096
+ # "open_interest": "0.0001",
4097
+ # "position_id": 306458800,
4098
+ # "settle_price": "61047.84"
4099
+ # }
4133
4100
  #
4134
4101
  marketId = self.safe_string(data, 'market')
4135
- type = self.safe_string(data, 'type')
4136
- timestamp = self.safe_integer_product_2(data, 'time', 'update_time', 1000)
4102
+ timestamp = self.safe_integer_2(data, 'updated_at', 'created_at')
4103
+ change = self.safe_string(data, 'margin_change')
4137
4104
  return {
4138
4105
  'info': data,
4139
4106
  'symbol': self.safe_symbol(marketId, market, None, 'swap'),
4140
- 'type': 'add' if (type == '1') else 'reduce',
4107
+ 'type': None,
4141
4108
  'marginMode': 'isolated',
4142
- 'amount': self.safe_number(data, 'margin_change'),
4143
- 'total': self.safe_number(data, 'position_amount'),
4109
+ 'amount': self.parse_number(Precise.string_abs(change)),
4110
+ 'total': self.safe_number(data, 'margin_avbl'),
4144
4111
  'code': market['quote'],
4145
4112
  'status': None,
4146
4113
  'timestamp': timestamp,
@@ -4150,24 +4117,24 @@ class coinex(Exchange, ImplicitAPI):
4150
4117
  def add_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
4151
4118
  """
4152
4119
  add margin
4153
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http032_adjust_position_margin
4120
+ :see: https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin
4154
4121
  :param str symbol: unified market symbol
4155
4122
  :param float amount: amount of margin to add
4156
4123
  :param dict [params]: extra parameters specific to the exchange API endpoint
4157
4124
  :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
4158
4125
  """
4159
- return self.modify_margin_helper(symbol, amount, 1, params)
4126
+ return self.modify_margin_helper(symbol, amount, 'add', params)
4160
4127
 
4161
4128
  def reduce_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
4162
4129
  """
4163
4130
  remove margin from a position
4164
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http032_adjust_position_margin
4131
+ :see: https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin
4165
4132
  :param str symbol: unified market symbol
4166
4133
  :param float amount: the amount of margin to remove
4167
4134
  :param dict [params]: extra parameters specific to the exchange API endpoint
4168
4135
  :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
4169
4136
  """
4170
- return self.modify_margin_helper(symbol, amount, 2, params)
4137
+ return self.modify_margin_helper(symbol, amount, 'reduce', params)
4171
4138
 
4172
4139
  def fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
4173
4140
  """
@@ -5592,65 +5559,60 @@ class coinex(Exchange, ImplicitAPI):
5592
5559
  def fetch_margin_adjustment_history(self, symbol: Str = None, type: Str = None, since: Num = None, limit: Num = None, params={}) -> List[MarginModification]:
5593
5560
  """
5594
5561
  fetches the history of margin added or reduced from contract isolated positions
5595
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http046_position_margin_history
5596
- :param str [symbol]: unified market symbol
5562
+ :see: https://docs.coinex.com/api/v2/futures/position/http/list-position-margin-history
5563
+ :param str symbol: unified market symbol
5597
5564
  :param str [type]: not used by coinex fetchMarginAdjustmentHistory
5598
5565
  :param int [since]: timestamp in ms of the earliest change to fetch
5599
- :param int [limit]: the maximum amount of changes to fetch, default=100, max=100
5566
+ :param int [limit]: the maximum amount of changes to fetch, default is 10
5600
5567
  :param dict params: extra parameters specific to the exchange api endpoint
5601
5568
  :param int [params.until]: timestamp in ms of the latest change to fetch
5602
- *
5603
- * EXCHANGE SPECIFIC PARAMETERS
5604
- :param int [params.offset]: offset
5569
+ :param int [params.positionId]: the id of the position that you want to retrieve margin adjustment history for
5605
5570
  :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
5606
5571
  """
5607
5572
  self.load_markets()
5608
- until = self.safe_integer(params, 'until')
5609
- params = self.omit(params, 'until')
5610
- if limit is None:
5611
- limit = 100
5573
+ if symbol is None:
5574
+ raise ArgumentsRequired(self.id + ' fetchMarginAdjustmentHistory() requires a symbol argument')
5575
+ positionId = self.safe_integer_2(params, 'positionId', 'position_id')
5576
+ params = self.omit(params, 'positionId')
5577
+ if positionId is None:
5578
+ raise ArgumentsRequired(self.id + ' fetchMarginAdjustmentHistory() requires a positionId parameter')
5579
+ market = self.market(symbol)
5612
5580
  request = {
5613
- 'market': '',
5614
- 'position_id': 0,
5615
- 'offset': 0,
5616
- 'limit': limit,
5581
+ 'market': market['id'],
5582
+ 'market_type': 'FUTURES',
5583
+ 'position_id': positionId,
5617
5584
  }
5618
- if symbol is not None:
5619
- market = self.market(symbol)
5620
- request['market'] = market['id']
5585
+ request, params = self.handle_until_option('end_time', request, params)
5621
5586
  if since is not None:
5622
5587
  request['start_time'] = since
5623
- if until is not None:
5624
- request['end_time'] = until
5625
- response = self.v1PerpetualPrivateGetPositionMarginHistory(self.extend(request, params))
5588
+ if limit is not None:
5589
+ request['limit'] = limit
5590
+ response = self.v2PrivateGetFuturesPositionMarginHistory(self.extend(request, params))
5626
5591
  #
5627
- # {
5628
- # code: '0',
5629
- # data: {
5630
- # limit: '100',
5631
- # offset: '0',
5632
- # records: [
5633
- # {
5634
- # bkr_price: '0',
5635
- # leverage: '3',
5636
- # liq_price: '0',
5637
- # margin_amount: '5.33236666666666666666',
5638
- # margin_change: '3',
5639
- # market: 'XRPUSDT',
5640
- # position_amount: '11',
5641
- # position_id: '297155652',
5642
- # position_type: '2',
5643
- # settle_price: '0.6361',
5644
- # time: '1711050906.382891',
5645
- # type: '1',
5646
- # user_id: '3685860'
5647
- # }
5648
- # ]
5649
- # },
5650
- # message: 'OK'
5651
- # }
5592
+ # {
5593
+ # "code": 0,
5594
+ # "data": [
5595
+ # {
5596
+ # "bkr_pirce": "24698.56000000000000005224",
5597
+ # "created_at": 1715489978697,
5598
+ # "leverage": "3",
5599
+ # "liq_price": "24822.67336683417085432386",
5600
+ # "margin_avbl": "3.634928",
5601
+ # "margin_change": "-1.5",
5602
+ # "margin_mode": "isolated",
5603
+ # "market": "BTCUSDT",
5604
+ # "market_type": "FUTURES",
5605
+ # "open_interest": "0.0001",
5606
+ # "position_id": 306458800,
5607
+ # "settle_price": "61047.84"
5608
+ # },
5609
+ # ],
5610
+ # "message": "OK",
5611
+ # "pagination": {
5612
+ # "has_next": True
5613
+ # }
5614
+ # }
5652
5615
  #
5653
- data = self.safe_dict(response, 'data', {})
5654
- records = self.safe_list(data, 'records', [])
5655
- modifications = self.parse_margin_modifications(records, None, 'market', 'swap')
5616
+ data = self.safe_list(response, 'data', [])
5617
+ modifications = self.parse_margin_modifications(data, None, 'market', 'swap')
5656
5618
  return self.filter_by_symbol_since_limit(modifications, symbol, since, limit)
ccxt/delta.py CHANGED
@@ -2539,7 +2539,7 @@ class delta(Exchange, ImplicitAPI):
2539
2539
  result = self.safe_dict(response, 'result', {})
2540
2540
  return self.parse_margin_modification(result, market)
2541
2541
 
2542
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
2542
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
2543
2543
  #
2544
2544
  # {
2545
2545
  # "auto_topup": False,
ccxt/digifinex.py CHANGED
@@ -3791,7 +3791,7 @@ class digifinex(Exchange, ImplicitAPI):
3791
3791
  'status': status,
3792
3792
  })
3793
3793
 
3794
- def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
3794
+ def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
3795
3795
  #
3796
3796
  # {
3797
3797
  # "instrument_id": "BTCUSDTPERP",