@@ -38,28 +38,31 @@ def apply(self, r):
3838 return r
3939
4040 # Generates an API signature.
41- # A signature is HMAC_SHA256(secret, verb + path + nonce + data), hex encoded.
42- # Verb must be uppercased, url is relative, nonce must be an increasing 64-bit integer
41+ # A signature is HMAC_SHA256(secret, verb + path + expires + data), hex encoded.
42+ # Verb must be uppercased, url is relative, expires must be an increasing 64-bit integer
4343 # and the data, if present, must be JSON without whitespace between keys.
4444 #
4545 # For example, in psuedocode (and in real code below):
4646 #
4747 # verb=POST
4848 # url=/api/v1/order
49- # nonce=1416993995705
50- # data={"symbol":"XBTZ14","quantity":1,"price":395.01}
51- # signature = HEX(HMAC_SHA256(secret, 'POST/api/v1/order1416993995705{"symbol":"XBTZ14","quantity":1,"price":395.01}'))
52- def generate_signature (self , secret , verb , url , nonce , data ):
49+ # expires=1518064237
50+ # data={"symbol":"XBTUSD","quantity":1,"price":52000.50}
51+ # message='POST/api/v1/order1518064237{"symbol":"XBTUSD","quantity":1,"price":52000.50}'
52+ # signature = HEX(HMAC_SHA256(secret, message))
53+ def generate_signature (self , secret , verb , url , expires , data ):
5354 """Generate a request signature compatible with BitMEX."""
5455 # Parse the url so we can remove the base and extract just the path.
5556 parsedURL = urllib .parse .urlparse (url )
5657 path = parsedURL .path
5758 if parsedURL .query :
5859 path = path + '?' + parsedURL .query
5960
60- message = bytes (verb + path + str (nonce ) + data , 'utf-8' )
61+ message = bytes (verb + path + str (expires ) + data , 'utf-8' )
6162 # print("Computing HMAC: %s" % message)
6263
6364 signature = hmac .new (bytes (secret , 'utf-8' ), message , digestmod = hashlib .sha256 ).hexdigest ()
65+ # print("Signature: %s" % signature)
66+
6467 return signature
6568
0 commit comments