Skip to content

Instantly share code, notes, and snippets.

@gelldur
Created December 5, 2017 23:40
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 gelldur/4edf64514e18304a67c426ba20e4c9bc to your computer and use it in GitHub Desktop.
Save gelldur/4edf64514e18304a67c426ba20e4c9bc to your computer and use it in GitHub Desktop.
Abucoins sample api call
import json, hmac, hashlib, time, requests, base64
from requests.auth import AuthBase
class AbuCoins(AuthBase):
def __init__(self, api_key, secret_key, passphrase):
self.api_key = api_key
self.secret_key = secret_key
self.passphrase = passphrase
def __call__(self, request):
timestamp = str(int(time.time())) # eg. 1512516837
# timestamp = eg. 1512516837
# request.method = eg. POST
# request.path_url = eg. /orders
message = timestamp + request.method + request.path_url
if request.body: # if present
message = message + request.body.decode() # decode raw bytes
hmac_key = base64.b64decode(self.secret_key)
signature = hmac.new(hmac_key, message.encode('utf-8'), hashlib.sha256)
signature_base64 = base64.b64encode(signature.digest())
request.headers.update({
'AC-ACCESS-KEY': self.api_key,
'AC-ACCESS-PASSPHRASE': self.passphrase,
'AC-ACCESS-SIGN': signature_base64,
'AC-ACCESS-TIMESTAMP' : timestamp,
})
return request
abucoins_api = 'https://api.abucoins.com'
abucoins_passphrase = '6XcXXXXXX'
abucoins_key = '007-XIXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC582'
abucoins_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX4Ml5vST93Tml1KSg8YzsvNmhZUUAuYEE3'
authenticator = AbuCoins(api_key = abucoins_key, secret_key = abucoins_secret, passphrase = abucoins_passphrase)
order = {
"cancel_after" : "min",
"price" : "0.035582569",
"product_id" : "ZEC-BTC",
"side" : "buy",
"size" : "17.3124",
"time_in_force" : "GTT",
"type" : "limit"
}
response = requests.post(abucoins_api + '/orders', json = order, auth = authenticator)
print(response)
print(response.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment