Skip to content

Instantly share code, notes, and snippets.

@caulinez
Last active May 27, 2018 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caulinez/5fbf28a426009b6cc7c6e080b7683fe3 to your computer and use it in GitHub Desktop.
Save caulinez/5fbf28a426009b6cc7c6e080b7683fe3 to your computer and use it in GitHub Desktop.
For Python 3.X
import requests
import base64
import hmac
import hashlib
from hashlib import sha384
from io import BytesIO
import time
import json
def connect():
f=open("gemini-api-sandbox.txt", "r")
if f.mode == 'r':
gemini_api_key =f.readline().rstrip('\n')
gemini_api_secret =f.readline().rstrip('\n')
f.close()
payload_nonce = int(round(time.time()-1398621111,1)*10)
url = 'https://api.sandbox.gemini.com/v1/heartbeat'
payload = {"request": "/v1/heartbeat", "nonce": payload_nonce}
encoded_payload = json.dumps(payload)
b64 = base64.b64encode(bytes(encoded_payload, 'utf-8'))
signature = hmac.new(bytearray(gemini_api_secret, 'utf-8'), 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, verify=False)
print(response.status_code)
print(response.content)
connect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment