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

Files changed (64) hide show
  1. ccxt/__init__.py +1 -1
  2. ccxt/abstract/bingx.py +2 -0
  3. ccxt/abstract/bybit.py +2 -0
  4. ccxt/ascendex.py +1 -0
  5. ccxt/async_support/__init__.py +1 -1
  6. ccxt/async_support/ascendex.py +1 -0
  7. ccxt/async_support/base/exchange.py +13 -1
  8. ccxt/async_support/binance.py +81 -9
  9. ccxt/async_support/bingx.py +94 -1
  10. ccxt/async_support/bitfinex2.py +1 -0
  11. ccxt/async_support/bitget.py +2 -0
  12. ccxt/async_support/bitmex.py +1 -0
  13. ccxt/async_support/bitrue.py +1 -0
  14. ccxt/async_support/bybit.py +50 -0
  15. ccxt/async_support/coinbase.py +40 -20
  16. ccxt/async_support/coinbaseinternational.py +1 -0
  17. ccxt/async_support/coinex.py +96 -8
  18. ccxt/async_support/cryptocom.py +1 -0
  19. ccxt/async_support/delta.py +1 -0
  20. ccxt/async_support/digifinex.py +1 -0
  21. ccxt/async_support/exmo.py +1 -0
  22. ccxt/async_support/gate.py +2 -0
  23. ccxt/async_support/gemini.py +10 -9
  24. ccxt/async_support/hitbtc.py +1 -0
  25. ccxt/async_support/htx.py +1 -0
  26. ccxt/async_support/hyperliquid.py +1 -0
  27. ccxt/async_support/kucoin.py +1 -0
  28. ccxt/async_support/kucoinfutures.py +32 -4
  29. ccxt/async_support/mexc.py +1 -0
  30. ccxt/async_support/okx.py +143 -8
  31. ccxt/async_support/phemex.py +1 -0
  32. ccxt/async_support/woo.py +1 -0
  33. ccxt/base/exchange.py +52 -6
  34. ccxt/base/types.py +1 -0
  35. ccxt/binance.py +81 -9
  36. ccxt/bingx.py +94 -1
  37. ccxt/bitfinex2.py +1 -0
  38. ccxt/bitget.py +2 -0
  39. ccxt/bitmex.py +1 -0
  40. ccxt/bitrue.py +1 -0
  41. ccxt/bybit.py +50 -0
  42. ccxt/coinbase.py +40 -20
  43. ccxt/coinbaseinternational.py +1 -0
  44. ccxt/coinex.py +96 -8
  45. ccxt/cryptocom.py +1 -0
  46. ccxt/delta.py +1 -0
  47. ccxt/digifinex.py +1 -0
  48. ccxt/exmo.py +1 -0
  49. ccxt/gate.py +2 -0
  50. ccxt/gemini.py +10 -9
  51. ccxt/hitbtc.py +1 -0
  52. ccxt/htx.py +1 -0
  53. ccxt/hyperliquid.py +1 -0
  54. ccxt/kucoin.py +1 -0
  55. ccxt/kucoinfutures.py +32 -4
  56. ccxt/mexc.py +1 -0
  57. ccxt/okx.py +143 -8
  58. ccxt/phemex.py +1 -0
  59. ccxt/pro/__init__.py +1 -1
  60. ccxt/woo.py +1 -0
  61. {ccxt-4.2.89.dist-info → ccxt-4.2.90.dist-info}/METADATA +4 -4
  62. {ccxt-4.2.89.dist-info → ccxt-4.2.90.dist-info}/RECORD +64 -64
  63. {ccxt-4.2.89.dist-info → ccxt-4.2.90.dist-info}/WHEEL +0 -0
  64. {ccxt-4.2.89.dist-info → ccxt-4.2.90.dist-info}/top_level.txt +0 -0
@@ -93,6 +93,7 @@ class coinex(Exchange, ImplicitAPI):
93
93
  'fetchLeverage': 'emulated',
