-
-
Save phillijw/1f78c8bafdce3a71a0b2ef9d4f5942a1 to your computer and use it in GitHub Desktop.
Coinigy API v2 Signature and Request 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' | |
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) |
Thanks Joe. I checked and points 2 and 3 are definitely correct. I also
made sure my time is current and I double-checked against
unixtimestamp .com and my output definitely matches the universal time.
Still no luck. Any other things I could try on my end?
…On Mon, 12 Apr 2021 at 21:43, Joe Phillips ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
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
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/1f78c8bafdce3a71a0b2ef9d4f5942a1#gistcomment-3703303>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKG3F7SJIAPXQGSPTDPCSLLTINLNJANCNFSM4IRPY4RA>
.
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
There are a few reasons:
That's about it