· 6 years ago · Mar 29, 2019, 10:00 AM
1import hashlib
2import hmac
3import json
4import time
5import requests
6
7KUNA_API_URL_PREFIX = '/v3/auth/kuna_codes/issued-by-me'
8KUNA_API_BASEURL = 'https://api.kuna.io{}'.format(KUNA_API_URL_PREFIX)
9
10
11class KunaAPI(object):
12
13 def __init__(self, access_key=None, secret_key=None):
14
15 self.access_key = access_key
16 self.secret_key = secret_key
17
18 def get_user_account_info(self):
19 """
20 Information about the User and Assets.
21 This is a User method.
22 :return:
23 """
24 return self.request()
25
26 def request(self):
27
28 body = {}
29 headers = {}
30
31 headers['kun-apikey'] = self.access_key
32 headers['kun-nonce'] = str(int(round(time.time() * 1000)))
33 headers['kun-signature'] = self._generate_signature(headers['kun-nonce'], body)
34
35 print("{} ::: {} ::: {}".format(KUNA_API_BASEURL, headers, body))
36 response = requests.post(url=KUNA_API_BASEURL, headers=headers, data=body)
37
38 result = response.json()
39 print(result)
40
41 def _generate_signature(self, nonce, body):
42 signature = "{}{}{}".format(KUNA_API_URL_PREFIX, nonce, json.dumps(body))
43 return hmac.new(self.secret_key.encode('utf8'), signature.encode('utf8'), hashlib.sha384).hexdigest()
44
45
46exchange_connection = KunaAPI(access_key='xO1MxKDC0kOWQqYmW9xPzV4keL7pFMH3A3HLoVal',
47 secret_key='qbQ7OOXcZ02kuGxpnxPnDjSmr8a3aCIRY3zdFezN')