Skip to content

Instantly share code, notes, and snippets.

@yoheioka
Last active January 30, 2021 03:17
Show Gist options
  • Save yoheioka/b691e98f1b4f257d8052334fd71899b7 to your computer and use it in GitHub Desktop.
Save yoheioka/b691e98f1b4f257d8052334fd71899b7 to your computer and use it in GitHub Desktop.
example of selling on gemini
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