ccxt 4.0.71__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.
@@ -81,6 +81,7 @@ class bybit(Exchange, ImplicitAPI):
81
81
  'fetchMarketLeverageTiers': True,
82
82
  'fetchMarkets': True,
83
83
  'fetchMarkOHLCV': True,
84
+ 'fetchMySettlementHistory': True,
84
85
  'fetchMyTrades': True,
85
86
  'fetchOHLCV': True,
86
87
  'fetchOpenInterest': True,
@@ -8309,7 +8310,68 @@ class bybit(Exchange, ImplicitAPI):
8309
8310
  sorted = self.sort_by(settlements, 'timestamp')
8310
8311
  return self.filter_by_symbol_since_limit(sorted, market['symbol'], since, limit)
8311
8312
 
8313
+ async def fetch_my_settlement_history(self, symbol: Optional[str] = None, since: Optional[int] = None, limit: Optional[int] = None, params={}):
8314
+ """
8315
+ fetches historical settlement records of the user
8316
+ see https://bybit-exchange.github.io/docs/v5/asset/delivery
8317
+ :param str symbol: unified market symbol of the settlement history
8318
+ :param int [since]: timestamp in ms
8319
+ :param int [limit]: number of records
8320
+ :param dict [params]: exchange specific params
8321
+ :returns dict[]: a list of [settlement history objects]
8322
+ """
8323
+ await self.load_markets()
8324
+ request = {}
8325
+ market = None
8326
+ if symbol is not None:
8327
+ market = self.market(symbol)
8328
+ request['symbol'] = market['id']
8329
+ type = None
8330
+ type, params = self.handle_market_type_and_params('fetchMySettlementHistory', market, params)
8331
+ if type == 'option':
8332
+ request['category'] = 'option'
8333
+ else:
8334
+ subType = None
8335
+ subType, params = self.handle_sub_type_and_params('fetchMySettlementHistory', market, params, 'linear')
8336
+ if subType == 'inverse':
8337
+ raise NotSupported(self.id + ' fetchMySettlementHistory() doesn\'t support inverse markets')
8338
+ request['category'] = 'linear'
8339
+ if limit is not None:
8340
+ request['limit'] = limit
8341
+ response = await self.privateGetV5AssetDeliveryRecord(self.extend(request, params))
8342
+ #
8343
+ # {
8344
+ # "retCode": 0,
8345
+ # "retMsg": "success",
8346
+ # "result": {
8347
+ # "category": "option",
8348
+ # "nextPageCursor": "0%2C3",
8349
+ # "list": [
8350
+ # {
8351
+ # "symbol": "SOL-27JUN23-20-C",
8352
+ # "deliveryPrice": "16.62258889",
8353
+ # "deliveryTime": "1687852800000",
8354
+ # "side": "Buy",
8355
+ # "strike": "20",
8356
+ # "fee": "0.00000000",
8357
+ # "position": "0.01",
8358
+ # "deliveryRpl": "3.5"
8359
+ # },
8360
+ # ]
8361
+ # },
8362
+ # "retExtInfo": {},
8363
+ # "time": 1689043527231
8364
+ # }
8365
+ #
8366
+ result = self.safe_value(response, 'result', {})
8367
+ data = self.safe_value(result, 'list', [])
8368
+ settlements = self.parse_settlements(data, market)
8369
+ sorted = self.sort_by(settlements, 'timestamp')
8370
+ return self.filter_by_symbol_since_limit(sorted, market['symbol'], since, limit)
8371
+
8312
8372
  def parse_settlement(self, settlement, market):
8373
+ #
8374
+ # fetchSettlementHistory
8313
8375
  #
8314
8376
  # {
8315
8377
  # "symbol": "SOL-27JUN23-20-C",
@@ -8317,6 +8379,19 @@ class bybit(Exchange, ImplicitAPI):
8317
8379
  # "deliveryTime": "1687852800000"
8318
8380
  # }
8319
8381
  #
8382
+ # fetchMySettlementHistory
8383
+ #
8384
+ # {
8385
+ # "symbol": "SOL-27JUN23-20-C",
8386
+ # "deliveryPrice": "16.62258889",
8387
+ # "deliveryTime": "1687852800000",
8388
+ # "side": "Buy",
8389
+ # "strike": "20",
8390
+ # "fee": "0.00000000",
8391
+ # "position": "0.01",
8392
+ # "deliveryRpl": "3.5"
8393
+ # }
8394
+ #
8320
8395
  timestamp = self.safe_integer(settlement, 'deliveryTime')
8321
8396
  marketId = self.safe_string(settlement, 'symbol')
8322
8397
  return {
@@ -8328,6 +8403,8 @@ class bybit(Exchange, ImplicitAPI):
8328
8403
  }
8329
8404
 
8330
8405
  def parse_settlements(self, settlements, market):
8406
+ #
8407
+ # fetchSettlementHistory
8331
8408
  #
8332
8409
  # [
8333
8410
  # {
@@ -8337,6 +8414,21 @@ class bybit(Exchange, ImplicitAPI):
8337
8414
  # }
8338
8415
  # ]
8339
8416
  #
8417
+ # fetchMySettlementHistory
8418
+ #
8419
+ # [
8420
+ # {
8421
+ # "symbol": "SOL-27JUN23-20-C",
8422
+ # "deliveryPrice": "16.62258889",
8423
+ # "deliveryTime": "1687852800000",
8424
+ # "side": "Buy",
8425
+ # "strike": "20",
8426
+ # "fee": "0.00000000",
8427
+ # "position": "0.01",
8428
+ # "deliveryRpl": "3.5"
8429
+ # }
8430
+ # ]
8431
+ #
8340
8432
  result = []
8341
8433
  for i in range(0, len(settlements)):
8342
8434
  result.append(self.parse_settlement(settlements[i], market))
@@ -78,6 +78,7 @@ class cryptocom(Exchange, ImplicitAPI):
78
78
  'fetchMarketLeverageTiers': False,
79
79
  'fetchMarkets': True,
80
80
  'fetchMarkOHLCV': False,
81
+ 'fetchMySettlementHistory': False,
81
82
  'fetchMyTrades': True,
82
83
  'fetchOHLCV': True,
83
84
  'fetchOpenOrders': True,
@@ -63,6 +63,7 @@ class delta(Exchange, ImplicitAPI):
63
63
  'fetchMarketLeverageTiers': False,
64
64
  'fetchMarkets': True,
65
65
  'fetchMarkOHLCV': True,
66
+ 'fetchMySettlementHistory': False,
66
67
  'fetchMyTrades': True,
67
68
  'fetchOHLCV': True,
68
69
  'fetchOpenInterest': True,
@@ -76,6 +76,7 @@ class deribit(Exchange, ImplicitAPI):
76
76
  'fetchMarginMode': False,
77
77
  'fetchMarkets': True,
78
78
  'fetchMarkOHLCV': False,
79
+ 'fetchMySettlementHistory': False,
79
80
  'fetchMyTrades': True,
80
81
  'fetchOHLCV': True,
81
82
  'fetchOpenOrders': True,
@@ -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))