forked from c00w/bitHopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool_class.py
161 lines (134 loc) · 6.18 KB
/
pool_class.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/python
#License#
#bitHopper by Colin Rice is licensed under a Creative Commons
# Attribution-NonCommercial-ShareAlike 3.0 Unported License.
#Based on a work at github.com.
import time, logging
class Pool():
def __init__(self, name, attribute_dict, bitHopper):
self.bitHopper = bitHopper
self.dict = {'index_name':name}
self._parse(attribute_dict)
def _parse(self, attribute_dict):
self['shares'] = int(self.bitHopper.difficulty['btc'])
self['ghash'] = -1
self['duration'] = -2
self['duration_temporal'] = 0
self['isDurationEstimated'] = False
self['last_pulled'] = time.time()
self['lag'] = False
self['api_lag'] = False
refresh_limit = self.bitHopper.config.getint('main', 'pool_refreshlimit')
self['refresh_time'] = int(attribute_dict.get('refresh_time', refresh_limit))
self['refresh_limit'] = int(attribute_dict.get('refresh_limit', refresh_limit))
self['rejects'] = self.bitHopper.db.get_rejects(self['index_name'])
self['user_shares'] = self.bitHopper.db.get_shares(self['index_name'])
self['payout'] = self.bitHopper.db.get_payout(self['index_name'])
self['expected_payout'] = self.bitHopper.db.get_expected_payout(self['index_name'])
self['name'] = attribute_dict.get('name', self[
'index_name'])
self['wallet'] = attribute_dict.get('wallet', '')
self['api_address'] = attribute_dict.get('api_address', self['index_name'])
self['role'] = attribute_dict.get('role', 'disable')
if self['role'] in ['mine_slush']:
self['role'] = 'mine_c'
self['c'] = 300
self['lp_address'] = attribute_dict.get('lp_address', None)
self['err_api_count'] = 0
self['pool_index'] = self['index_name']
self['default_role'] = self['role']
if self['default_role'] in ['info','disable']:
self['default_role'] = 'mine'
#Pools are now grouped by priority
self['priority'] = int(attribute_dict.get('priority', 0))
#Coin Handling
coin_roles = {'mine': 'btc', 'info': 'btc', 'backup': 'btc', 'backup_latehop': 'btc', 'mine_charity': 'btc', 'mine_c':'btc', 'mine_force':'btc'}
for coin in self.bitHopper.altercoins.itervalues():
if coin['short_name'] != 'btc':
coin_roles[coin['short_name']] = 'mine_' + coin['short_name']
if 'coin' not in attribute_dict:
try: coin_type = coin_roles[self['role']]
except KeyError: coin_type = 'btc'
self['coin'] = coin_type
else:
self['coin'] = attribute_dict['coin']
#Everything not explicitly handled should be set
for attr in attribute_dict:
if attr not in self.dict:
self.dict[attr] = attribute_dict[attr]
def __lt__(self, other):
#Ordering of backup roles
role_order = {'backup_latehop':0,'backup':1}
#If the roles are different use the role_order if it exists
if self['role'] != other['role']:
if self['role'] in role_order and other['role'] in role_order:
return role_order[self['role']] < role_order[other['role']]
#backup sorts by reject rate
if self['role'] in ['backup']:
rr_self = float(self['rejects'])/(self['user_shares']+1)
rr_self += float(self.get('penalty', 0.0)) / 100
rr_other = float(other['rejects'])/(other['user_shares']+1)
rr_other += float(other.get('penalty', 0.0)) / 100
return rr_self < rr_other
#backup latehop sorts purely by shares
if self['role'] in ['backup_latehop']:
return self['shares'] < other['shares']
#disabled pools should never end up in a list
elif other['role'] in ['disable']:
return True
elif self['role'] in ['disable']:
return False
else:
if self['coin'] == other['coin']:
return self['shares'] < other['shares']
else:
self_proff = self.bitHopper.exchange.profitability.get(self['coin'],0)
other_proff = self.bitHopper.exchange.profitability.get(other['coin'],0)
return self_proff < other_proff
def btc_shares(self):
coin_diffs = {}
for attr_coin in self.bitHopper.altercoins.itervalues():
coin_diffs[attr_coin['short_name']] = self.bitHopper.difficulty[attr_coin['short_name']]
if self['coin'] in ['btc']:
shares = self['shares']
try: shares = self['shares'] * coin_diffs['btc'] / coin_diffs[self['coin']]
except KeyError: shares = coin_diffs['btc']
if self['role'] == 'mine_c':
#Checks if shares are to high and if so sends it through the roof
#So we don't mine it.
try:
c = float(self['c'])
except:
c = 300
hashrate = float(self['ghash'])
hopoff = coin_diffs['btc'] * (0.0164293 + 1.14254 / (1.8747 * (coin_diffs['btc'] / (c * hashrate)) + 2.71828))
if shares > hopoff:
shares = 2*coin_diffs['btc']
if self['role'] in ['mine_force', 'mine_lp_force']:
shares = 0
# apply penalty
shares = shares * float(self.get('penalty', 1))
return shares, self
def is_valid(self):
if self['lag']:
return False
if self['role'] not in ['backup', 'backup_latehop'] and self['api_lag']:
return False
try:
coin_proff = float(self.config.getboolean('main', 'min_coin_proff'))
except:
coin_proff = 1.0
if self.bitHopper.exchange.profitability.get(self['coin'],0) < coin_proff and self['coin'] != 'btc':
return False
return True
def __getitem__(self, key):
return self.dict[key]
def get(self, key, default=None):
if default != None:
return self.dict.get(key, default)
else:
return self.dict.get(key)
def __setitem__(self, key, value):
self.dict[key] = value
def __contains__(self, item):
return item in self.dict