-
Notifications
You must be signed in to change notification settings - Fork 0
/
CryptoAlert.py
161 lines (120 loc) · 3.77 KB
/
CryptoAlert.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
# Import libraries
from telethon.tl.types import (PeerChannel)
from telethon.tl.functions.messages import (GetHistoryRequest)
from telethon import TelegramClient, events, sync
from telethon.errors import SessionPasswordNeededError
import json
#from pickle import GLOBAL
#from xxlimited import new
import requests
import telegram_send
import time
import configparser
import asyncio
import os
os.system('cls||clear')
username = input("Enter your username (@name): ")
api_id = input("Enter your api id: ")
api_hash = input("Enter your api hash: ")
user_input_channel = input("Enter your channel link: ")
with open("wc.jpg", "rb") as wc:
telegram_send.send(images=[wc])
telegram_send.send(messages=["Send desired pair in following format"])
# defining key/request url
ogkey = "https://api.binance.com/api/v3/ticker/price?symbol="
#Change price here
top = 2000
bottom = 1750
print("upper limit is ", top, " down limit is ", bottom)
client = TelegramClient(username, api_id, api_hash)
@client.on(events.NewMessage(chats=user_input_channel))
async def newMessageListener(event):
newMessage = event.message.message
if ('buy' in newMessage):
global top
print("------------------------------")
print("top updated with the value ")
newMessage = newMessage[3:8]
print(newMessage)
newMessage = int(newMessage)
top = newMessage
print("------------------------------")
telegram_send.send(messages=["updated"])
loop()
elif ('sell' in newMessage):
global bottom
print("------------------------------")
print("bottom updated with the value ")
newMessage = newMessage[4:9]
print(newMessage)
newMessage = int(newMessage)
bottom = newMessage
print("------------------------------")
telegram_send.send(messages=[" updated"])
loop()
elif ("Current" in newMessage):
currentprice()
elif ("Config" in newMessage):
settings()
elif ("Coin" in newMessage):
global key
telegram_send.send(messages=["Pair Updated"])
key = ogkey+newMessage[4:12]
print(key)
elif ("ClearAll" in newMessage):
top = 9999999
bottom = -9999999
telegram_send.send(
messages=["All settings got clear! setup again to start the bot"])
elif ("Exit" in newMessage):
sys.exit()
elif ("Ping" in newMessage):
Ping()
else:
loop()
def loop():
data = requests.get(key)
data = data.json()
strprice = json.dumps(f"{data['price']}")
strprice = str(strprice)
strprice = strprice[1:8]
strprice = (float(strprice))
notifyprice = str(strprice)
if strprice>=top:
with open("top.jpg", "rb") as tp:
telegram_send.send(images=[tp])
print("Sending top notification", top)
telegram_send.send(messages=[notifyprice + " - ETH Reached the upper limit"])
elif strprice<=bottom:
with open("bottom.jpg", "rb") as bc:
telegram_send.send(images=[bc])
print("Sending bottom notification",bottom)
telegram_send.send(messages=[notifyprice + " - ETH Reached the down limit"])
time.sleep(10)
os.system('cls||clear')
def currentprice():
data = requests.get(key)
data = data.json()
strprice = json.dumps(f"{data['price']}")
strprice = str(strprice)
strprice = strprice[1:8]
strprice = (float(strprice))
notifyprice = str(strprice)
telegram_send.send(messages=[notifyprice + " is now price"])
loop()
def settings():
global top
global bottom
top = str(top)
bottom = str(bottom)
telegram_send.send(
messages=["top is set to " + top+" bottom is set to " + bottom])
top = int(top)
bottom = int(bottom)
loop()
def Ping():
with open("wc.jpg", "rb") as wc:
telegram_send.send(images=[wc])
loop()
with client:
client.run_until_disconnected()