-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path__main__.py
98 lines (89 loc) · 2.75 KB
/
__main__.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
from pymongo import MongoClient
from exchangeAPI.poloniex import Poloniex
from exchangeAPI.bitmex import Bitmex
from exchangeAPI.bitfinex import Bitfinex
from exchangeAPI.bittrex import Bittrex
from exchangeAPI.gdax import Gdax
from multiprocessing import Process
from database import Data
import parallel
import utility
import sys
import time
import copy
proc = []
def command_handler(command):
command = command.split(' ')
if command[0] == '/help':
print (utility.help_message)
utility.wtf()
return
if command[0] == '/add':
exch_check_er = utility.check_exchanges(command[2:])
if exch_check_er:
utility.wtf()
return
pair_er = utility.check_cur_pair(command[1], command[2:])
if pair_er:
utility.wtf()
return
setup_dict = copy.deepcopy(utility.template)
if len(command[2:]) == 0:
print ('Enter exchanges.')
utility.wtf()
return
for exchange in command[2:]:
setup_dict[exchange].append(command[1])
db = Data()
db.setup(setup_dict)
print ('OK, instrument added to collector. Use /on to start gathering information.')
utility.wtf()
return
if command[0] == '/remove':
exch_check_er = utility.check_exchanges(command[2:])
if exch_check_er:
utility.wtf()
return
db = Data()
db.remove(command[1], command[2:])
utility.wtf()
return
if command[0] == '/info':
db = Data()
cur_setup = db.get_cur_setup()
for key, item in cur_setup.items():
print (key, ':', item)
utility.wtf()
return
global proc
if command[0] == '/off':
if len(proc) != 0:
parallel.stop_collecting(proc[0])
print ('Collecting stopped.')
proc = []
utility.wtf()
return
if command[0] == '/on':
proc.append(Process(target=parallel.start_collecting, args=()))
proc[0].start()
print ('Collecting started.')
utility.wtf()
return
raise BaseException
if __name__ == '__main__':
print ('You are using exchange statistics collector.\nEnter command to start gathering information.\n'
'Enter /help to get list of available commands.')
while True:
try:
command = input().strip()
command_handler(command)
except KeyboardInterrupt:
print ('Turning bot off...')
db = Data()
db.clean()
if len(proc) != 0:
parallel.stop_collecting(proc[0])
sys.exit(0)
except:
print ('Unrecognized command. Please, try again.')
utility.wtf()