MCPcopy Create free account
hub / github.com/ccxt/ccxt / initialize_client

Method initialize_client

python/ccxt/async_support/grvt.py:556–612  ·  view source on GitHub ↗
(self, params={})

Source from the content-addressed store, hash-verified

554 return response
555
556 async def initialize_client(self, params={}):
557 builderFee = self.safe_bool(params, 'builderFee', self.safe_bool(self.options, 'builderFee', True)) # we shouldn't omit here
558 if not builderFee:
559 return False # skip if builder fee is not enabled
560 approvedBuilderFee = self.safe_bool(self.options, 'approvedBuilderFee', False)
561 if approvedBuilderFee:
562 return True # skip if builder fee is already approved
563 results = await asyncio.gather(*[self.privateTradingPostFullV1GetAuthorizedBuilders(), self.load_account_infos()])
564 #
565 # {
566 # "results": [{
567 # "builder_account_id": "GRVT_MAIN_ACCOUNT_ID_HERE",
568 # "max_futures_fee_rate": 0.001,
569 # "max_spot_fee_rate": 0.0001
570 # }]
571 # }
572 #
573 currentBuilders = results[0]
574 approvedBuilder = self.safe_list(currentBuilders, 'results', [])
575 length = len(approvedBuilder)
576 found = False
577 for i in range(0, length):
578 builderInfo = self.safe_dict(approvedBuilder, i, {})
579 builderAccountId = self.safe_string(builderInfo, 'builder_account_id')
580 if builderAccountId == self.safe_string(self.options, 'builder'):
581 found = True
582 break
583 if found:
584 self.options['approvedBuilderFee'] = True
585 else:
586 try:
587 defaultFromAccountId = self.safe_string(self.options, 'userMainAccountId') # self.eth_get_address_from_private_key(self.secret) # self.safe_string(self.options, 'userMainAccountId')
588 request = {
589 'main_account_id': defaultFromAccountId,
590 'builder_account_id': self.safe_string(self.options, 'builder'),
591 'max_futures_fee_rate': self.safe_string(self.options, 'builderRate'),
592 'max_spot_fee_rate': self.safe_string(self.options, 'builderRate'),
593 'signature': self.default_signature(),
594 }
595 request = self.create_signed_request(request, 'EIP712_BUILDER_APPROVAL_TYPE')
596 authResponse = await self.privateTradingPostFullV1AuthorizeBuilder(self.extend(request, params))
597 #
598 # {
599 # "result": {
600 # "ack": "true",
601 # "tx_id":"0"
602 # }
603 # }
604 #
605 authResult = self.safe_dict(authResponse, 'result')
606 ack = self.safe_bool(authResult, 'ack')
607 if not ack:
608 raise ExchangeError('Builder authorization failed, ' + self.json(authResponse))
609 self.options['approvedBuilderFee'] = True
610 except Exception as e:
611 self.options['builderFee'] = False # disable builder fee if an error occurs
612 return None # just c#
613

Callers 1

sign_inMethod · 0.95

Calls 13

load_account_infosMethod · 0.95
default_signatureMethod · 0.95
create_signed_requestMethod · 0.95
ExchangeErrorClass · 0.90
safe_boolMethod · 0.80
safe_listMethod · 0.80
safe_dictMethod · 0.80
safe_stringMethod · 0.80
rangeFunction · 0.50
extendMethod · 0.45

Tested by

no test coverage detected