-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
591 lines (514 loc) · 27 KB
/
bot.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
import logging
import telegram
from telegram.ext import CommandHandler, Updater
import os
import sys
import pandas as pd
import numpy as np
from scipy import stats
import seaborn as sns
import random
import requests
import time
import pywaves as pw
class Bot(telegram.Bot):
def __init__(self, config, *args, **kwargs):
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
self.config = config
super(Bot, self).__init__(self.config['Bot']['TOKEN'], *args, **kwargs)
self.btc_price = 0
self.price = 0
self.price_cached_at = 0
self.volume = 0
self.snm_change = 0
self.dwh_deals = {}
self.dwh_deals_cached_at = 0
self.df = {}
def predict(self, bot, update):
old_price = self.price
price = self.__get_price()
increase = (self.snm_change/price)*100
if increase > 10:
foo = ['SUPER MOON', 'moon', 'moon', 'moon', 'moon', 'moon', 'two weeks', 'ded']
elif increase > 5:
foo = ['moon', 'two weeks', 'ded']
else:
foo = ['moon', 'ded', 'ded', 'ded', 'ded', 'ded', 'scam', 'ded scam', 'ded scam village', 'delisted']
bot.send_message(chat_id=update.message.chat_id, text=random.choice(foo))
def version(self, bot, update):
message = "Ver 0.5.4"
bot.send_message(chat_id=update.message.chat_id, text=message)
def DICS(selfself, bot, update):
import pywaves as pw
DICS = "Fweiconow1LnWTwCKdQzqUsbbc6xEnp1tMvFMqpm4e6F"
myToken = pw.Asset(DICS)
PAIR = pw.AssetPair(myToken, pw.BTC)
NODE = "http://nodes.wavesnodes.com"
# select the network: testnet or mainnet
NETWORK = "mainnet"
MATCHER = "http://matcher.wavesnodes.com"
pw.setNode(NODE, NETWORK)
pw.setMatcher(MATCHER)
out = PAIR.orderbook()
divider = 100000000
response = "Deal Index Coin for SONM (DICS) https://bit.ly/2QXKCDF"
response = response + "\n"
response = response + "DICS price: " + str(int(out['bids'][0]['price'] / divider)) + " sats"
response = response + "\n"
response = response + "DICS/BTC exchange: https://bit.ly/2Kg7jjZ"
bot.send_message(chat_id=update.message.chat_id, text=response)
def data_update(self):
command = "curl -s https://dwh.livenet.sonm.com:15022/DWHServer/GetDeals/ -d"
command = command + " '"
command = command + '{"status":1}'
command = command + "' > livedeal.txt"
os.system(command)
f = open('livedeal.txt', 'r')
k = f.readlines()
r = k[0].split(',')
headposition = []
i = 0
for item in r:
if 'deal' in item:
headposition.append(i)
i = i + 1
headposition.append(len(r))
testlist = []
for i in range(len(headposition)):
if headposition[i] > 0:
# print(headposition[i-1], headposition[i])
# print(r[headposition[i-1] : headposition[i]])
testlist.append(r[headposition[i - 1]: headposition[i]])
self.df = pd.DataFrame(testlist)
f.close()
del k
del r
del testlist
del headposition
del command
self.df['consumer_ID'] = self.df[18].apply(self.Supplier_ID_conversion)
self.df['supplier_ID'] = self.df[17].apply(self.Supplier_ID_conversion)
self.df['price_USD/h'] = self.df[22].apply(self.Price_conversion)
self.df['Ethash'] = self.df[10].apply(self.Ethash_conversion)
self.df['master_ID'] = self.df[19].apply(self.Master_ID_conversion)
self.df['benchmark'] = self.df[1].apply(self.benchmark)
return self.df
def stats(self, bot, update):
self.df = self.data_update()
# Run stats
df10 = self.df.groupby('supplier_ID').describe()['Ethash']
df10.to_csv('eth.csv')
df11 = pd.read_csv('eth.csv')
df11['total_Ethash'] = df11['count'] * df11['mean']
df12 = df11[['supplier_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df12.to_csv('ethash.csv', index=False)
df13 = pd.read_csv('ethash.csv')
print('Real-time total Ethash rate of the entire SONM platform is ' + str(df13['total_Ethash'].sum()) + ' Mh/s')
df13['total_revenue_USD/h'] = df13['supplier_ID'].apply(self.total_revenue)
df13['total_revenue_USD/d'] = df13['total_revenue_USD/h'] * 24
df13['revenue_USD/d'] = df13['total_revenue_USD/d'].map('${:,.2f}'.format)
# print('At this moment, total ' + str("{:.2f}".format(df13['total_revenue_USD/d'].sum())) + ' USD/day is spent on the entire SONM platform.')
df20 = self.df.groupby('master_ID').describe()['Ethash']
df20.to_csv('mastereth.csv')
df21 = pd.read_csv('mastereth.csv')
df21['total_Ethash'] = df21['count'] * df21['mean']
# df21[['master_ID','total_Ethash','count']]
df22 = df21[['master_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df22.to_csv('masterethash.csv', index=False)
df23 = pd.read_csv('masterethash.csv')
df23['total_revenue_USD/h'] = df23['master_ID'].apply(self.total_master_revenue)
df23['total_revenue_USD/d'] = df23['total_revenue_USD/h'] * 24
df23['revenue_USD/d'] = df23['total_revenue_USD/d'].map('${:,.2f}'.format)
df10 = self.df.groupby('consumer_ID').describe()['Ethash']
df10.to_csv('consumer.csv')
df11 = pd.read_csv('consumer.csv')
df11['total_Ethash'] = df11['mean'] * df11['count']
df11['total_expense_USD/h'] = df11['consumer_ID'].apply(self.total_expense)
df11['total_expense_USD/d'] = df11['total_expense_USD/h'] * 24
df11['expense_USD/d'] = df11['total_expense_USD/d'].map('${:,.2f}'.format)
df11 = df11.sort_values('total_expense_USD/h', ascending=False)
# df[df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = self.df[self.df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = df12.sort_values(['Ethash', 'price_USD/h'], ascending=False)
slope, intercept, r_value, p_value, std_err = stats.linregress(df12.Ethash, df12['price_USD/h'])
# print("Current profitability (USD/h) = " + str(slope) + " * Ethash(Mh/s)")
# self.df['benchmark'] = self.df[1].apply(benchmark)
df_cpu = self.df[self.df.consumer_ID == '0x4C5BAf6Fa57AA4b37DB3dAcd5eAf5A220Db638c7']
# df_cpu2 = df_cpu[['price_USD/h','master_ID','benchmark',0]].sort_values('price_USD/h', ascending = False)
#
# send stats to telegram
###############################################
#hashrate = format(hashrate, '.2f')
# Calculate SNM inside the sidechain here######
k = requests.get('https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=0x983f6d60db79ea8ca4eb9968c6aff8cfa04b3c63&address=0x125f1e37a45abf9b9894aefcb03d14d170d1489b')
#l = requests.get('https://api.etherscan.io/api?module=stats&action=tokensupply&contractaddress=0x983f6d60db79ea8ca4eb9968c6aff8cfa04b3c63')
sidechain_amount = int(k.json()['result'])/1000000000000000000
total_supply = 440*1000*1000
sidechain_percent = sidechain_amount/total_supply*100
sidechain_percent = format(sidechain_percent, '.4f')
###############################################
message = ('Real-time total Ethash rate of the entire SONM platform is ' + str(
df13['total_Ethash'].sum()) + ' Mh/s.')
message = message + "\n"
message = message + ('At this moment, total ' + str(
"{:.2f}".format(df13['total_revenue_USD/d'].sum())) + ' USD/day are spent on the entire SONM platform.')
message = message + "\n"
message = message + ('GPU-Connor currently has ' + str(len(df12)) + ' deals.')
message = message + "\n"
message = message + (
'GPU-Connor currently pays ' + str("{:.2f}".format(df12['price_USD/h'].sum() * 24)) + " USD/day.")
message = message + "\n"
message = message + ('GPU-Connor currently mines ETH with ' + str(df12['Ethash'].sum()) + ' Mh/s hashrate.')
message = message + "\n"
message = message + ('There are ' + str(len(df23)) + ' unique suppliers at this moment.')
message = message + "\n"
message = message + (
'There are ' + str(len(df23[df23['total_Ethash'] > 0])) + ' unique GPU suppliers at this moment.')
message = message + "\n"
message = message + ('There are ' + str(
len(df23) - len(df23[df23['total_Ethash'] > 0])) + ' unique CPU suppliers at this moment.')
message = message + "\n"
message = message + ('There are ' + str(len(df11)) + ' unique consumers at this moment.')
message = message + "\n"
message = message + ('Currenlty, there are total ' + str(len(self.df)) + ' deals.')
message = message + "\n"
message = message + ('Of which ' + str(len(self.df[self.df.Ethash > 0])) + ' deals contain GPU.')
message = message + "\n"
message = message + ('And ' + str(len(self.df[self.df.Ethash == 0])) + ' deals are CPU only.')
message = message + "\n"
# message = message + ("Current profitability (USD/h) = " + str(slope) + " * Ethash(Mh/s)")
# message = message + "\n"
message = message + ('CPU-Connor currently has ' + str(len(df_cpu)) + ' deals.')
message = message + "\n"
message = message + (
'CPU-Connor currently pays ' + str("{:.2f}".format(df_cpu['price_USD/h'].sum() * 24)) + " USD/day.")
message = message + "\n"
message = message + ("Currently " + str(sidechain_amount)+ " SNM are deposited in the SONM side-chain, which are " + str(sidechain_percent) + "% of the total supply.")
# Push the message to the bot here
bot.send_message(chat_id=update.message.chat_id, text=message)
#
del df10
del df11
del df12
del df13
del df20
del df21
del df22
del df23
del df_cpu
def gpu(self, bot, update):
self.df = self.data_update()
# Run stats
df10 = self.df.groupby('supplier_ID').describe()['Ethash']
df10.to_csv('eth.csv')
df11 = pd.read_csv('eth.csv')
df11['total_Ethash'] = df11['count'] * df11['mean']
df12 = df11[['supplier_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df12.to_csv('ethash.csv', index=False)
df13 = pd.read_csv('ethash.csv')
print('Real-time total Ethash rate of the entire SONM platform is ' + str(
df13['total_Ethash'].sum()) + ' Mh/s')
df13['total_revenue_USD/h'] = df13['supplier_ID'].apply(self.total_revenue)
df13['total_revenue_USD/d'] = df13['total_revenue_USD/h'] * 24
df13['revenue_USD/d'] = df13['total_revenue_USD/d'].map('${:,.2f}'.format)
# print('At this moment, total ' + str("{:.2f}".format(df13['total_revenue_USD/d'].sum())) + ' USD/day is spent on the entire SONM platform.')
df20 = self.df.groupby('master_ID').describe()['Ethash']
df20.to_csv('mastereth.csv')
df21 = pd.read_csv('mastereth.csv')
df21['total_Ethash'] = df21['count'] * df21['mean']
# df21[['master_ID','total_Ethash','count']]
df22 = df21[['master_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df22.to_csv('masterethash.csv', index=False)
df23 = pd.read_csv('masterethash.csv')
df23['total_revenue_USD/h'] = df23['master_ID'].apply(self.total_master_revenue)
df23['total_revenue_USD/d'] = df23['total_revenue_USD/h'] * 24
df23['revenue_USD/d'] = df23['total_revenue_USD/d'].map('${:,.2f}'.format)
message = 'GPU suppliers: ' + str(len(df23[df23['total_Ethash'] > 0]))
message = message + "\n"
message = message + 'GPU deals: ' + str(len(self.df[self.df.Ethash > 0]))
message = message + "\n"
bot.send_message(chat_id=update.message.chat_id, text=message)
del df23
del df22
del df21
del df20
del df13
del df12
del df11
del df10
def consumers(self, bot, update):
self.df = self.data_update()
# Run stats
df10 = self.df.groupby('supplier_ID').describe()['Ethash']
df10.to_csv('eth.csv')
df11 = pd.read_csv('eth.csv')
df11['total_Ethash'] = df11['count'] * df11['mean']
df12 = df11[['supplier_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df12.to_csv('ethash.csv', index=False)
df13 = pd.read_csv('ethash.csv')
print('Real-time total Ethash rate of the entire SONM platform is ' + str(df13['total_Ethash'].sum()) + ' Mh/s')
df13['total_revenue_USD/h'] = df13['supplier_ID'].apply(self.total_revenue)
df13['total_revenue_USD/d'] = df13['total_revenue_USD/h'] * 24
df13['revenue_USD/d'] = df13['total_revenue_USD/d'].map('${:,.2f}'.format)
# print('At this moment, total ' + str("{:.2f}".format(df13['total_revenue_USD/d'].sum())) + ' USD/day is spent on the entire SONM platform.')
df20 = self.df.groupby('master_ID').describe()['Ethash']
df20.to_csv('mastereth.csv')
df21 = pd.read_csv('mastereth.csv')
df21['total_Ethash'] = df21['count'] * df21['mean']
# df21[['master_ID','total_Ethash','count']]
df22 = df21[['master_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df22.to_csv('masterethash.csv', index=False)
df23 = pd.read_csv('masterethash.csv')
df23['total_revenue_USD/h'] = df23['master_ID'].apply(self.total_master_revenue)
df23['total_revenue_USD/d'] = df23['total_revenue_USD/h'] * 24
df23['revenue_USD/d'] = df23['total_revenue_USD/d'].map('${:,.2f}'.format)
df10 = self.df.groupby('consumer_ID').describe()['Ethash']
df10.to_csv('consumer.csv')
df11 = pd.read_csv('consumer.csv')
df11['total_Ethash'] = df11['mean'] * df11['count']
df11['total_expense_USD/h'] = df11['consumer_ID'].apply(self.total_expense)
df11['total_expense_USD/d'] = df11['total_expense_USD/h'] * 24
df11['expense_USD/d'] = df11['total_expense_USD/d'].map('${:,.2f}'.format)
df11 = df11.sort_values('total_expense_USD/h', ascending=False)
# df[df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = self.df[self.df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = df12.sort_values(['Ethash', 'price_USD/h'], ascending=False)
# Consumer plot
sns.set()
sns.lmplot(y="total_Ethash", x="total_expense_USD/h", data=df11, fit_reg=False, hue='consumer_ID',
legend=True).savefig("consumer.png")
bot.send_photo(chat_id=update.message.chat_id, photo=open('consumer.png', 'rb'))
del df11
del df10
del df12
del df13
del df20
del df21
del df22
del df23
def suppliers(self, bot, update):
self.df = self.data_update()
# Run stats
df10 = self.df.groupby('supplier_ID').describe()['Ethash']
df10.to_csv('eth.csv')
df11 = pd.read_csv('eth.csv')
df11['total_Ethash'] = df11['count'] * df11['mean']
df12 = df11[['supplier_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df12.to_csv('ethash.csv', index=False)
df13 = pd.read_csv('ethash.csv')
print('Real-time total Ethash rate of the entire SONM platform is ' + str(df13['total_Ethash'].sum()) + ' Mh/s')
df13['total_revenue_USD/h'] = df13['supplier_ID'].apply(self.total_revenue)
df13['total_revenue_USD/d'] = df13['total_revenue_USD/h'] * 24
df13['revenue_USD/d'] = df13['total_revenue_USD/d'].map('${:,.2f}'.format)
# print('At this moment, total ' + str("{:.2f}".format(df13['total_revenue_USD/d'].sum())) + ' USD/day is spent on the entire SONM platform.')
df20 = self.df.groupby('master_ID').describe()['Ethash']
df20.to_csv('mastereth.csv')
df21 = pd.read_csv('mastereth.csv')
df21['total_Ethash'] = df21['count'] * df21['mean']
# df21[['master_ID','total_Ethash','count']]
df22 = df21[['master_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df22.to_csv('masterethash.csv', index=False)
df23 = pd.read_csv('masterethash.csv')
df23['total_revenue_USD/h'] = df23['master_ID'].apply(self.total_master_revenue)
df23['total_revenue_USD/d'] = df23['total_revenue_USD/h'] * 24
df23['revenue_USD/d'] = df23['total_revenue_USD/d'].map('${:,.2f}'.format)
df10 = self.df.groupby('consumer_ID').describe()['Ethash']
df10.to_csv('consumer.csv')
df11 = pd.read_csv('consumer.csv')
df11['total_Ethash'] = df11['mean'] * df11['count']
df11['total_expense_USD/h'] = df11['consumer_ID'].apply(self.total_expense)
df11['total_expense_USD/d'] = df11['total_expense_USD/h'] * 24
df11['expense_USD/d'] = df11['total_expense_USD/d'].map('${:,.2f}'.format)
df11 = df11.sort_values('total_expense_USD/h',
ascending=False) # df[df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = self.df[self.df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = df12.sort_values(['Ethash', 'price_USD/h'], ascending=False)
slope, intercept, r_value, p_value, std_err = stats.linregress(df12.Ethash, df12['price_USD/h'])
df_cpu = self.df[self.df.consumer_ID == '0x4C5BAf6Fa57AA4b37DB3dAcd5eAf5A220Db638c7']
# Supplier plot
sns.set()
sns.lmplot(y="total_Ethash", x="total_revenue_USD/h", data=df23, fit_reg=False, hue='master_ID',
legend=True).savefig("supplier.png")
#
bot.send_photo(chat_id=update.message.chat_id, photo=open('supplier.png', 'rb'))
del df22
del df23
del df21
del df20
del df13
del df12
del df10
del df11
del df_cpu
def profit(self, bot, update):
self.df = self.data_update()
# Run stats
df10 = self.df.groupby('supplier_ID').describe()['Ethash']
df10.to_csv('eth.csv')
df11 = pd.read_csv('eth.csv')
df11['total_Ethash'] = df11['count'] * df11['mean']
df12 = df11[['supplier_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df12.to_csv('ethash.csv', index=False)
df13 = pd.read_csv('ethash.csv')
print('Real-time total Ethash rate of the entire SONM platform is ' + str(df13['total_Ethash'].sum()) + ' Mh/s')
df13['total_revenue_USD/h'] = df13['supplier_ID'].apply(self.total_revenue)
df13['total_revenue_USD/d'] = df13['total_revenue_USD/h'] * 24
df13['revenue_USD/d'] = df13['total_revenue_USD/d'].map('${:,.2f}'.format)
# print('At this moment, total ' + str("{:.2f}".format(df13['total_revenue_USD/d'].sum())) + ' USD/day is spent on the entire SONM platform.')
df20 = self.df.groupby('master_ID').describe()['Ethash']
df20.to_csv('mastereth.csv')
df21 = pd.read_csv('mastereth.csv')
df21['total_Ethash'] = df21['count'] * df21['mean']
# df21[['master_ID','total_Ethash','count']]
df22 = df21[['master_ID', 'total_Ethash', 'count']].sort_values('total_Ethash', ascending=False)
df22.to_csv('masterethash.csv', index=False)
df23 = pd.read_csv('masterethash.csv')
df23['total_revenue_USD/h'] = df23['master_ID'].apply(self.total_master_revenue)
df23['total_revenue_USD/d'] = df23['total_revenue_USD/h'] * 24
df23['revenue_USD/d'] = df23['total_revenue_USD/d'].map('${:,.2f}'.format)
df10 = self.df.groupby('consumer_ID').describe()['Ethash']
df10.to_csv('consumer.csv')
df11 = pd.read_csv('consumer.csv')
df11['total_Ethash'] = df11['mean'] * df11['count']
df11['total_expense_USD/h'] = df11['consumer_ID'].apply(self.total_expense)
df11['total_expense_USD/d'] = df11['total_expense_USD/h'] * 24
df11['expense_USD/d'] = df11['total_expense_USD/d'].map('${:,.2f}'.format)
df11 = df11.sort_values('total_expense_USD/h', ascending=False)
# df[df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = self.df[self.df.consumer_ID == '0x417c92FbD944b125A578848DE44a4FD9132E0911']
df12 = df12.sort_values(['Ethash', 'price_USD/h'], ascending=False)
slope, intercept, r_value, p_value, std_err = stats.linregress(df12.Ethash, df12['price_USD/h'])
df_cpu = self.df[self.df.consumer_ID == '0x4C5BAf6Fa57AA4b37DB3dAcd5eAf5A220Db638c7']
# Profitability
msg = ("Current profitability (USD/h) = " + str(slope) + " * Ethash(Mh/s)")
msg = msg + "\n"
msg = msg + (" ")
msg = msg + "\n"
msg = msg + ("GPU card EThash SONM profitability")
msg = msg + "\n"
msg = msg + ("Nvida GTX 1050 TI 15 Mh/s " + str("{:.2f}".format(slope * 15 * 24)) + " USD/day")
msg = msg + "\n"
msg = msg + ("Nvida GTX 1060 24 Mh/s " + str("{:.2f}".format(slope * 24 * 24)) + " USD/day")
msg = msg + "\n"
msg = msg + ("Nvida GTX 1070 TI 32 Mh/s " + str("{:.2f}".format(slope * 32 * 24)) + " USD/day")
msg = msg + "\n"
msg = msg + ("Nvida GTX 1080 27 Mh/s " + str("{:.2f}".format(slope * 27 * 24)) + " USD/day")
msg = msg + "\n"
msg = msg + ("Nvida GTX 1080 TI 37 Mh/s " + str("{:.2f}".format(slope * 37 * 24)) + " USD/day")
msg = msg + "\n"
msg = msg + ("Nvida GTX TITAN 40 Mh/s " + str("{:.2f}".format(slope * 40 * 24)) + " USD/day")
msg = msg + "\n"
msg = msg + ("Nvida GTX 1080 +pill 40 Mh/s " + str("{:.2f}".format(slope * 40 * 24)) + " USD/day")
msg = msg + "\n"
msg = msg + ("Nvida GTX 1080 TI +pill 50 Mh/s " + str("{:.2f}".format(slope * 50 * 24)) + " USD/day")
#
bot.send_message(chat_id=update.message.chat_id, text=msg)
del df11
del df_cpu
del df10
del df12
del df13
del df20
del df21
del df23
del df22
def benchmark(self, content):
return int(content[content.find('[') + 1:])
def Supplier_ID_conversion(self, content):
return content[14:-1]
def Price_conversion(self, content):
unit = 10.0 ** 18.0
if 'price' in content:
return float(content[9:-1]) / unit * 60 * 60
if 'duration' in content:
return float(content[11:-1]) / unit * 60 * 60
def Ethash_conversion(self, content):
return float(content) / 1000000
def Master_ID_conversion(self, content):
return content[12:-1]
def total_revenue(self, address):
return self.df[self.df.supplier_ID == address]['price_USD/h'].sum()
def total_master_revenue(self, address):
return self.df[self.df.master_ID == address]['price_USD/h'].sum()
def total_expense(self, address):
return self.df[self.df.consumer_ID == address]['price_USD/h'].sum()
def token_price(self, bot, update):
old_price = self.price
price = self.__get_price()
usd_price = format((self.btc_price * price/100000000), '.3f')
hashrate = 0
for deal in self.__get_dwh_deals():
hashrate += deal["deal"]["benchmarks"]["values"][9]
hashrate /= 1000000 # convert to MH/s
hashrate /= 1000 # further convert to GH/s
hashrate = format(hashrate, '.2f')
DICS = "Fweiconow1LnWTwCKdQzqUsbbc6xEnp1tMvFMqpm4e6F"
myToken = pw.Asset(DICS)
PAIR = pw.AssetPair(myToken, pw.BTC)
NODE = "http://nodes.wavesnodes.com"
# select the network: testnet or mainnet
NETWORK = "mainnet"
MATCHER = "http://matcher.wavesnodes.com"
pw.setNode(NODE, NETWORK)
pw.setMatcher(MATCHER)
out = PAIR.orderbook()
divider = 100000000
#return int(out['bids'][0]['price'] / divider)
DICS_price = int(out['bids'][0]['price'] / divider)
#DICS_price = DICS_price()
usd_DICS_price = format((self.btc_price * DICS_price/100000000), '.3f')
msg = """\
SNM Price: {price} sats (${usd} US)\n\
Volume: {vol} BTC\n\
\n\
(Source: Binance)\n\
\n\
Deals: {deals}\n\
DICS Price: {DICS_price} sats (${DICS_usd} US)\n\
ETH-hashrate: {hashrate} GH/s""".format(price=price, usd=usd_price, vol=self.volume, deals=len(self.__get_dwh_deals()), DICS_price = DICS_price, DICS_usd = usd_DICS_price, hashrate=hashrate)
bot.send_message(chat_id=update.message.chat_id, text=msg)
def __commands(self, dispatcher):
dispatcher.add_handler(CommandHandler("stats", self.stats))
dispatcher.add_handler(CommandHandler("version", self.version))
dispatcher.add_handler(CommandHandler("profit", self.profit))
dispatcher.add_handler(CommandHandler("suppliers", self.suppliers))
dispatcher.add_handler(CommandHandler("consumers", self.consumers))
dispatcher.add_handler(CommandHandler("predict", self.predict))
dispatcher.add_handler(CommandHandler("price", self.token_price))
dispatcher.add_handler(CommandHandler("gpu", self.gpu))
dispatcher.add_handler(CommandHandler("DICS", self.DICS))
def __get_dwh_deals(self):
ts = time.time()
if ts > self.dwh_deals_cached_at + 60:
try:
r = requests.request(method='get', url='https://dwh.livenet.sonm.com:15022/DWHServer/GetDeals/', data='{"status": 1}')
data = r.json()
self.dwh_deals = data["deals"]
self.dwh_deals_cached_at = ts
except Exception as e:
print(e)
return self.dwh_deals # return latest known price
return self.dwh_deals
def __get_price(self):
ts = time.time()
if ts > self.price_cached_at + 60:
try:
r = requests.get('https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT')
self.btc_price = int(float(r.json()["lastPrice"]))
r = requests.get('https://api.binance.com/api/v1/ticker/24hr?symbol=SNMBTC')
data = r.json()
self.price = int(float(data["lastPrice"]) * 100000000) # convert to satoshis
self.volume = int(float(data["quoteVolume"]))
self.snm_change = int(float(data["priceChange"]) * 100000000) # change is converted to satoshis
self.price_cached_at = ts
except Exception as e:
print(e)
return self.price # return latest known price
return self.price
def start(self):
updater = Updater(token=self.config['Bot']['TOKEN'])
dispatcher = updater.dispatcher
self.__commands(dispatcher)
updater.start_polling()
updater.idle()