-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.py
executable file
·131 lines (108 loc) · 3.22 KB
/
cli.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
124
125
126
127
128
129
130
131
#!/usr/bin/python2.7
import sys
import time
from poloniex import Poloniex
pl = Poloniex()
# 1m | 5m | 10m | 20m | 30m | 1h | 3h | 6h | 12h | 24h | Price |Volume
x = [0, 1, 2, 4, 6, 12, 36, 72, 144, 288]
# get_volumes returns volumes from X different coins.
def get_volumes():
cur_print = []
btc_price = get_btc_price()
try:
Volumes = pl.return24hVolume()
except:
return 1
for i in Volumes:
if "USDT_" in i:
cur_print.append((i,int(float(Volumes[i]['USDT']))))
if "BTC_" in i:
cur_print.append((i,int(float(Volumes[i]['BTC']))*btc_price))
cur_print.sort(key=lambda tup:tup[1], reverse=True)
if len(sys.argv)>1:
results=int(sys.argv[1])
else:
results = 30
return cur_print[0:results]
# get_btc_price returns BTC price in USDT.
def get_btc_price():
return float(pl.returnTicker()['USDT_BTC']['last'])
# get_indicator returns a symbol, indicating if price is going up or down,
# according to simple moving average. SHOULDN'T BE TAKEN TOO SERIOUS!
def get_indicator(d):
# not used yet.
if sideways:
return '\u219D'
if sell:
return '\u2198'
if buy:
return '\u2197'
def var(list_):
val_list = []
for i in range(1,len(x)):
val = round(float(list_[x[i-1]]*100/list_[x[i]])-100, 2)
val_list.append(add_color(val))
val_list.append(add_color(round(float(list_[0]*100/list_[x[-1]-1])-100, 2)))
return val_list
# add_color adds color to CLI, according to price variation.
def add_color(val):
if val < -3 or val >3:
factor = '7'
else:
factor = '1'
#'\033[1;32m
if val > 0:
val = '\033[{};32m{:^6}\033[0;m'.format(factor,str(val))
#color = 'green'
elif val < 0:
val = '\033[{};31m{:^6}\033[0;m'.format(factor,str(val))
#color = 'red'
else:
val = '\033[{};30m{:^6}\033[0;m'.format('1','0.0')
return val
# print_head plots first line of CLI.
def print_head():
print '{:^10}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^10}|{:^8}'\
.format('Pair','1m','5m','10m','20m','30m',
'1h','3h','6h','12h','24h', 'Price','Volume')
print ' {}+{}+{}+{}+{}+{}+{}+{}+{}+{}+{}+{}+{}'\
.format('-'*9,'-'*6,'-'*6,'-'*6,'-'*6,'-'*6,
'-'*6,'-'*6,'-'*6,'-'*6,'-'*6,'-'*10,'-'*8)
# main
def main():
if len(sys.argv)==1:
stop = 30
else:
if ('--nocolor' or '-c') in sys.argv:
nocolor = True
# if ('--mycoins' or '-m') in sys.argv:
if len(sys.argv)>1:
stop = int(sys.argv[1])
else:
stop = 30
print "\033c"
print_head()
while(1):
try:
currencies = get_volumes()
for currency in currencies:
if currency[1] > 200000:
a = [float(item['weightedAverage']) for item in pl.returnChartData(currency[0],300)]
val_list = var(list(reversed(a)))
if a[-1]>1:
price_val = "%.4f" % a[-1]
else:
price_val = "%.8f" % a[-1]
print '{:^10}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^6}|{:^10}|{:>6}'\
.format(currency[0], val_list[0], val_list[1], val_list[2], val_list[3],
val_list[4], val_list[5], val_list[6], val_list[7], val_list[8],
val_list[9], price_val, str(int(currency[1]/1000000)) + ' M')
old_currencies = currencies
except Exception as e:
print "\033c"
print "Error getting data."
time.sleep(60 - stop)
print "\033c"
print_head()
if __name__=="__main__":
main()