-
Notifications
You must be signed in to change notification settings - Fork 1
/
coinone_api.py
57 lines (42 loc) · 1.41 KB
/
coinone_api.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
#import urllib2
from urllib.request import urlopen
import json
import multiprocessing
from pprint import pprint
"""def work(url):
response = urlopen(url)
data = json.loads(response.read())
return data
"""
class CoinOne():
def __init__(self):
#self.types = ['btc', 'eth', 'etc', 'xrp']
self.types = ['eth']
self.base_url = 'https://api.coinone.co.kr'
def currency(self):
url = self.base_url + '/currency'
response = urlopen(url)
data = json.loads(response.read())
if data['result'] == 'success':
#pprint(data)
return data['currency']
print("Fail to get currency")
def orderbook(self):
def get_max(data):
ask_min = min([x['price'] for x in data['ask']])
bid_max = max([x['price'] for x in data['bid']])
return ask_min, bid_max
#pool = multiprocessing.Pool(2)
url = self.base_url + "/orderbook/?currency=%s"
datas = {}
try:
#XXX: more types, fix it
for idx in range(len(self.types)):
response = urlopen(url % self.types[idx])
data = json.loads(response.read())
datas[data['currency']] = get_max(data)
return datas
#results = pool.map(work, [url % x for x in self.types])
except Exception as e:
print(e)
exit(1)