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

Method sign

python/ccxt/backpack.py:2170–2207  ·  view source on GitHub ↗
(self, path, api: Any = 'public', method='GET', params={}, headers: dict = None, body: Str = None)

Source from the content-addressed store, hash-verified

2168 return self.milliseconds() - self.options['timeDifference']
2169
2170 def sign(self, path, api: Any = 'public', method='GET', params={}, headers: dict = None, body: Str = None):
2171 endpoint = '/' + path
2172 url = self.urls['api'][api]
2173 sortedParams = params if isinstance(params, list) else self.keysort(params)
2174 if api == 'private':
2175 self.check_required_credentials()
2176 ts = str(self.nonce())
2177 recvWindow = self.safe_string_2(self.options, 'recvWindow', 'X-Window', '5000')
2178 optionInstructions = self.safe_dict(self.options, 'instructions', {})
2179 optionPathInstructions = self.safe_dict(optionInstructions, path, {})
2180 instruction = self.safe_string(optionPathInstructions, method, '')
2181 payload = ''
2182 if (path == 'api/v1/orders') and (method == 'POST'): # for createOrders
2183 payload = self.generate_batch_payload(sortedParams, ts, recvWindow, instruction)
2184 else:
2185 queryString = self.urlencode(sortedParams)
2186 if len(queryString) > 0:
2187 queryString += '&'
2188 payload = 'instruction=' + instruction + '&' + queryString + 'timestamp=' + ts + '&window=' + recvWindow
2189 secretBytes = self.base64_to_binary(self.secret)
2190 seed = self.array_slice(secretBytes, 0, 32)
2191 signature = self.eddsa(self.encode(payload), seed, 'ed25519')
2192 headers = {
2193 'X-Timestamp': ts,
2194 'X-Window': recvWindow,
2195 'X-API-Key': self.apiKey,
2196 'X-Signature': signature,
2197 'X-Broker-Id': '1400',
2198 }
2199 if method != 'GET':
2200 body = self.json(sortedParams)
2201 headers['Content-Type'] = 'application/json'
2202 if method == 'GET':
2203 query = self.urlencode(sortedParams)
2204 if len(query) != 0:
2205 endpoint += '?' + query
2206 url += endpoint
2207 return {'url': url, 'method': method, 'body': body, 'headers': headers}
2208
2209 def generate_batch_payload(self, params, ts, recvWindow, instruction):
2210 payload = ''

Callers

nothing calls this directly

Calls 13

nonceMethod · 0.95
safe_string_2Method · 0.80
safe_dictMethod · 0.80
safe_stringMethod · 0.80
base64_to_binaryMethod · 0.80
array_sliceMethod · 0.80
keysortMethod · 0.45
urlencodeMethod · 0.45
eddsaMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected