Created
October 29, 2014 19:12
-
-
Save mattions/f9f545a5eac5eb5ed1b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import base64 | |
import hashlib | |
import hmac | |
def _prepare_headers(payload, api_key, api_secret): | |
# payload = parameters-dictionary -> JSON encode -> base64 | |
payload_json = json.dumps(payload) | |
payload_encoded = base64.encodestring(payload_json) | |
# signature = HMAC-SHA384(payload, api-secret) as hexadecimal | |
encryptor = hmac.new(payload_encoded, api_secret, hashlib.sha384) | |
signature = encryptor.hexdigest() | |
# send (api-key, payload, signature) | |
headers = {"X-BFX-APIKEY" : api_key, | |
"X-BFX-PAYLOAD" : payload_encoded, | |
"X-BFX-SIGNATURE": signature | |
} | |
return headers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment