Last active
May 27, 2018 06:32
-
-
Save caulinez/5fbf28a426009b6cc7c6e080b7683fe3 to your computer and use it in GitHub Desktop.
For Python 3.X
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 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