ccxt 4.2.78__py2.py3-none-any.whl → 4.2.80__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 (58) hide show
  1. ccxt/__init__.py +1 -1
  2. ccxt/abstract/bingx.py +1 -0
  3. ccxt/abstract/gate.py +1 -0
  4. ccxt/abstract/gateio.py +1 -0
  5. ccxt/abstract/upbit.py +1 -0
  6. ccxt/async_support/__init__.py +1 -1
  7. ccxt/async_support/base/exchange.py +10 -1
  8. ccxt/async_support/base/ws/functions.py +1 -1
  9. ccxt/async_support/binance.py +3 -3
  10. ccxt/async_support/bingx.py +37 -5
  11. ccxt/async_support/bitstamp.py +20 -26
  12. ccxt/async_support/bybit.py +92 -0
  13. ccxt/async_support/coinbaseinternational.py +2 -2
  14. ccxt/async_support/deribit.py +152 -1
  15. ccxt/async_support/gate.py +11 -4
  16. ccxt/async_support/hyperliquid.py +42 -9
  17. ccxt/async_support/mexc.py +2 -2
  18. ccxt/async_support/upbit.py +2 -0
  19. ccxt/base/exchange.py +38 -9
  20. ccxt/base/types.py +23 -0
  21. ccxt/binance.py +3 -3
  22. ccxt/bingx.py +37 -5
  23. ccxt/bitstamp.py +20 -26
  24. ccxt/bybit.py +92 -0
  25. ccxt/coinbaseinternational.py +2 -2
  26. ccxt/deribit.py +152 -1
  27. ccxt/gate.py +11 -4
  28. ccxt/hyperliquid.py +42 -9
  29. ccxt/mexc.py +2 -2
  30. ccxt/pro/__init__.py +1 -1
  31. ccxt/pro/alpaca.py +1 -1
  32. ccxt/pro/binance.py +5 -5
  33. ccxt/pro/bitfinex2.py +1 -1
  34. ccxt/pro/bitget.py +1 -1
  35. ccxt/pro/bitmart.py +1 -1
  36. ccxt/pro/bitmex.py +1 -1
  37. ccxt/pro/bitopro.py +2 -1
  38. ccxt/pro/blockchaincom.py +1 -1
  39. ccxt/pro/bybit.py +14 -1
  40. ccxt/pro/cex.py +9 -5
  41. ccxt/pro/cryptocom.py +1 -1
  42. ccxt/pro/gemini.py +4 -3
  43. ccxt/pro/hitbtc.py +1 -1
  44. ccxt/pro/htx.py +1 -1
  45. ccxt/pro/okcoin.py +1 -1
  46. ccxt/pro/onetrading.py +1 -1
  47. ccxt/pro/phemex.py +6 -1
  48. ccxt/pro/woo.py +30 -0
  49. ccxt/test/base/test_ohlcv.py +3 -2
  50. ccxt/test/base/test_shared_methods.py +8 -0
  51. ccxt/test/base/test_ticker.py +7 -1
  52. ccxt/test/test_async.py +26 -25
  53. ccxt/test/test_sync.py +26 -25
  54. ccxt/upbit.py +2 -0
  55. {ccxt-4.2.78.dist-info → ccxt-4.2.80.dist-info}/METADATA +6 -6
  56. {ccxt-4.2.78.dist-info → ccxt-4.2.80.dist-info}/RECORD +58 -58
  57. {ccxt-4.2.78.dist-info → ccxt-4.2.80.dist-info}/WHEEL +0 -0
  58. {ccxt-4.2.78.dist-info → ccxt-4.2.80.dist-info}/top_level.txt +0 -0
ccxt/__init__.py CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  # ----------------------------------------------------------------------------
24
24
 
25
- __version__ = '4.2.78'
25
+ __version__ = '4.2.80'
26
26
 
27
27
  # ----------------------------------------------------------------------------
28
28
 
ccxt/abstract/bingx.py CHANGED
@@ -32,6 +32,7 @@ class ImplicitAPI:
32
32
  swap_v1_private_get_trade_batchcancelreplace = swapV1PrivateGetTradeBatchCancelReplace = Entry('trade/batchCancelReplace', ['swap', 'v1', 'private'], 'GET', {'cost': 1})
