-
Notifications
You must be signed in to change notification settings - Fork 5
/
bot.py
executable file
Β·377 lines (280 loc) Β· 20.2 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
#!/usr/bin/env python
import os
import telebot
import logging
from telebot import types
from decouple import config
import requests
from requests import Request, Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
import json
import random
TOKEN = config("TOKEN")
CMC_API_KEY = config("CMC_KEY")
bot = telebot.TeleBot(TOKEN, parse_mode="HTML") # You can set parse_mode by default. HTML or MARKDOWN
# This will start the bot for a new user
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
cid = message.chat.id
bot.reply_to(message, "Welcome to CryptoPrice Bot, this Bot provides you with Up-to-date Cryptocurrencies Price\n\n Type 'Waves' to get Waves Price OR 'BTC' to get Bitcoin Price and you can do the Same for All Cryptocurrencies")
# this handles messages from group chats
@bot.message_handler(commands=['price', 'p', 'waves'])
def price_finder(message):
query = message.text.split()
coin_symbol = query[1].upper()
print(coin_symbol)
if message.chat.type == "group" or message.chat.type == "supergroup":
try:
crypto_requests = requests.get("https://wavescap.com/api/asset/{}.json".format(coin_symbol))
crypto_data = crypto_requests.json()
coin_price = crypto_data["data"]["lastPrice_usdt"]
first_price = crypto_data["data"]["firstPrice_usdt"]
percent_change_float = (float(coin_price) / float(first_price) - 1) * 100
percent_change = round(percent_change_float, 2)
round_coin_price = round(coin_price,5)
coin_name = crypto_data["name"]
volume_full = crypto_data["24h_vol_usdt"]
volume = round(volume_full,5)
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell USDT on Lopeer.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
except Exception as e:
cmc_url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
cmc_parameters = {
'symbol': coin_symbol,
}
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': CMC_API_KEY,
}
session = Session()
session.headers.update(headers)
try:
response = session.get(cmc_url, params=cmc_parameters)
data = json.loads(response.text)
price = data['data'][coin_symbol]['quote']['USD']['price']
volume = data['data'][coin_symbol]['quote']['USD']['volume_24h']
percent_change = data['data'][coin_symbol]['quote']['USD']['percent_change_24h']
round_coin_price = round(price,18)
coin_name = data['data'][coin_symbol]['name']
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto on Lopeer.</a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Free Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer P2P.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
# Start of Custom Waves Asset Check
except Exception as e:
print(e)
print("At fore part")
if coin_symbol == "ROE":
coin_symbol = "A4h9aifPtz371noBA1Khi2Eb4L3Vzf8LC8PtF4QysEd9"
print(coin_symbol)
ticker = 'ROE'
coin_name = 'FROE'
cmc_url = 'https://api.wavesplatform.com/v0/pairs/{}/DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p'.format(coin_symbol)
headers = {
'accepts': 'application/json',
}
session = Session()
session.headers.update(headers)
try:
response = session.get(cmc_url)
data = json.loads(response.text)
# print(data)
price = data['data']["lastPrice"]
volume = data['data']["quoteVolume"]
round_coin_price = round(price,5)
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto with Lopeer. </a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Free Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer P2P.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
except (Exception, KeyError) as e:
print(e)
response = '''Sorry, We do not support this Token/Coin at this Time\n\n Enter '/price Coin Symbol' or Shortcode to get started\n E.g, '/price BTC', ETH, NSBT \n\n <a href="https://onelink.to/e6jquz/">π° Buy & Sell USDT with Naira.</a>'''
bot.reply_to(message, response, disable_web_page_preview=True)
except (Exception, KeyError) as e:
print(e)
response = '''Sorry, We do not support this Token/Coin at this Time\n\n Enter '/price Coin Symbol' or Shortcode to get started\n E.g, '/price BTC', ETH, NSBT \n\n <a href="https://www.lopeer.com">π° Buy & Sell Crypto with Lopeer P2P.</a>'''
bot.reply_to(message, response, disable_web_page_preview=True)
if message.chat.type == "private":
query = message.text.split()
coin_symbol = query[1].upper()
print(coin_symbol)
try:
crypto_requests = requests.get("https://wavescap.com/api/asset/{}.json".format(coin_symbol))
crypto_data = crypto_requests.json()
coin_price = crypto_data["data"]["lastPrice_usdt"]
first_price = crypto_data["data"]["firstPrice_usdt"]
percent_change_float = (float(coin_price) / float(first_price) - 1) * 100
percent_change = round(percent_change_float,2)
round_coin_price = round(coin_price,5)
volume_full = crypto_data["24h_vol_usdt"]
volume = round(volume_full,5)
coin_name = crypto_data["name"]
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto with Lopeer.</a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Free Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer P2P.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
except Exception as e:
cmc_url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
cmc_parameters = {
'symbol': coin_symbol,
}
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': CMC_API_KEY,
}
session = Session()
session.headers.update(headers)
try:
response = session.get(cmc_url, params=cmc_parameters)
data = json.loads(response.text)
price = data['data'][coin_symbol]['quote']['USD']['price']
volume = data['data'][coin_symbol]['quote']['USD']['volume_24h']
percent_change = data['data'][coin_symbol]['quote']['USD']['percent_change_24h']
round_coin_price = round(price,18)
coin_name = data['data'][coin_symbol]['name']
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto on Lopeer. </a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Free Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
# Start of Custom Waves Asset Check
except Exception as e:
print(e)
print("At fore part")
if coin_symbol == "ROE":
coin_symbol = "A4h9aifPtz371noBA1Khi2Eb4L3Vzf8LC8PtF4QysEd9"
print(coin_symbol)
ticker = 'ROE'
coin_name = "FROE"
cmc_url = 'https://api.wavesplatform.com/v0/pairs/{}/DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p'.format(coin_symbol)
headers = {
'accepts': 'application/json',
}
session = Session()
session.headers.update(headers)
try:
response = session.get(cmc_url)
data = json.loads(response.text)
# print(data)
price = data['data']["lastPrice"]
volume = data['data']["quoteVolume"]
round_coin_price = round(price,5)
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Free Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer P2P.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
except (Exception, KeyError) as e:
print(e)
response = '''Sorry, We do not support this Token/Coin at this Time\n\n Enter '/price Coin Symbol' or Shortcode to get started\n E.g, '/price BTC', ETH, NSBT \n\n <a href="https://www.lopeer.com">π° Buy & Sell Crypto with Lopeer P2P.</a>'''
bot.reply_to(message, response, disable_web_page_preview=True)
except (Exception, KeyError) as e:
print(e)
response = '''Sorry, We do not support this Token/Coin at this Time\n\n Enter '/price Coin Symbol' or Shortcode to get started\n E.g, '/price BTC', ETH, NSBT \n\n <a href="https://www.lopeer.com">π° Buy & Sell Crypto with Lopeer P2P.</a>'''
bot.reply_to(message, response, disable_web_page_preview=True)
# this handles messages in private chats with the bot
@bot.message_handler(regexp='')
def price_finder(message):
coin_symbol = message.text.upper()
print(coin_symbol)
if message.chat.type == "private":
try:
crypto_requests = requests.get("https://wavescap.com/api/asset/{}.json".format(coin_symbol))
crypto_data = crypto_requests.json()
coin_price = crypto_data["data"]["lastPrice_usdt"]
first_price = crypto_data["data"]["firstPrice_usdt"]
percent_change_float = (float(coin_price) / float(first_price) - 1) * 100
percent_change = round(percent_change_float,2)
volume_full = crypto_data["24h_vol_usdt"]
volume = round(volume_full,5)
round_coin_price = round(coin_price,5)
coin_name = crypto_data["name"]
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto with Lopeer P2P </a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Free Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer P2P.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
except Exception as e:
cmc_url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
cmc_parameters = {
'symbol': coin_symbol,
}
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': CMC_API_KEY,
}
session = Session()
session.headers.update(headers)
try:
response = session.get(cmc_url, params=cmc_parameters)
data = json.loads(response.text)
price = data['data'][coin_symbol]['quote']['USD']['price']
volume = data['data'][coin_symbol]['quote']['USD']['volume_24h']
percent_change = data['data'][coin_symbol]['quote']['USD']['percent_change_24h']
round_coin_price = round(price,18)
coin_name = data['data'][coin_symbol]['name']
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto on Lopeer </a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Free Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
# Start of Custom Waves Asset Check
except Exception as e:
print(e)
print("At fore part")
if coin_symbol == "ROE":
coin_symbol = "A4h9aifPtz371noBA1Khi2Eb4L3Vzf8LC8PtF4QysEd9"
print(coin_symbol)
ticker = 'ROE'
coin_name = "FROE"
cmc_url = 'https://api.wavesplatform.com/v0/pairs/{}/DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p'.format(coin_symbol)
headers = {
'accepts': 'application/json',
}
session = Session()
session.headers.update(headers)
try:
response = session.get(cmc_url)
data = json.loads(response.text)
# print(data)
price = data['data']["lastPrice"]
volume = data['data']["quoteVolume"]
round_coin_price = round(price,5)
response1 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Trade Crypto on Lopeer </a>'.format(coin_symbol,coin_name,round_coin_price,volume,percent_change)
response2 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Earn Crypto with Lopeer Affiliate Program</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response3 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer.</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response4 = '<b>{} - {}</b> \n Price: ${} USD \n 24h volume: ${} USD \n 24h change: {}% \n \n <a href="https://onelink.to/e6jquz">π° Enjoy Crypto savings with daily interest on Lopeer</a>'.format(coin_symbol,coin_name,round_coin_price,volume, percent_change)
response = random.choice([response4, response3, response1])
bot.reply_to(message, response, disable_web_page_preview=True)
except (Exception, KeyError) as e:
print(e)
response = '''Sorry, We do not support this Token/Coin at this Time\n\n Enter '/price Coin Symbol' or Shortcode to get started\n E.g, '/price BTC', ETH, NSBT \n\n <a href="https://onelink.to/e6jquz/">π° Buy & Sell Crypto with Lopeer P2P.</a>'''
bot.reply_to(message, response, disable_web_page_preview=True)
except (Exception, KeyError) as e:
print(e)
response = '''Sorry, We do not support this Token/Coin at this Time\n\n Enter '/price Coin Symbol' or Shortcode to get started\n E.g, '/price BTC', ETH, NSBT \n\n <a href="https://www.lopeer.com">π° Start P2P Crypto Trading with Lopeer</a>'''
bot.reply_to(message, response, disable_web_page_preview=True)
# @bot.message_handler(regexp='')
# def send_answer(m):
# user_msg = 'Hi, it seems you have entered an invalid comman, kindly "/p" with a Crypto Asset to get the price. \n\n Example "/p BTC"'
# bot.reply_to(m, user_msg)
# Upon calling this function, TeleBot starts polling the Telegram servers for new messages.
# - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers
# - interval: True/False (default False) - The interval between polling requests
# Note: Editing this parameter harms the bot's response time
# - timeout: integer (default 20) - Timeout in seconds for long polling.
bot.polling(none_stop=True)