2

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]

 
MFrost96
  • 21
  • 4

4 Answers4

0

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.

Mirom18
  • 1
  • 2
0

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".

0

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.

Dave
  • 15,639
  • 133
  • 442
  • 830
0

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.

CMcCudden
  • 1
  • 3