-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders.py
More file actions
48 lines (36 loc) · 1.11 KB
/
orders.py
File metadata and controls
48 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import jwt
import uuid
import hashlib
from urllib.parse import urlencode
import requests
def call_orders(acc_key, sec_key, state, uuid_param):
access_key = acc_key
secret_key = sec_key
server_url = 'https://api.upbit.com/v1/orders'
query = {
'state': state,
}
query_string = urlencode(query)
uuids = [
uuid_param,
# ...
]
uuids_query_string = '&'.join(["uuids[]={}".format(uuid) for uuid in uuids])
query['uuids[]'] = uuids
query_string = "{0}&{1}".format(query_string, uuids_query_string).encode()
m = hashlib.sha512()
m.update(query_string)
query_hash = m.hexdigest()
payload = {
'access_key': access_key,
'nonce': str(uuid.uuid4()),
'query_hash': query_hash,
'query_hash_alg': 'SHA512',
}
jwt_token = jwt.encode(payload, secret_key)
authorize_token = 'Bearer {}'.format(jwt_token)
headers = {"Authorization": authorize_token}
res = requests.get(server_url, params=query, headers=headers)
print(res.json())
return res.json()