Skip to content

Instantly share code, notes, and snippets.

@phillijw
Forked from nottug/sample.py
Last active April 13, 2021 18:26
Show Gist options
  • Save phillijw/1f78c8bafdce3a71a0b2ef9d4f5942a1 to your computer and use it in GitHub Desktop.
Save phillijw/1f78c8bafdce3a71a0b2ef9d4f5942a1 to your computer and use it in GitHub Desktop.
Coinigy API v2 Signature and Request Example in Python 3
import time
import hmac
import hashlib
import requests
BASE_URL = 'https://api.coinigy.com'
ENDPOINT = '/api/v2/private/exchanges'
X_API_KEY = 'your_api_v2_key_goes_here'
SECRET = 'your_corresponding_api_v2_secret_goes_here'
METHOD = 'GET'
UNIXTIME = time.time()
PARAMS = {} # = {'StartDate':'2018-07-30T00:00:00.000Z','EndDate':'2018-07-30T23:59:59.000Z'}
BODY = ''
X_API_TIMESTAMP = str(int(UNIXTIME))
query_string = "?" + "&".join( [ key + '=' + urllib.parse.quote_plus(PARAMS[key]) for key in PARAMS.keys() ] )
msg = X_API_KEY + X_API_TIMESTAMP + METHOD + ENDPOINT + (query_string if len(query_string) > 1 else '') + 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': X_API_KEY}
r = requests.get(BASE_URL + ENDPOINT, headers=headers, params=PARAMS, data=BODY)
print(r.status_code, r.reason, r.content, BASE_URL + ENDPOINT)
@dddragos
Copy link

dddragos commented Apr 12, 2021 via email

@phillijw
Copy link
Author

Any ideas what might cause this issue?

There are a few reasons:

  • The clock on your computer may be out of sync. The request needs to occur within 30sec of Coinigy server time otherwise it is denied
  • Make sure you're using a v2 api key, not a v1 key
  • Make sure you have a Crypto Feed subscription

That's about it

@dddragos
Copy link

dddragos commented Apr 13, 2021 via email

@phillijw
Copy link
Author

Any other things I could try on my end?

I'm out of ideas. If you want to contact me through the Coinigy support email and ask for me, I can continue helping you there. Next thing I would try is looking into your account to make sure everything is set up properly.

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