-
-
Save nottug/07d6a79a8c4e2e53d238b87d953d79b4 to your computer and use it in GitHub Desktop.
Coinigy API v2 Signature Example in Python 3
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 time | |
import hmac | |
import hashlib | |
import requests | |
BASE_URL = 'https://api.coinigy.com' | |
ENDPOINT = '/api/v2/private/exchanges' | |
KEY = 'keykeykeykeykeykeykeykeykeykeyke' | |
SECRET = 'secretsecretsecretsecretsecretse' | |
METHOD = 'GET' | |
UNIXTIME = time.time() | |
BODY = '' | |
X_API_TIMESTAMP = str(int(UNIXTIME)) | |
msg = KEY + X_API_TIMESTAMP + METHOD + ENDPOINT + BODY | |
signature_bytes = hmac.new(SECRET.encode("ascii"), msg.encode("ascii"), digestmod=hashlib.sha256).digest() | |
signature_hex = map("{:02X}".format, signature_bytes) | |
X_API_SIGN = ''.join(signature_hex) | |
headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'X-API-SIGN': X_API_SIGN, 'X-API-TIMESTAMP' : X_API_TIMESTAMP, 'X-API-KEY': KEY} | |
r = requests.get(BASE_URL + ENDPOINT, headers=headers, data=BODY) | |
print(r.status_code, r.reason, r.content, BASE_URL + ENDPOINT) | |
# 401 Unauthorized b'' https://api.coinigy.com/api/v2/private/exchanges |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code works when I test it but you have to change the KEY and SECRET to be a v2 api key/secret. Once you do that it should work fine.