-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi_parser.py
More file actions
68 lines (55 loc) · 2.36 KB
/
Copy pathapi_parser.py
File metadata and controls
68 lines (55 loc) · 2.36 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
import re
import time
from mpmath import mpf, nstr
import api_models
import extensions
class KucoinGrabber:
def __init__(self, pair, requests_session, auth, api):
self.auth = auth
self.pair = pair
self.session = requests_session
self.api = api
def grab(self):
info_dict = {
'time': time.strftime("%d.%m %H:%M:%S", time.localtime()),
'24h_info': self.api.client.get_24hr_stats(self.pair),
'orders': self.api.client.get_order_book(self.pair),
'to_btc': False,
'converted': None
}
if not re.findall('BTC', self.pair):
curr = re.findall('\w+', self.pair)
btc_price = self.api.client.get_24hr_stats(curr[1] + '-BTC')['last']
converted = nstr(mpf(info_dict['24h_info']['last']) * mpf(btc_price), 50)[:13]
info_dict['to_btc'] = True
info_dict['converted'] = converted
return info_dict
class TradeOgreGrabber:
def __init__(self, pair, requests_session, api):
self.pair = pair
self.session = requests_session
self.api = api
def grab(self):
info_dict = {
'time': time.strftime("%d.%m %H:%M:%S", time.localtime()),
'24h_info': self.api.get_market_currency(self.pair),
'orders': self.api.get_order_book(self.pair),
'to_btc': False,
'converted': None
}
if not re.findall('BTC', self.pair):
kucoin_api = api_models.KucoinApi({'api_key': None,
'api_secret': None,
'api_passphrase': None})
curr = re.findall('\w+', self.pair)
btc_price = kucoin_api.client.get_24hr_stats(curr[0] + '-BTC')['last']
converted = nstr(mpf(info_dict['24h_info'][self.pair]['price']) * mpf(btc_price), 50)[:13]
info_dict['to_btc'] = True
info_dict['converted'] = converted
# curr = re.findall('\w+', self.pair)
# btc_curr = 'BTC-' + curr[0]
# btc_price = self.api.get_market_currency(btc_curr)[btc_curr]['price']
# converted = nstr(mpf(info_dict['24h_info'][self.pair]['price']) * mpf(btc_price), 50)[:13]
# info_dict['to_btc'] = True
# info_dict['converted'] = converted
return info_dict