'Gemini API Python {'result': 'error', 'reason': 'InvalidSignature', 'message': 'InvalidSignature'}
I Am getting an error when using the [Gemini API documentation][1] while following the documentation for a Private API invocation.
The json output is:
{'result': 'error', 'reason': 'InvalidSignature', 'message': 'InvalidSignature'}.
My code:
gemini_api_key = getMasterApi()#gets master api key from a json file
gemini_api_secret = getSecretApi().encode()#gets secret api key from a json file
print(gemini_api_secret)
t = datetime.datetime.now()
payload_nonce = str(int(time.mktime(t.timetuple())*1000))
payload = {"request": "/v1/mytrades", "nonce": payload_nonce}
encoded_payload = json.dumps(payload).encode()
b64 = base64.b64encode(encoded_payload)
signature = hmac.new(gemini_api_secret, b64, hashlib.sha384).hexdigest()
request_headers = {
'Content-Type': "text/plain",
'Content-Length': "0",
'X-GEMINI-APIKEY': gemini_api_key,
'X-GEMINI-PAYLOAD': b64,
'X-GEMINI-SIGNATURE': signature,
'Cache-Control': "no-cache"
}
response = requests.post(url, headers=request_headers)
my_trades = response.json()
print(my_trades)
[https://docs.gemini.com/rest-api/#public-api-invocation][1]
Solution 1:[1]
I had the same issue and was able to resolve it by creating a new API key with Primary scope (instead of Master scope) and Auditor permissions.
Solution 2:[2]
Make sure you're using the right URL. If you made an API key using a sandbox account, you have to change the URL to url = "https://api.sandbox.gemini.com/v1/mytrades".
Solution 3:[3]
If you are using the Gemini sandbox, you will need to create your API keys using https://exchange.sandbox.gemini.com/ as opposed to their normal site.
Solution 4:[4]
If doing this on your live account and not a sandbox account, when you go to create an API, select 'primary' with 'Fund Management' and 'Trading' permissions. 'Auditor' will not allow you to interact with your funds or place orders.
I had the same issue until I did this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mirom18 |
| Solution 2 | John Born |
| Solution 3 | Dave |
| Solution 4 | CMcCudden |
