-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdatabase.py
68 lines (60 loc) · 1.87 KB
/
database.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
from pymongo import MongoClient
from utility import template
class Data(object):
def __init__(self):
self.database = MongoClient()['ExchangeStat']
def setup(self, setup_dict):
cur_setup = self.database['setup'].find_one()
if cur_setup != None:
for key in setup_dict.keys():
if len(setup_dict[key]) != 0:
if setup_dict[key][0] not in cur_setup[key]:
cur_setup[key].extend(setup_dict[key])
self.database['setup'].update_one(
{},
{
'$set' : cur_setup
}
)
else:
self.database['setup'].insert_one(
setup_dict
)
def get_cur_setup(self):
cur_setup = self.database['setup'].find_one()
if cur_setup == None:
return template
else:
cur_setup.pop('_id')
return cur_setup
def remove(self, pair, exchanges):
cur_setup = self.database['setup'].find_one()
if cur_setup == None:
return
else:
for cur in exchanges:
try:
cur_setup[cur].remove(pair)
except:
pass
self.database['setup'].update_one(
{},
{
'$set' : cur_setup
}
)
def insert_tick(self, tick):
self.database['tickers'].insert_one(
tick
)
def get_tickers(self):
tickers = self.database['tickers'].find()
return tickers
def del_tickers(self):
self.database['tickers'].delete_many({})
def clean(self):
cur_setup = self.database['setup'].find_one()
if cur_setup != None:
self.database['setup'].delete_one(
cur_setup
)