-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIGraviex.py
123 lines (92 loc) · 4.4 KB
/
APIGraviex.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import hashlib
import hmac
import requests
import time
import ssl
import json
import collections
class APIGraviex:
def __init__(self, access_key, secret_key):
self.ctx = ssl.create_default_context()
self.ctx.check_hostname = False
self.ctx.verify_mode = ssl.CERT_NONE
self.access = access_key
self.secret = secret_key
self.timer = int(time.time()) * 1000
self.timer2 = int(time.time()) * 1000
def api_query(self, type, feature_requested, get_parameters={}):
timer = int(time.time()) * 1000
# print(timer)
if self.timer == timer:
self.timer2 = self.timer2 + 1
else:
self.timer = timer
self.timer2 = timer
# print(self.timer2)
get_parameters['tonce'] = str(self.timer2)
get_parameters = collections.OrderedDict(sorted(get_parameters.items(), key=lambda t: t[0]))
text = ''
for key, value in get_parameters.items():
if value != '':
text = text + '&' + key + '=' + str(value)
req = 'access_key=' + self.access + text
message = type + '|/api/v3/' + feature_requested + '|' + req
# print(message)
signature = hmac.new(
bytes(self.secret , 'latin-1'),
bytes(message, 'latin-1'),
hashlib.sha256
).hexdigest()
if type == 'GET':
query = 'https://graviex.net/api/v3/' + feature_requested \
+ '?' + (req) + '&signature=' + (signature)
#print(query)
r = requests.get(query)
try:
data = json.loads(r.content.decode('utf-8'))
return data
except:
return r.content.decode('utf-8')
else:
query = 'https://graviex.net/api/v3/' + feature_requested \
+ '?' + (req) + '&signature=' + (signature)
# print(query)
r = requests.post(query)
# print(r.url)
data = json.loads(r.content.decode('utf-8'))
return data
def api_query_public(self, feature_requested, get_parameters=None):
query = 'https://graviex.net/api/v3/' + feature_requested + "/" + ('/'.join(i for i in get_parameters.values()
) if get_parameters is not None else "")
# print(query)
r = requests.get(query)
data = json.loads(r.content.decode('utf-8'))
return data
def timestamp(self):
return self.api_query_public('timestamp')
def market(self):
return self.api_query_public('markets')
def tickers(self):
return self.api_query_public('tickers')
def ticker(self, market):
return self.api_query_public('tickers', get_parameters={'market': market.lower()})
def me(self):
return self.api_query('GET', 'members/me')
def deposits(self, currency, limit = '', state = ''):
return self.api_query('GET', 'deposits', get_parameters={'currency':currency.lower(), 'limit':limit, 'state':state})
def deposit(self, txid):
return self.api_query('GET', 'deposit', get_parameters={'txid':txid})
def deposit_address(self, currency):
return self.api_query('GET', 'deposit_address', get_parameters={'currency':currency.lower()})
def get_order_market(self, market = '', limit = '', state = '', page = '', order_by = ''):
return self.api_query('GET', 'orders', get_parameters={'market':market.lower(), 'limit':limit, 'state':state, 'page':page, 'order_by':order_by})
def put_orders(self, market = '', side = '', volume = '', price = ''):
return self.api_query('POST', 'orders', get_parameters={'market':market.lower(), 'side':side, 'volume':volume, 'price':price})
def clear_orders(self, side = ""):
return self.api_query('POST', 'orders/clear', get_parameters={'side':side})
def get_order_id(self, id = ''):
return self.api_query('GET', 'order', get_parameters={'id':id})
def depth(self, market = '', limit = ''):
return self.api_query('GET', 'depth', get_parameters={'market':market.lower(), 'limit':limit})