forked from Dragonexio/OpenApi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdragonex.py
More file actions
139 lines (106 loc) · 4.91 KB
/
dragonex.py
File metadata and controls
139 lines (106 loc) · 4.91 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
import time
import logging
from examples.python3.base import Base, InvalidParamsHttpResponse
from examples.python3.utils import check_is_all_digit
class DragonExV1(Base):
def __init__(self, access_key, secret_key, host):
super(DragonExV1, self).__init__(access_key=access_key, secret_key=secret_key, host=host)
def create_new_token(self):
path = '/api/v1/token/new/'
data = {}
return self.post(path, data)
def token_status(self):
path = '/api/v1/token/status/'
data = {}
return self.post(path, data)
def ensure_token_enable(self, forever=False):
http = self.token_status()
if not http.ok:
logging.debug('abnormal token status : token={}, code={}, msg={}'.format(self.token, http.code, http.msg))
r = self.create_new_token()
if r.ok:
self.token = r.data['token']
logging.debug('create new token succeed: token={}'.format(self.token))
else:
logging.debug('create token failed: code={}, msg={}'.format(r.code, r.msg))
else:
logging.debug('normal token status: token={}'.format(self.token))
while forever:
time.sleep(60)
self.ensure_token_enable()
return http
def get_all_coins(self):
path = '/api/v1/coin/all/'
params = {}
return self.get(path, params)
def get_user_own_coins(self):
path = '/api/v1/user/own/'
data = {}
return self.post(path, data)
def get_all_symbos(self):
path = '/api/v1/symbol/all/'
params = {}
return self.get(path, params)
def get_market_kline(self, symbol_id, start_time=0, search_direction=2, count=10, kline_type=1):
if not check_is_all_digit(symbol_id, start_time, search_direction, count, kline_type):
return InvalidParamsHttpResponse
path = '/api/v1/market/kline/'
params = {'symbol_id': symbol_id, 'st': start_time, 'direction': search_direction, 'count': count,
'kline_type': kline_type}
return self.get(path, params)
def get_market_buy(self, symbol_id):
if not check_is_all_digit(symbol_id):
return InvalidParamsHttpResponse
path = '/api/v1/market/buy/'
params = {'symbol_id': symbol_id}
return self.get(path, params)
def get_market_sell(self, symbol_id):
if not check_is_all_digit(symbol_id):
return InvalidParamsHttpResponse
path = '/api/v1/market/sell/'
params = {'symbol_id': symbol_id}
return self.get(path, params)
def get_market_real(self, symbol_id):
if not check_is_all_digit(symbol_id):
return InvalidParamsHttpResponse
path = '/api/v1/market/real/'
params = {'symbol_id': symbol_id}
return self.get(path, params)
def add_order_buy(self, symbol_id, price, volume):
if not check_is_all_digit(symbol_id):
return InvalidParamsHttpResponse
path = '/api/v1/order/buy/'
data = {'symbol_id': symbol_id, 'price': '{}'.format(price), 'volume': '{}'.format(volume)}
return self.post(path, data)
def add_order_sell(self, symbol_id, price, volume):
if not check_is_all_digit(symbol_id):
return InvalidParamsHttpResponse
path = '/api/v1/order/sell/'
data = {'symbol_id': symbol_id, 'price': '{}'.format(price), 'volume': '{}'.format(volume)}
return self.post(path, data)
def cancel_order(self, symbol_id, order_id):
if not check_is_all_digit(symbol_id, order_id):
return InvalidParamsHttpResponse
path = '/api/v1/order/cancel/'
data = {'symbol_id': symbol_id, 'order_id': order_id}
return self.post(path, data)
def get_order_detail(self, symbol_id, order_id):
if not check_is_all_digit(symbol_id, order_id):
return InvalidParamsHttpResponse
path = '/api/v1/order/detail/'
data = {'symbol_id': symbol_id, 'order_id': order_id}
return self.post(path, data)
def get_user_order_history(self, symbol_id, search_direction=2, start_time=0, count=10, status=0):
if not check_is_all_digit(symbol_id, search_direction, start_time, count, status):
return InvalidParamsHttpResponse
path = '/api/v1/order/history/'
data = {'symbol_id': symbol_id, 'direction': search_direction, 'start': start_time, 'count': count,
'status': status}
return self.post(path, data)
def get_user_deal_history(self, symbol_id, search_direction=2, start_time=0, count=10):
if not check_is_all_digit(symbol_id, search_direction, start_time, count):
return InvalidParamsHttpResponse
path = '/api/v1/deal/history/'
data = {'symbol_id': symbol_id, 'direction': search_direction, 'start': start_time, 'count': count}
return self.post(path, data)