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

Method sign

python/ccxt/async_support/coinbase.py:4891–4973  ·  view source on GitHub ↗
(self, path, api: Any = [], method='GET', params={}, headers: dict = None, body: Str = None)

Source from the content-addressed store, hash-verified

4889 return self.milliseconds() - self.options['timeDifference']
4890
4891 def sign(self, path, api: Any = [], method='GET', params={}, headers: dict = None, body: Str = None):
4892 version = api[0]
4893 signed = api[1] == 'private'
4894 isV3 = version == 'v3'
4895 pathPart = 'api/v3' if (isV3) else 'v2'
4896 fullPath = '/' + pathPart + '/' + self.implode_params(path, params)
4897 query = self.omit(params, self.extract_params(path))
4898 savedPath = fullPath
4899 if method == 'GET':
4900 if query:
4901 fullPath += '?' + self.urlencode_with_array_repeat(query)
4902 url = self.urls['api']['rest'] + fullPath
4903 if signed:
4904 authorization = self.safe_string(self.headers, 'Authorization')
4905 authorizationString = None
4906 if authorization is not None:
4907 authorizationString = authorization
4908 elif self.token and not self.check_required_credentials(False):
4909 authorizationString = 'Bearer ' + self.token
4910 else:
4911 self.check_required_credentials()
4912 seconds = self.seconds()
4913 payload = ''
4914 if method != 'GET':
4915 if query:
4916 body = self.json(query)
4917 payload = body
4918 else:
4919 if not isV3:
4920 if query:
4921 payload += '?' + self.urlencode(query)
4922 # v3: 'GET' doesn't need payload in the signature. inside url is enough
4923 # https://docs.cdp.coinbase.com/coinbase-app/authentication-authorization/api-key-authentication
4924 # v2: 'GET' require payload in the signature
4925 # https://docs.cdp.coinbase.com/coinbase-app/authentication-authorization/api-key-authentication
4926 isCloudAPiKey = (self.apiKey.find('organizations/') >= 0) or (self.secret.startswith('-----BEGIN'))
4927 # using the size might be fragile, so we add an option to force v2 cloud api key if needed
4928 isV2CloudAPiKey = len(self.secret) == 88 or self.safe_bool(self.options, 'v2CloudAPiKey', False) or self.secret.endswith('=')
4929 if isCloudAPiKey or isV2CloudAPiKey:
4930 if isCloudAPiKey and self.apiKey.startswith('-----BEGIN'):
4931 raise ArgumentsRequired(self.id + ' apiKey should contain the name(eg: organizations/3b910e93....) and not the public key')
4932 # # it may not work for v2
4933 # uri = method + ' ' + url.replace('https://', '')
4934 # quesPos = uri.find('?')
4935 # # Due to we use mb_strpos, quesPos could be False in php. In that case, the quesPos >= 0 is True
4936 # # Also it's not possible that the question mark is first character, only check > 0 here.
4937 # if quesPos > 0:
4938 # uri = uri[0:quesPos]
4939 # }
4940 # nonce = self.random_bytes(16)
4941 # request = {
4942 # 'aud': ['retail_rest_api_proxy'],
4943 # 'iss': 'coinbase-cloud',
4944 # 'nbf': seconds,
4945 # 'exp': seconds + 120,
4946 # 'sub': self.apiKey,
4947 # 'uri': uri,
4948 # 'iat': seconds,

Callers

nothing calls this directly

Calls 15

create_auth_tokenMethod · 0.95
nonceMethod · 0.95
ArgumentsRequiredClass · 0.90
implode_paramsMethod · 0.80
extract_paramsMethod · 0.80
safe_stringMethod · 0.80
findMethod · 0.80
safe_boolMethod · 0.80
parse_to_intMethod · 0.80
omitMethod · 0.45

Tested by

no test coverage detected