33
33
  swap_v1_private_post_trade_cancelreplace = swapV1PrivatePostTradeCancelReplace = Entry('trade/cancelReplace', ['swap', 'v1', 'private'], 'POST', {'cost': 1})
34
34
  swap_v1_private_post_positionside_dual = swapV1PrivatePostPositionSideDual = Entry('positionSide/dual', ['swap', 'v1', 'private'], 'POST', {'cost': 1})
35
+ swap_v1_private_post_trade_closeposition = swapV1PrivatePostTradeClosePosition = Entry('trade/closePosition', ['swap', 'v1', 'private'], 'POST', {'cost': 1})
35
36
  swap_v2_public_get_server_time = swapV2PublicGetServerTime = Entry('server/time', ['swap', 'v2', 'public'], 'GET', {'cost': 3})
36
37
  swap_v2_public_get_quote_contracts = swapV2PublicGetQuoteContracts = Entry('quote/contracts', ['swap', 'v2', 'public'], 'GET', {'cost': 1})
37
38
  swap_v2_public_get_quote_price = swapV2PublicGetQuotePrice = Entry('quote/price', ['swap', 'v2', 'public'], 'GET', {'cost': 1})
ccxt/abstract/gate.py CHANGED
@@ -91,6 +91,7 @@ class ImplicitAPI:
91
91
  private_unified_get_loan_records = privateUnifiedGetLoanRecords = Entry('loan_records', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
92
92
  private_unified_get_interest_records = privateUnifiedGetInterestRecords = Entry('interest_records', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
93
93
  private_unified_get_estimate_rate = privateUnifiedGetEstimateRate = Entry('estimate_rate', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
94
+ private_unified_get_currency_discount_tiers = privateUnifiedGetCurrencyDiscountTiers = Entry('currency_discount_tiers', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
94
95
  private_unified_post_account_mode = privateUnifiedPostAccountMode = Entry('account_mode', ['private', 'unified'], 'POST', {'cost': 1.3333333333333333})
95
96
  private_unified_post_loans = privateUnifiedPostLoans = Entry('loans', ['private', 'unified'], 'POST', {'cost': 13.333333333333334})
96
97
  private_spot_get_fee = privateSpotGetFee = Entry('fee', ['private', 'spot'], 'GET', {'cost': 1})
ccxt/abstract/gateio.py CHANGED
@@ -91,6 +91,7 @@ class ImplicitAPI:
91
91
  private_unified_get_loan_records = privateUnifiedGetLoanRecords = Entry('loan_records', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
92
92
  private_unified_get_interest_records = privateUnifiedGetInterestRecords = Entry('interest_records', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
93
93
  private_unified_get_estimate_rate = privateUnifiedGetEstimateRate = Entry('estimate_rate', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
94
+ private_unified_get_currency_discount_tiers = privateUnifiedGetCurrencyDiscountTiers = Entry('currency_discount_tiers', ['private', 'unified'], 'GET', {'cost': 1.3333333333333333})
94
95
  private_unified_post_account_mode = privateUnifiedPostAccountMode = Entry('account_mode', ['private', 'unified'], 'POST', {'cost': 1.3333333333333333})
95
96
  private_unified_post_loans = privateUnifiedPostLoans = Entry('loans', ['private', 'unified'], 'POST', {'cost': 13.333333333333334})
96
97
  private_spot_get_fee = privateSpotGetFee = Entry('fee', ['private', 'spot'], 'GET', {'cost': 1})
ccxt/abstract/upbit.py CHANGED
@@ -9,6 +9,7 @@ class ImplicitAPI:
9
9
  public_get_candles_minutes_1 = publicGetCandlesMinutes1 = Entry('candles/minutes/1', 'public', 'GET', {})
10
10
  public_get_candles_minutes_3 = publicGetCandlesMinutes3 = Entry('candles/minutes/3', 'public', 'GET', {})
11
11
  public_get_candles_minutes_5 = publicGetCandlesMinutes5 = Entry('candles/minutes/5', 'public', 'GET', {})
12
+ public_get_candles_minutes_10 = publicGetCandlesMinutes10 = Entry('candles/minutes/10', 'public', 'GET', {})
12
13
  public_get_candles_minutes_15 = publicGetCandlesMinutes15 = Entry('candles/minutes/15', 'public', 'GET', {})
13
14
  public_get_candles_minutes_30 = publicGetCandlesMinutes30 = Entry('candles/minutes/30', 'public', 'GET', {})
14
15
  public_get_candles_minutes_60 = publicGetCandlesMinutes60 = Entry('candles/minutes/60', 'public', 'GET', {})
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.2.78'
7
+ __version__ = '4.2.80'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  # -----------------------------------------------------------------------------
4
4
 
5
- __version__ = '4.2.78'
5
+ __version__ = '4.2.80'
6
6
 
7
7
  # -----------------------------------------------------------------------------
8
8
 
@@ -982,6 +982,9 @@ class Exchange(BaseExchange):
982
982
  async def fetch_order_books(self, symbols: List[str] = None, limit: Int = None, params={}):
983
983
  raise NotSupported(self.id + ' fetchOrderBooks() is not supported yet')
984
984
 
985
+ async def watch_bids_asks(self, symbols: List[str] = None, params={}):
986
+ raise NotSupported(self.id + ' watchBidsAsks() is not supported yet')
987
+
985
988
  async def watch_tickers(self, symbols: List[str] = None, params={}):
986
989
  raise NotSupported(self.id + ' watchTickers() is not supported yet')
987
990
 
@@ -1284,6 +1287,12 @@ class Exchange(BaseExchange):
1284
1287
  async def fetch_greeks(self, symbol: str, params={}):
1285
1288
  raise NotSupported(self.id + ' fetchGreeks() is not supported yet')
1286
1289
 
1290
+ async def fetch_option_chain(self, code: str, params={}):
1291
+ raise NotSupported(self.id + ' fetchOptionChain() is not supported yet')
1292
+
1293
+ async def fetch_option(self, symbol: str, params={}):
1294
+ raise NotSupported(self.id + ' fetchOption() is not supported yet')
1295
+
1287
1296
  async def fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
1288
1297
  """
1289
1298
  fetch history of deposits and withdrawals
@@ -34,7 +34,7 @@ def iso8601(timestamp=None):
34
34
  if int(timestamp) < 0:
35
35
  return None
36
36
  try:
37
- utc = datetime.datetime.utcfromtimestamp(timestamp // 1000)
37
+ utc = datetime.datetime.fromtimestamp(timestamp // 1000, datetime.timezone.utc)
38
38
  return utc.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-6] + "{:03d}".format(int(timestamp) % 1000) + 'Z'
39
39
  except (TypeError, OverflowError, OSError):
40
40
  return None
@@ -2423,13 +2423,13 @@ class binance(Exchange, ImplicitAPI):
2423
2423
  },
2424
2424
  })
2425
2425
 
2426
- def is_inverse(self, type, subType=None) -> bool:
2426
+ def is_inverse(self, type: str, subType: Str = None) -> bool:
2427
2427
  if subType is None:
2428
- return type == 'delivery'
2428
+ return(type == 'delivery')
2429
2429
  else:
2430
2430
  return subType == 'inverse'
2431
2431
 
2432
- def is_linear(self, type, subType=None) -> bool:
2432
+ def is_linear(self, type: str, subType: Str = None) -> bool:
2433
2433
  if subType is None:
2434
2434
  return(type == 'future') or (type == 'swap')
2435
2435
  else:
@@ -196,6 +196,7 @@ class bingx(Exchange, ImplicitAPI):
196
196
  'post': {
197
197
  'trade/cancelReplace': 1,
198
198
  'positionSide/dual': 1,
199
+ 'trade/closePosition': 1,
199
200
  },
200
201
  },
201
202
  },
@@ -2032,6 +2033,8 @@ class bingx(Exchange, ImplicitAPI):
2032
2033
  'SELL': 'sell',
2033
2034
  'SHORT': 'sell',
2034
2035
  'LONG': 'buy',
2036
+ 'ask': 'sell',
2037
+ 'bid': 'buy',
2035
2038
  }
2036
2039
  return self.safe_string(sides, side, side)
2037
2040
 
@@ -3656,14 +3659,43 @@ class bingx(Exchange, ImplicitAPI):
3656
3659
  :param str symbol: Unified CCXT market symbol
3657
3660
  :param str [side]: not used by bingx
3658
3661
  :param dict [params]: extra parameters specific to the bingx api endpoint
3662
+ :param str|None [params.positionId]: it is recommended to hasattr(self, fill) parameter when closing a position
3659
3663
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3660
3664
  """
3661
3665
  await self.load_markets()
3662
- market = self.market(symbol)
3663
- request: dict = {
3664
- 'symbol': market['id'],
3665
- }
3666
- response = await self.swapV2PrivatePostTradeCloseAllPositions(self.extend(request, params))
3666
+ positionId = self.safe_string(params, 'positionId')
3667
+ params = self.omit(params, 'positionId')
3668
+ response = None
3669
+ if positionId is not None:
3670
+ request: dict = {
3671
+ 'positionId': positionId,
3672
+ }
3673
+ response = await self.swapV1PrivatePostTradeClosePosition(self.extend(request, params))
3674
+ else:
3675
+ market = self.market(symbol)
3676
+ request: dict = {
3677
+ 'symbol': market['id'],
3678
+ }
3679
+ response = await self.swapV2PrivatePostTradeCloseAllPositions(self.extend(request, params))
3680
+ #
3681
+ # swapV1PrivatePostTradeClosePosition
3682
+ #
3683
+ # {
3684
+ # "code": 0,
3685
+ # "msg": "",
3686
+ # "timestamp": 1710992264190,
3687
+ # "data": {
3688
+ # "orderId": 1770656007907930112,
3689
+ # "positionId": "1751667128353910784",
3690
+ # "symbol": "LTC-USDT",
3691
+ # "side": "Ask",
3692
+ # "type": "MARKET",
3693
+ # "positionSide": "Long",
3694
+ # "origQty": "0.2"
3695
+ # }
3696
+ # }
3697
+ #
3698
+ # swapV2PrivatePostTradeCloseAllPositions
3667
3699
  #
3668
3700
  # {
3669
3701
  # "code": 0,
@@ -1082,16 +1082,17 @@ class bitstamp(Exchange, ImplicitAPI):
1082
1082
  'timestamp': None,
1083
1083
  'datetime': None,
1084
1084
  }
1085
- codes = list(self.currencies.keys())
1086
- for i in range(0, len(codes)):
1087
- code = codes[i]
1088
- currency = self.currency(code)
1089
- currencyId = currency['id']
1085
+ if response is None:
1086
+ response = []
1087
+ for i in range(0, len(response)):
1088
+ currencyBalance = response[i]
1089
+ currencyId = self.safe_string(currencyBalance, 'currency')
1090
+ currencyCode = self.safe_currency_code(currencyId)
1090
1091
  account = self.account()
1091
- account['free'] = self.safe_string(response, currencyId + '_available')
1092
- account['used'] = self.safe_string(response, currencyId + '_reserved')
1093
- account['total'] = self.safe_string(response, currencyId + '_balance')
1094
- result[code] = account
1092
+ account['free'] = self.safe_string(currencyBalance, 'available')
1093
+ account['used'] = self.safe_string(currencyBalance, 'reserved')
1094
+ account['total'] = self.safe_string(currencyBalance, 'total')
1095
+ result[currencyCode] = account
1095
1096
  return self.safe_balance(result)
1096
1097
 
1097
1098
  async def fetch_balance(self, params={}) -> Balances:
@@ -1102,24 +1103,17 @@ class bitstamp(Exchange, ImplicitAPI):
1102
1103
  :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
1103
1104
  """
1104
1105
  await self.load_markets()
1105
- response = await self.privatePostBalance(params)
1106
+ response = await self.privatePostAccountBalances(params)
1106
1107
  #
1107
- # {
1108
- # "aave_available": "0.00000000",
1109
- # "aave_balance": "0.00000000",
1110
- # "aave_reserved": "0.00000000",
1111
- # "aave_withdrawal_fee": "0.07000000",
1112
- # "aavebtc_fee": "0.000",
1113
- # "aaveeur_fee": "0.000",
1114
- # "aaveusd_fee": "0.000",
1115
- # "bat_available": "0.00000000",
1116
- # "bat_balance": "0.00000000",
1117
- # "bat_reserved": "0.00000000",
1118
- # "bat_withdrawal_fee": "5.00000000",
1119
- # "batbtc_fee": "0.000",
1120
- # "bateur_fee": "0.000",
1121
- # "batusd_fee": "0.000",
1122
- # }
1108
+ # [
1109
+ # {
1110
+ # "currency": "usdt",
1111
+ # "total": "7.00000",
1112
+ # "available": "7.00000",
1113
+ # "reserved": "0.00000"
1114
+ # },
1115
+ # ...
1116
+ # ]
1123
1117
  #
1124
1118
  return self.parse_balance(response)
1125
1119
 
@@ -85,6 +85,7 @@ class bybit(Exchange, ImplicitAPI):
85
85
  'fetchDeposits': True,
86
86
  'fetchDepositWithdrawFee': 'emulated',
87
87
  'fetchDepositWithdrawFees': True,
88
+ 'fetchFundingHistory': True,
88
89
  'fetchFundingRate': True, # emulated in exchange
89
90
  'fetchFundingRateHistory': True,
90
91
  'fetchFundingRates': True,
@@ -7540,6 +7541,97 @@ class bybit(Exchange, ImplicitAPI):
7540
7541
  })
7541
7542
  return tiers
7542
7543
 
7544
+ async def fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
7545
+ """
7546
+ fetch the history of funding payments paid and received on self account
7547
+ :see: https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution
7548
+ :param str [symbol]: unified market symbol
7549
+ :param int [since]: the earliest time in ms to fetch funding history for
7550
+ :param int [limit]: the maximum number of funding history structures to retrieve
7551
+ :param dict [params]: extra parameters specific to the exchange API endpoint
7552
+ :param boolean [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)
7553
+ :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
7554
+ """
7555
+ await self.load_markets()
7556
+ paginate = False
7557
+ paginate, params = self.handle_option_and_params(params, 'fetchFundingHistory', 'paginate')
7558
+ if paginate:
7559
+ return await self.fetch_paginated_call_cursor('fetchFundingHistory', symbol, since, limit, params, 'nextPageCursor', 'cursor', None, 100)
7560
+ request = {
7561
+ 'execType': 'Funding',
7562
+ }
7563
+ market: Market = None
7564
+ if symbol is not None:
7565
+ market = self.market(symbol)
7566
+ request['symbol'] = market['id']
7567
+ type = None
7568
+ type, params = self.get_bybit_type('fetchFundingHistory', market, params)
7569
+ request['category'] = type
7570
+ if symbol is not None:
7571
+ request['symbol'] = market['id']
7572
+ if since is not None:
7573
+ request['startTime'] = since
7574
+ if limit is not None:
7575
+ request['size'] = limit
7576
+ else:
7577
+ request['size'] = 100
7578
+ request, params = self.handle_until_option('endTime', request, params)
7579
+ response = await self.privateGetV5ExecutionList(self.extend(request, params))
7580
+ fundings = self.add_pagination_cursor_to_result(response)
7581
+ return self.parse_incomes(fundings, market, since, limit)
7582
+
7583
+ def parse_income(self, income, market: Market = None):
7584
+ #
7585
+ # {
7586
+ # "symbol": "XMRUSDT",
7587
+ # "orderType": "UNKNOWN",
7588
+ # "underlyingPrice": "",
7589
+ # "orderLinkId": "",
7590
+ # "orderId": "a11e5fe2-1dbf-4bab-a9b2-af80a14efc5d",
7591
+ # "stopOrderType": "UNKNOWN",
7592
+ # "execTime": "1710950400000",
7593
+ # "feeCurrency": "",
7594
+ # "createType": "",
7595
+ # "feeRate": "-0.000761",
7596
+ # "tradeIv": "",
7597
+ # "blockTradeId": "",
7598
+ # "markPrice": "136.79",
7599
+ # "execPrice": "137.11",
7600
+ # "markIv": "",
7601
+ # "orderQty": "0",
7602
+ # "orderPrice": "0",
7603
+ # "execValue": "134.3678",
7604
+ # "closedSize": "0",
7605
+ # "execType": "Funding",
7606
+ # "seq": "28097658790",
7607
+ # "side": "Sell",
7608
+ # "indexPrice": "",
7609
+ # "leavesQty": "0",
7610
+ # "isMaker": False,
7611
+ # "execFee": "-0.10232512",
7612
+ # "execId": "8d1ef156-4ec6-4445-9a6c-1c0c24dbd046",
7613
+ # "marketUnit": "",
7614
+ # "execQty": "0.98",
7615
+ # "nextPageCursor": "5774437%3A0%2C5771289%3A0"
7616
+ # }
7617
+ #
7618
+ marketId = self.safe_string(income, 'symbol')
7619
+ market = self.safe_market(marketId, market, None, 'contract')
7620
+ code = 'USDT'
7621
+ if market['inverse']:
7622
+ code = market['quote']
7623
+ timestamp = self.safe_integer(income, 'execTime')
7624
+ return {
7625
+ 'info': income,
7626
+ 'symbol': self.safe_symbol(marketId, market, '-', 'swap'),
7627
+ 'code': code,
7628
+ 'timestamp': timestamp,
7629
+ 'datetime': self.iso8601(timestamp),
7630
+ 'id': self.safe_string(income, 'execId'),
7631
+ 'amount': self.safe_number(income, 'execQty'),
7632
+ 'rate': self.safe_number(income, 'feeRate'),
7633
+ }
7634
+
7543
7635
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
7544
7636
  url = self.implode_hostname(self.urls['api'][api]) + '/' + path
7545
7637
  if api == 'public':
@@ -126,10 +126,10 @@ class coinbaseinternational(Exchange, ImplicitAPI):
126
126
  },
127
127
  'www': 'https://international.coinbase.com',
128
128
  'doc': [
129
- 'https://docs.cloud.coinbaseinternational.com/intx/docs',
129
+ 'https://docs.cloud.coinbase.com/intx/docs',
130
130
  ],
131
131
  'fees': [
132
- 'https://help.coinbaseinternational.com/en/international-exchange/trading-deposits-withdrawals/international-exchange-fees',
132
+ 'https://help.coinbase.com/en/international-exchange/trading-deposits-withdrawals/international-exchange-fees',
133
133
  ],
134
134
  'referral': '',
135
135
  },
@@ -6,7 +6,7 @@
6
6
  from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.deribit import ImplicitAPI
8
8
  import hashlib
9
- from ccxt.base.types import Account, Balances, Currency, Greeks, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
9
+ from ccxt.base.types import Account, Balances, Currency, Greeks, Int, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import PermissionDenied
@@ -83,6 +83,8 @@ class deribit(Exchange, ImplicitAPI):
83
83
  'fetchMyTrades': True,
84
84
  'fetchOHLCV': True,
85
85
  'fetchOpenOrders': True,
86
+ 'fetchOption': True,
87
+ 'fetchOptionChain': True,
86
88
  'fetchOrder': True,
87
89
  'fetchOrderBook': True,
88
90
  'fetchOrders': False,
@@ -3270,6 +3272,155 @@ class deribit(Exchange, ImplicitAPI):
3270
3272
  'info': greeks,
3271
3273
  }
3272
3274
 
3275
+ async def fetch_option(self, symbol: str, params={}) -> Option:
3276
+ """
3277
+ fetches option data that is commonly found in an option chain
3278
+ :see: https://docs.deribit.com/#public-get_book_summary_by_instrument
3279
+ :param str symbol: unified market symbol
3280
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3281
+ :returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
3282
+ """
3283
+ await self.load_markets()
3284
+ market = self.market(symbol)
3285
+ request = {
3286
+ 'instrument_name': market['id'],
3287
+ }
3288
+ response = await self.publicGetGetBookSummaryByInstrument(self.extend(request, params))
3289
+ #
3290
+ # {
3291
+ # "jsonrpc": "2.0",
3292
+ # "result": [
3293
+ # {
3294
+ # "mid_price": 0.04025,
3295
+ # "volume_usd": 11045.12,
3296
+ # "quote_currency": "BTC",
3297
+ # "estimated_delivery_price": 65444.72,
3298
+ # "creation_timestamp": 1711100949273,
3299
+ # "base_currency": "BTC",
3300
+ # "underlying_index": "BTC-27DEC24",
3301
+ # "underlying_price": 73742.14,
3302
+ # "volume": 4.0,
3303
+ # "interest_rate": 0.0,
3304
+ # "price_change": -6.9767,
3305
+ # "open_interest": 274.2,
3306
+ # "ask_price": 0.042,
3307
+ # "bid_price": 0.0385,
3308
+ # "instrument_name": "BTC-27DEC24-240000-C",
3309
+ # "mark_price": 0.04007735,
3310
+ # "last": 0.04,
3311
+ # "low": 0.04,
3312
+ # "high": 0.043
3313
+ # }
3314
+ # ],
3315
+ # "usIn": 1711100949273223,
3316
+ # "usOut": 1711100949273580,
3317
+ # "usDiff": 357,
3318
+ # "testnet": False
3319
+ # }
3320
+ #
3321
+ result = self.safe_list(response, 'result', [])
3322
+ chain = self.safe_dict(result, 0, {})
3323
+ return self.parse_option(chain, None, market)
3324
+
3325
+ async def fetch_option_chain(self, code: str, params={}) -> OptionChain:
3326
+ """
3327
+ fetches data for an underlying asset that is commonly found in an option chain
3328
+ :see: https://docs.deribit.com/#public-get_book_summary_by_currency
3329
+ :param str currency: base currency to fetch an option chain for
3330
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3331
+ :returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
3332
+ """
3333
+ await self.load_markets()
3334
+ currency = self.currency(code)
3335
+ request = {
3336
+ 'currency': currency['id'],
3337
+ 'kind': 'option',
3338
+ }
3339
+ response = await self.publicGetGetBookSummaryByCurrency(self.extend(request, params))
3340
+ #
3341
+ # {
3342
+ # "jsonrpc": "2.0",
3343
+ # "result": [
3344
+ # {
3345
+ # "mid_price": 0.4075,
3346
+ # "volume_usd": 2836.83,
3347
+ # "quote_currency": "BTC",
3348
+ # "estimated_delivery_price": 65479.26,
3349
+ # "creation_timestamp": 1711101594477,
3350
+ # "base_currency": "BTC",
3351
+ # "underlying_index": "BTC-28JUN24",
3352
+ # "underlying_price": 68827.27,
3353
+ # "volume": 0.1,
3354
+ # "interest_rate": 0.0,
3355
+ # "price_change": 0.0,
3356
+ # "open_interest": 364.1,
3357
+ # "ask_price": 0.411,
3358
+ # "bid_price": 0.404,
3359
+ # "instrument_name": "BTC-28JUN24-42000-C",
3360
+ # "mark_price": 0.40752052,
3361
+ # "last": 0.423,
3362
+ # "low": 0.423,
3363
+ # "high": 0.423
3364
+ # }
3365
+ # ],
3366
+ # "usIn": 1711101594456388,
3367
+ # "usOut": 1711101594484065,
3368
+ # "usDiff": 27677,
3369
+ # "testnet": False
3370
+ # }
3371
+ #
3372
+ result = self.safe_list(response, 'result', [])
3373
+ return self.parse_option_chain(result, 'base_currency', 'instrument_name')
3374
+
3375
+ def parse_option(self, chain, currency: Currency = None, market: Market = None):
3376
+ #
3377
+ # {
3378
+ # "mid_price": 0.04025,
3379
+ # "volume_usd": 11045.12,
3380
+ # "quote_currency": "BTC",
3381
+ # "estimated_delivery_price": 65444.72,
3382
+ # "creation_timestamp": 1711100949273,
3383
+ # "base_currency": "BTC",
3384
+ # "underlying_index": "BTC-27DEC24",
3385
+ # "underlying_price": 73742.14,
3386
+ # "volume": 4.0,
3387
+ # "interest_rate": 0.0,
3388
+ # "price_change": -6.9767,
3389
+ # "open_interest": 274.2,
3390
+ # "ask_price": 0.042,
3391
+ # "bid_price": 0.0385,
3392
+ # "instrument_name": "BTC-27DEC24-240000-C",
3393
+ # "mark_price": 0.04007735,
3394
+ # "last": 0.04,
3395
+ # "low": 0.04,
3396
+ # "high": 0.043
3397
+ # }
3398
+ #
3399
+ marketId = self.safe_string(chain, 'instrument_name')
3400
+ market = self.safe_market(marketId, market)
3401
+ currencyId = self.safe_string(chain, 'base_currency')
3402
+ code = self.safe_currency_code(currencyId, currency)
3403
+ timestamp = self.safe_integer(chain, 'timestamp')
3404
+ return {
3405
+ 'info': chain,
3406
+ 'currency': code['code'],
3407
+ 'symbol': market['symbol'],
3408
+ 'timestamp': timestamp,
3409
+ 'datetime': self.iso8601(timestamp),
3410
+ 'impliedVolatility': None,
3411
+ 'openInterest': self.safe_number(chain, 'open_interest'),
3412
+ 'bidPrice': self.safe_number(chain, 'bid_price'),
3413
+ 'askPrice': self.safe_number(chain, 'ask_price'),
3414
+ 'midPrice': self.safe_number(chain, 'mid_price'),
3415
+ 'markPrice': self.safe_number(chain, 'mark_price'),
3416
+ 'lastPrice': self.safe_number(chain, 'last'),
3417
+ 'underlyingPrice': self.safe_number(chain, 'underlying_price'),
3418
+ 'change': None,
3419
+ 'percentage': self.safe_number(chain, 'price_change'),
3420
+ 'baseVolume': self.safe_number(chain, 'volume'),
3421
+ 'quoteVolume': self.safe_number(chain, 'volume_usd'),
3422
+ }
3423
+
3273
3424
  def nonce(self):
3274
3425
  return self.milliseconds()
3275
3426
 
@@ -329,6 +329,7 @@ class gate(Exchange, ImplicitAPI):
329
329
  'loan_records': 20 / 15,
330
330
  'interest_records': 20 / 15,
331
331
  'estimate_rate': 20 / 15,
332
+ 'currency_discount_tiers': 20 / 15,
332
333
  },
333
334
  'post': {
334
335
  'account_mode': 20 / 15,
@@ -3959,7 +3960,13 @@ class gate(Exchange, ImplicitAPI):
3959
3960
  'account': account,
3960
3961
  }
3961
3962
  if amount is not None:
3962
- request['amount'] = self.amount_to_precision(symbol, amount)
3963
+ if market['spot']:
3964
+ request['amount'] = self.amount_to_precision(symbol, amount)
3965
+ else:
3966
+ if side == 'sell':
3967
+ request['size'] = Precise.string_neg(self.amount_to_precision(symbol, amount))
3968
+ else:
3969
+ request['size'] = self.amount_to_precision(symbol, amount)
3963
3970
  if price is not None:
3964
3971
  request['price'] = self.price_to_precision(symbol, price)
3965
3972
  response = None
@@ -4689,8 +4696,8 @@ class gate(Exchange, ImplicitAPI):
4689
4696
  """
4690
4697
  await self.load_markets()
4691
4698
  market = None if (symbol is None) else self.market(symbol)
4692
- stop = self.safe_value(params, 'stop')
4693
- params = self.omit(params, 'stop')
4699
+ stop = self.safe_bool_2(params, 'stop', 'trigger')
4700
+ params = self.omit(params, ['stop', 'trigger'])
4694
4701
  type, query = self.handle_market_type_and_params('cancelAllOrders', market, params)
4695
4702
  request, requestParams = self.multi_order_spot_prepare_request(market, stop, query) if (type == 'spot') else self.prepare_request(market, type, query)
4696
4703
  response = None
@@ -4984,7 +4991,7 @@ class gate(Exchange, ImplicitAPI):
4984
4991
  'unrealizedPnl': self.parse_number(unrealisedPnl),
4985
4992
  'realizedPnl': self.safe_number(position, 'realised_pnl'),
4986
4993
  'contracts': self.parse_number(Precise.string_abs(size)),
4987
- 'contractSize': self.safe_value(market, 'contractSize'),
4994
+ 'contractSize': self.safe_number(market, 'contractSize'),
4988
4995
  # 'realisedPnl': position['realised_pnl'],
4989
4996
  'marginRatio': None,
4990
4997
  'liquidationPrice': self.safe_number(position, 'liq_price'),