94
94
  'fetchLeverages': True,
95
95
  'fetchLeverageTiers': True,
96
+ 'fetchMarginAdjustmentHistory': True,
96
97
  'fetchMarketLeverageTiers': 'emulated',
97
98
  'fetchMarkets': True,
98
99
  'fetchMarkOHLCV': False,
@@ -3967,11 +3968,10 @@ class coinex(Exchange, ImplicitAPI):
3967
3968
  # "message":"OK"
3968
3969
  # }
3969
3970
  #
3971
+ data = self.safe_dict(response, 'data')
3970
3972
  status = self.safe_string(response, 'message')
3971
- type = 'add' if (addOrReduce == 1) else 'reduce'
3972
- return self.extend(self.parse_margin_modification(response, market), {
3973
+ return self.extend(self.parse_margin_modification(data, market), {
3973
3974
  'amount': self.parse_number(amount),
3974
- 'type': type,
3975
3975
  'status': status,
3976
3976
  })
3977
3977
 
@@ -4031,13 +4031,34 @@ class coinex(Exchange, ImplicitAPI):
4031
4031
  # "user_id": 3620173
4032
4032
  # }
4033
4033
  #
4034
- timestamp = self.safe_integer_product(data, 'update_time', 1000)
4034
+ # fetchMarginAdjustmentHistory
4035
+ #
4036
+ # {
4037
+ # bkr_price: '0',
4038
+ # leverage: '3',
4039
+ # liq_price: '0',
4040
+ # margin_amount: '5.33236666666666666666',
4041
+ # margin_change: '3',
4042
+ # market: 'XRPUSDT',
4043
+ # position_amount: '11',
4044
+ # position_id: '297155652',
4045
+ # position_type: '2',
4046
+ # settle_price: '0.6361',
4047
+ # time: '1711050906.382891',
4048
+ # type: '1',
4049
+ # user_id: '3685860'
4050
+ # }
4051
+ #
4052
+ marketId = self.safe_string(data, 'market')
4053
+ type = self.safe_string(data, 'type')
4054
+ timestamp = self.safe_integer_product_2(data, 'time', 'update_time', 1000)
4035
4055
  return {
4036
4056
  'info': data,
4037
- 'symbol': self.safe_symbol(None, market),
4038
- 'type': None,
4039
- 'amount': self.safe_number(data, 'margin_amount'),
4040
- 'total': None,
4057
+ 'symbol': self.safe_symbol(marketId, market, None, 'swap'),
4058
+ 'type': 'add' if (type == '1') else 'reduce',
4059
+ 'marginMode': 'isolated',
4060
+ 'amount': self.safe_number(data, 'margin_change'),
4061
+ 'total': self.safe_number(data, 'position_amount'),
4041
4062
  'code': market['quote'],
4042
4063
  'status': None,
4043
4064
  'timestamp': timestamp,
@@ -4645,6 +4666,7 @@ class coinex(Exchange, ImplicitAPI):
4645
4666
  currencyId = self.safe_string(transfer, 'asset')
4646
4667
  currencyCode = self.safe_currency_code(currencyId, currency)
4647
4668
  return {
4669
+ 'info': transfer,
4648
4670
  'id': self.safe_integer(transfer, 'id'),
4649
4671
  'timestamp': timestamp,
4650
4672
  'datetime': self.iso8601(timestamp),
@@ -5411,3 +5433,69 @@ class coinex(Exchange, ImplicitAPI):
5411
5433
  self.throw_exactly_matched_exception(self.exceptions['exact'], code, feedback)
5412
5434
  raise ExchangeError(feedback)
5413
5435
  return None
5436
+
5437
+ async def fetch_margin_adjustment_history(self, symbol: Str = None, type: Str = None, since: Num = None, limit: Num = None, params={}) -> List[MarginModification]:
5438
+ """
5439
+ fetches the history of margin added or reduced from contract isolated positions
5440
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http046_position_margin_history
5441
+ :param str [symbol]: unified market symbol
5442
+ :param str [type]: not used by coinex fetchMarginAdjustmentHistory
5443
+ :param int [since]: timestamp in ms of the earliest change to fetch
5444
+ :param int [limit]: the maximum amount of changes to fetch, default=100, max=100
5445
+ :param dict params: extra parameters specific to the exchange api endpoint
5446
+ :param int [params.until]: timestamp in ms of the latest change to fetch
5447
+ *
5448
+ * EXCHANGE SPECIFIC PARAMETERS
5449
+ :param int [params.offset]: offset
5450
+ :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
5451
+ """
5452
+ await self.load_markets()
5453
+ until = self.safe_integer(params, 'until')
5454
+ params = self.omit(params, 'until')
5455
+ if limit is None:
5456
+ limit = 100
5457
+ request = {
5458
+ 'market': '',
5459
+ 'position_id': 0,
5460
+ 'offset': 0,
5461
+ 'limit': limit,
5462
+ }
5463
+ if symbol is not None:
5464
+ market = self.market(symbol)
5465
+ request['market'] = market['id']
5466
+ if since is not None:
5467
+ request['start_time'] = since
5468
+ if until is not None:
5469
+ request['end_time'] = until
5470
+ response = await self.v1PerpetualPrivateGetPositionMarginHistory(self.extend(request, params))
5471
+ #
5472
+ # {
5473
+ # code: '0',
5474
+ # data: {
5475
+ # limit: '100',
5476
+ # offset: '0',
5477
+ # records: [
5478
+ # {
5479
+ # bkr_price: '0',
5480
+ # leverage: '3',
5481
+ # liq_price: '0',
5482
+ # margin_amount: '5.33236666666666666666',
5483
+ # margin_change: '3',
5484
+ # market: 'XRPUSDT',
5485
+ # position_amount: '11',
5486
+ # position_id: '297155652',
5487
+ # position_type: '2',
5488
+ # settle_price: '0.6361',
5489
+ # time: '1711050906.382891',
5490
+ # type: '1',
5491
+ # user_id: '3685860'
5492
+ # }
5493
+ # ]
5494
+ # },
5495
+ # message: 'OK'
5496
+ # }
5497
+ #
5498
+ data = self.safe_dict(response, 'data', {})
5499
+ records = self.safe_list(data, 'records', [])
5500
+ modifications = self.parse_margin_modifications(records, None, 'market', 'swap')
5501
+ return self.filter_by_symbol_since_limit(modifications, symbol, since, limit)
@@ -81,6 +81,7 @@ class cryptocom(Exchange, ImplicitAPI):
81
81
  'fetchLedger': True,
82
82
  'fetchLeverage': False,
83
83
  'fetchLeverageTiers': False,
84
+ 'fetchMarginAdjustmentHistory': False,
84
85
  'fetchMarginMode': False,
85
86
  'fetchMarketLeverageTiers': False,
86
87
  'fetchMarkets': True,
@@ -2566,6 +2566,7 @@ class delta(Exchange, ImplicitAPI):
2566
2566
  'info': data,
2567
2567
  'symbol': market['symbol'],
2568
2568
  'type': None,
2569
+ 'marginMode': 'isolated',
2569
2570
  'amount': None,
2570
2571
  'total': self.safe_number(data, 'margin'),
2571
2572
  'code': None,
@@ -3851,6 +3851,7 @@ class digifinex(Exchange, ImplicitAPI):
3851
3851
  'info': data,
3852
3852
  'symbol': self.safe_symbol(marketId, market, None, 'swap'),
3853
3853
  'type': 'add' if (rawType == 1) else 'reduce',
3854
+ 'marginMode': 'isolated',
3854
3855
  'amount': self.safe_number(data, 'amount'),
3855
3856
  'total': None,
3856
3857
  'code': market['settle'],
@@ -273,6 +273,7 @@ class exmo(Exchange, ImplicitAPI):
273
273
  'info': data,
274
274
  'symbol': self.safe_symbol(None, market),
275
275
  'type': None,
276
+ 'marginMode': 'isolated',
276
277
  'amount': None,
277
278
  'total': None,
278
279
  'code': self.safe_value(market, 'quote'),
@@ -139,6 +139,7 @@ class gate(Exchange, ImplicitAPI):
139
139
  'fetchLeverages': True,
140
140
  'fetchLeverageTiers': True,
141
141
  'fetchLiquidations': True,
142
+ 'fetchMarginAdjustmentHistory': False,
142
143
  'fetchMarginMode': False,
143
144
  'fetchMarketLeverageTiers': True,
144
145
  'fetchMarkets': True,
@@ -5688,6 +5689,7 @@ class gate(Exchange, ImplicitAPI):
5688
5689
  'info': data,
5689
5690
  'symbol': market['symbol'],
5690
5691
  'type': None,
5692
+ 'marginMode': 'isolated',
5691
5693
  'amount': None,
5692
5694
  'total': total,
5693
5695
  'code': self.safe_value(market, 'quote'),
@@ -122,6 +122,7 @@ class gemini(Exchange, ImplicitAPI):
122
122
  # https://github.com/ccxt/ccxt/issues/7874
123
123
  # https://github.com/ccxt/ccxt/issues/7894
124
124
  'web': 'https://docs.gemini.com',
125
+ 'webExchange': 'https://exchange.gemini.com',
125
126
  },
126
127
  'fees': [
127
128
  'https://gemini.com/api-fee-schedule',
@@ -630,7 +631,7 @@ class gemini(Exchange, ImplicitAPI):
630
631
  quoteId = None
631
632
  settleId = None
632
633
  tickSize = None
633
- increment = None
634
+ amountPrecision = None
634
635
  minSize = None
635
636
  status = None
636
637
  swap = False
@@ -641,9 +642,9 @@ class gemini(Exchange, ImplicitAPI):
641
642
  isArray = (isinstance(response, list))
642
643
  if not isString and not isArray:
643
644
  marketId = self.safe_string_lower(response, 'symbol')
645
+ amountPrecision = self.safe_number(response, 'tick_size') # right, exchange has an imperfect naming and self turns out to be an amount-precision
646
+ tickSize = self.safe_number(response, 'quote_increment') # self is tick-size actually
644
647
  minSize = self.safe_number(response, 'min_order_size')
645
- tickSize = self.safe_number(response, 'tick_size')
646
- increment = self.safe_number(response, 'quote_increment')
647
648
  status = self.parse_market_active(self.safe_string(response, 'status'))
648
649
  baseId = self.safe_string(response, 'base_currency')
649
650
  quoteId = self.safe_string(response, 'quote_currency')
@@ -654,9 +655,9 @@ class gemini(Exchange, ImplicitAPI):
654
655
  marketId = response
655
656
  else:
656
657
  marketId = self.safe_string_lower(response, 0)
657
- minSize = self.safe_number(response, 3)
658
- tickSize = self.parse_number(self.parse_precision(self.safe_string(response, 1)))
659
- increment = self.parse_number(self.parse_precision(self.safe_string(response, 2)))
658
+ tickSize = self.parse_number(self.parse_precision(self.safe_string(response, 1))) # priceTickDecimalPlaces
659
+ amountPrecision = self.parse_number(self.parse_precision(self.safe_string(response, 2))) # quantityTickDecimalPlaces
660
+ minSize = self.safe_number(response, 3) # quantityMinimum
660
661
  marketIdUpper = marketId.upper()
661
662
  isPerp = (marketIdUpper.find('PERP') >= 0)
662
663
  marketIdWithoutPerp = marketIdUpper.replace('PERP', '')
@@ -705,8 +706,8 @@ class gemini(Exchange, ImplicitAPI):
705
706
  'strike': None,
706
707
  'optionType': None,
707
708
  'precision': {
708
- 'price': increment,
709
- 'amount': tickSize,
709
+ 'price': tickSize,
710
+ 'amount': amountPrecision,
710
711
  },
711
712
  'limits': {
712
713
  'leverage': {
@@ -1708,7 +1709,7 @@ class gemini(Exchange, ImplicitAPI):
1708
1709
  apiKey = self.apiKey
1709
1710
  if apiKey.find('account') < 0:
1710
1711
  raise AuthenticationError(self.id + ' sign() requires an account-key, master-keys are not-supported')
1711
- nonce = self.nonce()
1712
+ nonce = str(self.nonce())
1712
1713
  request = self.extend({
1713
1714
  'request': url,
1714
1715
  'nonce': nonce,
@@ -3082,6 +3082,7 @@ class hitbtc(Exchange, ImplicitAPI):
3082
3082
  'info': data,
3083
3083
  'symbol': market['symbol'],
3084
3084
  'type': None,
3085
+ 'marginMode': 'isolated',
3085
3086
  'amount': None,
3086
3087
  'total': None,
3087
3088
  'code': self.safe_string(currencyInfo, 'code'),
ccxt/async_support/htx.py CHANGED
@@ -103,6 +103,7 @@ class htx(Exchange, ImplicitAPI):
103
103
  'fetchLeverage': False,
104
104
  'fetchLeverageTiers': True,
105
105
  'fetchLiquidations': True,
106
+ 'fetchMarginAdjustmentHistory': False,
106
107
  'fetchMarketLeverageTiers': True,
107
108
  'fetchMarkets': True,
108
109
  'fetchMarkOHLCV': True,
@@ -2025,6 +2025,7 @@ class hyperliquid(Exchange, ImplicitAPI):
2025
2025
  'info': data,
2026
2026
  'symbol': self.safe_symbol(None, market),
2027
2027
  'type': None,
2028
+ 'marginMode': 'isolated',
2028
2029
  'amount': None,
2029
2030
  'total': None,
2030
2031
  'code': self.safe_string(market, 'settle'),
@@ -93,6 +93,7 @@ class kucoin(Exchange, ImplicitAPI):
93
93
  'fetchL3OrderBook': True,
94
94
  'fetchLedger': True,
95
95
  'fetchLeverageTiers': False,
96
+ 'fetchMarginAdjustmentHistory': False,
96
97
  'fetchMarginMode': False,
97
98
  'fetchMarketLeverageTiers': False,
98
99
  'fetchMarkets': True,
@@ -80,6 +80,7 @@ class kucoinfutures(kucoin, ImplicitAPI):
80
80
  'fetchL3OrderBook': True,
81
81
  'fetchLedger': True,
82
82
  'fetchLeverageTiers': False,
83
+ 'fetchMarginAdjustmentHistory': False,
83
84
  'fetchMarginMode': False,
84
85
  'fetchMarketLeverageTiers': True,
85
86
  'fetchMarkets': True,
@@ -1497,7 +1498,7 @@ class kucoinfutures(kucoin, ImplicitAPI):
1497
1498
  'direction': 'in',
1498
1499
  })
1499
1500
 
1500
- def parse_margin_modification(self, info, market: Market = None):
1501
+ def parse_margin_modification(self, info, market: Market = None) -> MarginModification:
1501
1502
  #
1502
1503
  # {
1503
1504
  # "id": "62311d26064e8f00013f2c6d",
@@ -1549,14 +1550,18 @@ class kucoinfutures(kucoin, ImplicitAPI):
1549
1550
  crossMode = self.safe_value(info, 'crossMode')
1550
1551
  mode = 'cross' if crossMode else 'isolated'
1551
1552
  marketId = self.safe_string(market, 'symbol')
1553
+ timestamp = self.safe_integer(info, 'currentTimestamp')
1552
1554
  return {
1553
1555
  'info': info,
1554
- 'direction': None,
1555
- 'mode': mode,
1556
+ 'symbol': self.safe_symbol(marketId, market),
1557
+ 'type': None,
1558
+ 'marginMode': mode,
1556
1559
  'amount': None,
1560
+ 'total': None,
1557
1561
  'code': self.safe_currency_code(currencyId),
1558
- 'symbol': self.safe_symbol(marketId, market),
1559
1562
  'status': None,
1563
+ 'timestamp': timestamp,
1564
+ 'datetime': self.iso8601(timestamp),
1560
1565
  }
1561
1566
 
1562
1567
  async def fetch_orders_by_status(self, status, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
@@ -1682,6 +1687,29 @@ class kucoinfutures(kucoin, ImplicitAPI):
1682
1687
  return await self.fetch_paginated_call_dynamic('fetchClosedOrders', symbol, since, limit, params)
1683
1688
  return await self.fetch_orders_by_status('done', symbol, since, limit, params)
1684
1689
 
1690
+ async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1691
+ """
1692
+ fetches information on multiple open orders made by the user
1693
+ :see: https://docs.kucoin.com/futures/#get-order-list
1694
+ :see: https://docs.kucoin.com/futures/#get-untriggered-stop-order-list
1695
+ :param str symbol: unified market symbol of the market orders were made in
1696
+ :param int [since]: the earliest time in ms to fetch orders for
1697
+ :param int [limit]: the maximum number of order structures to retrieve
1698
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1699
+ :param int [params.till]: end time in ms
1700
+ :param str [params.side]: buy or sell
1701
+ :param str [params.type]: limit, or market
1702
+ :param boolean [params.trigger]: set to True to retrieve untriggered stop orders
1703
+ :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)
1704
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1705
+ """
1706
+ await self.load_markets()
1707
+ paginate = False
1708
+ paginate, params = self.handle_option_and_params(params, 'fetchOpenOrders', 'paginate')
1709
+ if paginate:
1710
+ return await self.fetch_paginated_call_dynamic('fetchOpenOrders', symbol, since, limit, params)
1711
+ return await self.fetch_orders_by_status('open', symbol, since, limit, params)
1712
+
1685
1713
  async def fetch_order(self, id: Str = None, symbol: Str = None, params={}):
1686
1714
  """
1687
1715
  fetches information on an order made by the user
@@ -89,6 +89,7 @@ class mexc(Exchange, ImplicitAPI):
89
89
  'fetchLeverage': True,
90
90
  'fetchLeverages': False,
91
91
  'fetchLeverageTiers': True,
92
+ 'fetchMarginAdjustmentHistory': False,
92
93
  'fetchMarginMode': False,
93
94
  'fetchMarketLeverageTiers': None,
94
95
  'fetchMarkets': True,
ccxt/async_support/okx.py CHANGED
@@ -107,6 +107,7 @@ class okx(Exchange, ImplicitAPI):
107
107
  'fetchLedgerEntry': None,
108
108
  'fetchLeverage': True,
109
109
  'fetchLeverageTiers': False,
110
+ 'fetchMarginAdjustmentHistory': True,
110
111
  'fetchMarketLeverageTiers': True,
111
112
  'fetchMarkets': True,
112
113
  'fetchMarkOHLCV': True,
@@ -6036,9 +6037,9 @@ class okx(Exchange, ImplicitAPI):
6036
6037
  # }
6037
6038
  #
6038
6039
  data = self.safe_list(response, 'data', [])
6040
+ entry = self.safe_dict(data, 0, {})
6039
6041
  errorCode = self.safe_string(response, 'code')
6040
- item = self.safe_dict(data, 0, {})
6041
- return self.extend(self.parse_margin_modification(item, market), {
6042
+ return self.extend(self.parse_margin_modification(entry, market), {
6042
6043
  'status': 'ok' if (errorCode == '0') else 'failed',
6043
6044
  })
6044
6045
 
@@ -6053,22 +6054,66 @@ class okx(Exchange, ImplicitAPI):
6053
6054
  # "type": "reduce"
6054
6055
  # }
6055
6056
  #
6056
- amountRaw = self.safe_number(data, 'amt')
6057
+ # fetchMarginAdjustmentHistory
6058
+ #
6059
+ # {
6060
+ # bal: '67621.4325135010619812',
6061
+ # balChg: '-10.0000000000000000',
6062
+ # billId: '691293628710342659',
6063
+ # ccy: 'USDT',
6064
+ # clOrdId: '',
6065
+ # execType: '',
6066
+ # fee: '0',
6067
+ # fillFwdPx: '',
6068
+ # fillIdxPx: '',
6069
+ # fillMarkPx: '',
6070
+ # fillMarkVol: '',
6071
+ # fillPxUsd: '',
6072
+ # fillPxVol: '',
6073
+ # fillTime: '1711089244850',
6074
+ # from: '',
6075
+ # instId: 'XRP-USDT-SWAP',
6076
+ # instType: 'SWAP',
6077
+ # interest: '0',
6078
+ # mgnMode: 'isolated',
6079
+ # notes: '',
6080
+ # ordId: '',
6081
+ # pnl: '0',
6082
+ # posBal: '73.12',
6083
+ # posBalChg: '10.00',
6084
+ # px: '',
6085
+ # subType: '160',
6086
+ # sz: '10',
6087
+ # tag: '',
6088
+ # to: '',
6089
+ # tradeId: '0',
6090
+ # ts: '1711089244699',
6091
+ # type: '6'
6092
+ # }
6093
+ #
6094
+ amountRaw = self.safe_string_2(data, 'amt', 'posBalChg')
6057
6095
  typeRaw = self.safe_string(data, 'type')
6058
- type = 'reduce' if (typeRaw == 'reduce') else 'add'
6096
+ type = None
6097
+ if typeRaw == '6':
6098
+ type = 'add' if Precise.string_gt(amountRaw, '0') else 'reduce'
6099
+ else:
6100
+ type = typeRaw
6101
+ amount = Precise.string_abs(amountRaw)
6059
6102
  marketId = self.safe_string(data, 'instId')
6060
6103
  responseMarket = self.safe_market(marketId, market)
6061
6104
  code = responseMarket['base'] if responseMarket['inverse'] else responseMarket['quote']
6105
+ timestamp = self.safe_integer(data, 'ts')
6062
6106
  return {
6063
6107
  'info': data,
6064
6108
  'symbol': responseMarket['symbol'],
6065
6109
  'type': type,
6066
- 'amount': amountRaw,
6067
- 'total': None,
6110
+ 'marginMode': 'isolated',
6111
+ 'amount': self.parse_number(amount),
6068
6112
  'code': code,
6113
+ 'total': None,
6069
6114
  'status': None,
6070
- 'timestamp': None,
6071
- 'datetime': None,
6115
+ 'timestamp': timestamp,
6116
+ 'datetime': self.iso8601(timestamp),
6072
6117
  }
6073
6118
 
6074
6119
  async def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
@@ -7089,3 +7134,93 @@ class okx(Exchange, ImplicitAPI):
7089
7134
  self.throw_exactly_matched_exception(self.exceptions['exact'], code, feedback)
7090
7135
  raise ExchangeError(feedback) # unknown message
7091
7136
  return None
7137
+
7138
+ async def fetch_margin_adjustment_history(self, symbol: Str = None, type: Str = None, since: Num = None, limit: Num = None, params={}) -> List[MarginModification]:
7139
+ """
7140
+ fetches the history of margin added or reduced from contract isolated positions
7141
+ :see: https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-7-days
7142
+ :see: https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months
7143
+ :param str [symbol]: not used by okx fetchMarginAdjustmentHistory
7144
+ :param str [type]: "add" or "reduce"
7145
+ :param dict params: extra parameters specific to the exchange api endpoint
7146
+ :param boolean [params.auto]: True if fetching auto margin increases
7147
+ :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
7148
+ """
7149
+ await self.load_markets()
7150
+ auto = self.safe_bool(params, 'auto')
7151
+ if type is None:
7152
+ raise ArgumentsRequired(self.id + ' fetchMarginAdjustmentHistory() requires a type argument')
7153
+ isAdd = type == 'add'
7154
+ subType = '160' if isAdd else '161'
7155
+ if auto:
7156
+ if isAdd:
7157
+ subType = '162'
7158
+ else:
7159
+ raise BadRequest(self.id + ' cannot fetch margin adjustments for type ' + type)
7160
+ request = {
7161
+ 'subType': subType,
7162
+ 'mgnMode': 'isolated',
7163
+ }
7164
+ until = self.safe_integer(params, 'until')
7165
+ params = self.omit(params, 'until')
7166
+ if since is not None:
7167
+ request['startTime'] = since
7168
+ if limit is not None:
7169
+ request['limit'] = limit
7170
+ if until is not None:
7171
+ request['endTime'] = until
7172
+ response = None
7173
+ now = self.milliseconds()
7174
+ oneWeekAgo = now - 604800000
7175
+ threeMonthsAgo = now - 7776000000
7176
+ if (since is None) or (since > oneWeekAgo):
7177
+ response = await self.privateGetAccountBills(self.extend(request, params))
7178
+ elif since > threeMonthsAgo:
7179
+ response = await self.privateGetAccountBillsArchive(self.extend(request, params))
7180
+ else:
7181
+ raise BadRequest(self.id + ' fetchMarginAdjustmentHistory() cannot fetch margin adjustments older than 3 months')
7182
+ #
7183
+ # {
7184
+ # code: '0',
7185
+ # data: [
7186
+ # {
7187
+ # bal: '67621.4325135010619812',
7188
+ # balChg: '-10.0000000000000000',
7189
+ # billId: '691293628710342659',
7190
+ # ccy: 'USDT',
7191
+ # clOrdId: '',
7192
+ # execType: '',
7193
+ # fee: '0',
7194
+ # fillFwdPx: '',
7195
+ # fillIdxPx: '',
7196
+ # fillMarkPx: '',
7197
+ # fillMarkVol: '',
7198
+ # fillPxUsd: '',
7199
+ # fillPxVol: '',
7200
+ # fillTime: '1711089244850',
7201
+ # from: '',
7202
+ # instId: 'XRP-USDT-SWAP',
7203
+ # instType: 'SWAP',
7204
+ # interest: '0',
7205
+ # mgnMode: 'isolated',
7206
+ # notes: '',
7207
+ # ordId: '',
7208
+ # pnl: '0',
7209
+ # posBal: '73.12',
7210
+ # posBalChg: '10.00',
7211
+ # px: '',
7212
+ # subType: '160',
7213
+ # sz: '10',
7214
+ # tag: '',
7215
+ # to: '',
7216
+ # tradeId: '0',
7217
+ # ts: '1711089244699',
7218
+ # type: '6'
7219
+ # }
7220
+ # ],
7221
+ # msg: ''
7222
+ # }
7223
+ #
7224
+ data = self.safe_list(response, 'data')
7225
+ modifications = self.parse_margin_modifications(data)
7226
+ return self.filter_by_symbol_since_limit(modifications, symbol, since, limit)
@@ -3792,6 +3792,7 @@ class phemex(Exchange, ImplicitAPI):
3792
3792
  'info': data,
3793
3793
  'symbol': self.safe_symbol(None, market),
3794
3794
  'type': 'set',
3795
+ 'marginMode': 'isolated',
3795
3796
  'amount': None,
3796
3797
  'total': None,
3797
3798
  'code': market[codeCurrency],
ccxt/async_support/woo.py CHANGED
@@ -77,6 +77,7 @@ class woo(Exchange, ImplicitAPI):
77
77
  'fetchIndexOHLCV': False,
78
78
  'fetchLedger': True,
79
79
  'fetchLeverage': True,
80
+ 'fetchMarginAdjustmentHistory': False,
80
81
  'fetchMarginMode': False,
81
82
  'fetchMarkets': True,
82
83
  'fetchMarkOHLCV': False,