Last active
January 30, 2021 03:17
-
-
Save yoheioka/b691e98f1b4f257d8052334fd71899b7 to your computer and use it in GitHub Desktop.
example of selling on gemini
This file contains hidden or 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 os | |
import requests | |
import json | |
import base64 | |
import hmac | |
import hashlib | |
import datetime, time | |
def make_sell(amount, price): | |
base_url = 'https://api.gemini.com' | |
endpoint = '/v1/order/new' | |
url = base_url + endpoint | |
gemini_api_key = os.environ.get('GEMINI_API_KEY') | |
gemini_api_secret = os.environ.get('GEMINI_API_SECRET').encode() | |
t = datetime.datetime.now() | |
payload_nonce = str(int(time.mktime(t.timetuple()) * 1000)) | |
payload = { | |
'request': '/v1/order/new', | |
'nonce': payload_nonce, | |
'symbol': 'btcusd', | |
'amount': str(amount), | |
'price': str(price), | |
'side': 'sell', | |
'type': 'exchange limit', | |
'options': ['maker-or-cancel'] | |
} | |
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, data=None, headers=request_headers) | |
return response.json() | |
if __name__ == '__main__': | |
print('selling') | |
make_sell(0.01, 20000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment