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

Method sign

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

Source from the content-addressed store, hash-verified

9260 return self.safe_string(marginModes, marginMode, marginMode)
9261
9262 def sign(self, path, api: Any = 'public', method='GET', params={}, headers: dict = None, body: Any = None):
9263 url = self.implode_hostname(self.urls['api'][api]) + '/' + path
9264 if api == 'public':
9265 if params:
9266 url += '?' + self.rawencode(params)
9267 elif api == 'private':
9268 self.check_required_credentials()
9269 isOpenapi = url.find('openapi') >= 0
9270 isV3UnifiedMargin = url.find('unified/v3') >= 0
9271 isV3Contract = url.find('contract/v3') >= 0
9272 isV5UnifiedAccount = url.find('v5') >= 0
9273 timestamp = str(self.nonce())
9274 if isOpenapi:
9275 if params:
9276 body = self.json(params)
9277 else:
9278 # self fix for PHP is required otherwise it generates
9279 # '[]' on empty arrays even when forced to use objects
9280 body = '{}'
9281 payload = timestamp + self.apiKey + body
9282 signature = self.hmac(self.encode(payload), self.encode(self.secret), hashlib.sha256, 'hex')
9283 headers = {
9284 'Content-Type': 'application/json',
9285 'X-BAPI-API-KEY': self.apiKey,
9286 'X-BAPI-TIMESTAMP': timestamp,
9287 'X-BAPI-SIGN': signature,
9288 }
9289 elif isV3UnifiedMargin or isV3Contract or isV5UnifiedAccount:
9290 headers = {
9291 'Content-Type': 'application/json',
9292 'X-BAPI-API-KEY': self.apiKey,
9293 'X-BAPI-TIMESTAMP': timestamp,
9294 'X-BAPI-RECV-WINDOW': str(self.options['recvWindow']),
9295 }
9296 if isV3UnifiedMargin or isV3Contract:
9297 headers['X-BAPI-SIGN-TYPE'] = '2'
9298 query = self.extend({}, params)
9299 queryEncoded = self.rawencode(query)
9300 auth_base = str(timestamp) + self.apiKey + str(self.options['recvWindow'])
9301 authFull = None
9302 if method == 'POST':
9303 body = self.json(query)
9304 authFull = auth_base + body
9305 else:
9306 authFull = auth_base + queryEncoded
9307 url += '?' + queryEncoded
9308 signature = None
9309 if self.secret.find('PRIVATE KEY') > -1:
9310 signature = self.rsa(authFull, self.secret, 'sha256')
9311 else:
9312 signature = self.hmac(self.encode(authFull), self.encode(self.secret), hashlib.sha256)
9313 headers['X-BAPI-SIGN'] = signature
9314 else:
9315 query = self.extend(params, {
9316 'api_key': self.apiKey,
9317 'recv_window': self.options['recvWindow'],
9318 'timestamp': timestamp,
9319 })

Callers

nothing calls this directly

Calls 13

nonceMethod · 0.95
implode_hostnameMethod · 0.80
findMethod · 0.80
safe_stringMethod · 0.80
rawencodeMethod · 0.45
jsonMethod · 0.45
hmacMethod · 0.45
encodeMethod · 0.45
extendMethod · 0.45
rsaMethod · 0.45
keysortMethod · 0.45

Tested by

no test coverage detected