ccxt 4.0.72__py2.py3-none-any.whl → 4.0.73__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.
@@ -130,6 +130,7 @@ class gate(Exchange, ImplicitAPI):
130
130
  'fetchMarketLeverageTiers': 'emulated',
131
131
  'fetchMarkets': True,
132
132
  'fetchMarkOHLCV': True,
133
+ 'fetchMySettlementHistory': True,
133
134
  'fetchMyTrades': True,
134
135
  'fetchNetworkDepositAddress': True,
135
136
  'fetchOHLCV': True,
@@ -834,6 +835,97 @@ class gate(Exchange, ImplicitAPI):
834
835
  super(gate, self).set_sandbox_mode(enable)
835
836
  self.options['sandboxMode'] = enable
836
837
 
838
+ def convert_expire_date(self, date):
839
+ # parse YYMMDD to timestamp
840
+ year = date[0:2]
841
+ month = date[2:4]
842
+ day = date[4:6]
843
+ reconstructedDate = '20' + year + '-' + month + '-' + day + 'T00:00:00Z'
844
+ return reconstructedDate
845
+
846
+ def create_expired_option_market(self, symbol):
847
+ # support expired option contracts
848
+ quote = 'USDT'
849
+ settle = quote
850
+ optionParts = symbol.split('-')
851
+ symbolBase = symbol.split('/')
852
+ marketIdBase = symbol.split('_')
853
+ base = None
854
+ expiry = self.safe_string(optionParts, 1)
855
+ if symbol.find('/') > -1:
856
+ base = self.safe_string(symbolBase, 0)
857
+ else:
858
+ base = self.safe_string(marketIdBase, 0)
859
+ expiry = expiry[2:8] # convert 20230728 to 230728
860
+ strike = self.safe_string(optionParts, 2)
861
+ optionType = self.safe_string(optionParts, 3)
862
+ datetime = self.convert_expire_date(expiry)
863
+ timestamp = self.parse8601(datetime)
864
+ return {
865
+ 'id': base + '_' + quote + '-' + '20' + expiry + '-' + strike + '-' + optionType,
866
+ 'symbol': base + '/' + quote + ':' + settle + '-' + expiry + '-' + strike + '-' + optionType,
867
+ 'base': base,
868
+ 'quote': quote,
869
+ 'settle': settle,
870
+ 'baseId': base,
871
+ 'quoteId': quote,
872
+ 'settleId': settle,
873
+ 'active': False,
874
+ 'type': 'option',
875
+ 'linear': None,
876
+ 'inverse': None,
877
+ 'spot': False,
878
+ 'swap': False,
879
+ 'future': False,
880
+ 'option': True,
881
+ 'margin': False,
882
+ 'contract': True,
883
+ 'contractSize': self.parse_number('1'),
884
+ 'expiry': timestamp,
885
+ 'expiryDatetime': datetime,
886
+ 'optionType': 'call' if (optionType == 'C') else 'put',
887
+ 'strike': self.parse_number(strike),
888
+ 'precision': {
889
+ 'amount': self.parse_number('1'),
890
+ 'price': None,
891
+ },
892
+ 'limits': {
893
+ 'amount': {
894
+ 'min': None,
895
+ 'max': None,
896
+ },
897
+ 'price': {
898
+ 'min': None,
899
+ 'max': None,
900
+ },
901
+ 'cost': {
902
+ 'min': None,
903
+ 'max': None,
904
+ },
905
+ },
906
+ 'info': None,
907
+ }
908
+
909
+ def market(self, symbol):
910
+ if self.markets is None:
911
+ raise ExchangeError(self.id + ' markets not loaded')
912
+ if isinstance(symbol, str):
913
+ if symbol in self.markets:
914
+ return self.markets[symbol]
915
+ elif symbol in self.markets_by_id:
916
+ markets = self.markets_by_id[symbol]
917
+ return markets[0]
918
+ elif (symbol.find('-C') > -1) or (symbol.find('-P') > -1):
919
+ return self.create_expired_option_market(symbol)
920
+ raise BadSymbol(self.id + ' does not have market symbol ' + symbol)
921
+
922
+ def safe_market(self, marketId=None, market=None, delimiter=None, marketType=None):
923
+ isOption = (marketId is not None) and ((marketId.find('-C') > -1) or (marketId.find('-P') > -1))
924
+ if isOption and not (marketId in self.markets_by_id):
925
+ # handle expired option contracts
926
+ return self.create_expired_option_market(marketId)
927
+ return super(gate, self).safe_market(marketId, market, delimiter, marketType)
928
+
837
929
  async def fetch_markets(self, params={}):
838
930
  """
839
931
  retrieves data on all markets for gate
@@ -5401,7 +5493,58 @@ class gate(Exchange, ImplicitAPI):
5401
5493
  sorted = self.sort_by(settlements, 'timestamp')
5402
5494
  return self.filter_by_symbol_since_limit(sorted, symbol, since, limit)
5403
5495
 
5496
+ async def fetch_my_settlement_history(self, symbol: Optional[str] = None, since: Optional[int] = None, limit: Optional[int] = None, params={}):
5497
+ """
5498
+ fetches historical settlement records of the user
5499
+ see https://www.gate.io/docs/developers/apiv4/en/#list-my-options-settlements
5500
+ :param str symbol: unified market symbol of the settlement history
5501
+ :param int [since]: timestamp in ms
5502
+ :param int [limit]: number of records
5503
+ :param dict [params]: exchange specific params
5504
+ :returns dict[]: a list of [settlement history objects]
5505
+ """
5506
+ self.check_required_symbol('fetchMySettlementHistory', symbol)
5507
+ await self.load_markets()
5508
+ market = self.market(symbol)
5509
+ type = None
5510
+ type, params = self.handle_market_type_and_params('fetchMySettlementHistory', market, params)
5511
+ if type != 'option':
5512
+ raise NotSupported(self.id + ' fetchMySettlementHistory() supports option markets only')
5513
+ marketId = market['id']
5514
+ optionParts = marketId.split('-')
5515
+ request = {
5516
+ 'underlying': self.safe_string(optionParts, 0),
5517
+ 'contract': marketId,
5518
+ }
5519
+ if since is not None:
5520
+ request['from'] = since
5521
+ if limit is not None:
5522
+ request['limit'] = limit
5523
+ response = await self.privateOptionsGetMySettlements(self.extend(request, params))
5524
+ #
5525
+ # [
5526
+ # {
5527
+ # "size": -1,
5528
+ # "settle_profit": "0",
5529
+ # "contract": "BTC_USDT-20220624-26000-C",
5530
+ # "strike_price": "26000",
5531
+ # "time": 1656057600,
5532
+ # "settle_price": "20917.461281337048",
5533
+ # "underlying": "BTC_USDT",
5534
+ # "realised_pnl": "-0.00116042",
5535
+ # "fee": "0"
5536
+ # }
5537
+ # ]
5538
+ #
5539
+ result = self.safe_value(response, 'result', {})
5540
+ data = self.safe_value(result, 'list', [])
5541
+ settlements = self.parse_settlements(data, market)
5542
+ sorted = self.sort_by(settlements, 'timestamp')
5543
+ return self.filter_by_symbol_since_limit(sorted, market['symbol'], since, limit)
5544
+
5404
5545
  def parse_settlement(self, settlement, market):
5546
+ #
5547
+ # fetchSettlementHistory
5405
5548
  #
5406
5549
  # {
5407
5550
  # "time": 1685952000,
@@ -5412,6 +5555,20 @@ class gate(Exchange, ImplicitAPI):
5412
5555
  # "strike_price": "25000"
5413
5556
  # }
5414
5557
  #
5558
+ # fetchMySettlementHistory
5559
+ #
5560
+ # {
5561
+ # "size": -1,
5562
+ # "settle_profit": "0",
5563
+ # "contract": "BTC_USDT-20220624-26000-C",
5564
+ # "strike_price": "26000",
5565
+ # "time": 1656057600,
5566
+ # "settle_price": "20917.461281337048",
5567
+ # "underlying": "BTC_USDT",
5568
+ # "realised_pnl": "-0.00116042",
5569
+ # "fee": "0"
5570
+ # }
5571
+ #
5415
5572
  timestamp = self.safe_timestamp(settlement, 'time')
5416
5573
  marketId = self.safe_string(settlement, 'contract')
5417
5574
  return {
@@ -5423,6 +5580,8 @@ class gate(Exchange, ImplicitAPI):
5423
5580
  }
5424
5581
 
5425
5582
  def parse_settlements(self, settlements, market):
5583
+ #
5584
+ # fetchSettlementHistory
5426
5585
  #
5427
5586
  # [
5428
5587
  # {
@@ -5435,6 +5594,22 @@ class gate(Exchange, ImplicitAPI):
5435
5594
  # }
5436
5595
  # ]
5437
5596
  #
5597
+ # fetchMySettlementHistory
5598
+ #
5599
+ # [
5600
+ # {
5601
+ # "size": -1,
5602
+ # "settle_profit": "0",
5603
+ # "contract": "BTC_USDT-20220624-26000-C",
5604
+ # "strike_price": "26000",
5605
+ # "time": 1656057600,
5606
+ # "settle_price": "20917.461281337048",
5607
+ # "underlying": "BTC_USDT",
5608
+ # "realised_pnl": "-0.00116042",
5609
+ # "fee": "0"
5610
+ # }
5611
+ # ]
5612
+ #
5438
5613
  result = []
5439
5614
  for i in range(0, len(settlements)):
5440
5615
  result.append(self.parse_settlement(settlements[i], market))