Skip to content

Instantly share code, notes, and snippets.

@nottug
Forked from phillijw/sample.py
Last active July 31, 2018 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nottug/07d6a79a8c4e2e53d238b87d953d79b4 to your computer and use it in GitHub Desktop.
Save nottug/07d6a79a8c4e2e53d238b87d953d79b4 to your computer and use it in GitHub Desktop.
Coinigy API v2 Signature Example in Python 3
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
@phillijw
Copy link

phillijw commented Jul 31, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment