-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
152 lines (136 loc) · 5.36 KB
/
main.py
File metadata and controls
152 lines (136 loc) · 5.36 KB
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
from datetime import datetime
import os
import sys
import time
from discord import Webhook, RequestsWebhookAdapter
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ParseMode
import urllib
from pexpect import TIMEOUT
import telegram
from web3 import Web3
from emojis import getEmoji
from polygonGET import (
checkAddress,
comparePositions,
getName,
getPositions,
getSymbol,
initConnection,
lastPositions,
updateFile,
)
from dotenv import load_dotenv
load_dotenv()
ADDRESSES = [
"0x25ad32265c9354c29e145c902ae876f6b69806f2", # Alpha Portfolio
"0x71b41b3b19aac53ca4063aec2d17fc3caeb38026", # Macro Trend BTC
"0x72Ca52512b93E8D67309aF0C14C1A225bcbd3548", # Macro Trend ETH
"0xabcc2102065ba01c6df1a5a5a57158f452403b70", # Quantum Momentum BTC
"0x9984d846a3dc77aa0488f3758976b149e8475995", # Quantum Momentum ETH
"0x20ab4cb8f8da39582bc92da954ab1bb128f4e244", # Quantum Momentum MATIC
"0x58f7C5707Ba8E09B5e61ceBe8821f65434372344", # Buy the Dip BTC
"0x07A79127182a1c303d11eCDa951310EC1C2E1444", # Buy the Dip ETH
"0xb87352B4C3EB9daEd09cD4996dFf85c122394912", # Buy the Dip MATIC
# "0xf2aa5ccea80c246a71e97b418173fcc956408d3f", # Discretionary BTC
# "0x72b467cacbdbec5918d8eec0371ca33e6fd42421", # Discretionary ETH
# "0xab80a6e2909c8089ebd84f331c05bbefa3276cd2", # Discretionary MATIC
# "0x62135f85899d97aed95f4405d710208e68b99f39", # DeFi Value Index
# "0xB4f78a05ab16CD3e6d0100112D0CC431942859Bb", # BTC Momentum Index
# "0xd3ef811331a98d24a2B2FB64cEBeEa5aF31b2568", # ETH Momentum Index
# "0xDFdDd9811796F72bA32a031724f5B1403CD48B91", # MATIC Momentum Index
# "0xB5253C58b8a361d9901922b23eC9fB9E7d38C98a", # DPI Momentum Index
# "0xad2b726fd2bd3a7f8f4b3929152438eba637ef19", # SWD Momentum Index
# "0x55a40b33CFf2eb062e7aa76506B7De711F2B2aff", # Polygon Ecosystem In dex
] # contract addresS
PIPE = os.getenv("TSN_PIPE")
TELEGRAM_BOT_TOKEN = os.getenv("TSN_TELEGRAM_BOT_TOKEN")
TELEGRAM_CHAT_ID = os.getenv("TSN_TELEGRAM_CHAT_ID")
DISCORD_WEBHOOK_URL = os.getenv("TSN_DISCORD_WEBHOOK_URL")
TIMEOUT = int(os.getenv("TSN_TIMEOUT"))
def prepareMessage(w3, obj, address):
title = getName(w3, address).replace("INDEX", "Index")
telegram = f"<b>⚠️{title} Rebalance Alert⚠️</b>\n\n"
sSymbol = getSymbol(w3, address)
emoji = getEmoji(sSymbol)
discord = f"{emoji} **{title} Rebalance Alert** {emoji}\n\n"
for i in obj:
if len(obj[i]) != 0:
for x in range(len(i)):
try:
t = ""
t2 = ""
if i == "in":
t2 = " is in 📈\n\n"
elif i == "out":
t2 = " is out 📉\n\n"
elif i == "pout":
t = "Partial "
t2 = " is out 📉\n\n"
elif i == "pin":
t = "More "
t2 = " is in 📈\n\n"
else:
continue
symbol = getSymbol(w3, obj[i][x])
telegram += f"{t}${symbol}{t2}"
discord += f"{t}${symbol}{t2}"
except IndexError:
pass
symbol = getSymbol(w3, address)
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
f"👉 Buy ${symbol} on Polygon 👈",
url=f"http://app.swdao.org/product/{symbol}",
)
]
]
)
discord += f"👇Buy ${symbol} on Polygon👇\n\nhttp://app.swdao.org/product/{symbol}"
return telegram, discord, reply_markup
def telegramNotification(message, reply_markup):
bot = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
now = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
try:
bot.sendMessage(
chat_id=TELEGRAM_CHAT_ID,
text=message,
disable_web_page_preview=True,
reply_markup=reply_markup,
parse_mode=ParseMode.HTML,
)
print(f"\n{now} - Message send to Telegram:")
except Exception as inst:
print(f"ERROR with Telegram {now}: {inst}")
def discordNotification(message):
dc = Webhook.from_url(DISCORD_WEBHOOK_URL, adapter=RequestsWebhookAdapter())
dc.send(message)
now = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
print(f"{now} - Message send to Dicord")
def mainLoop():
for address in ADDRESSES:
w3 = initConnection(PIPE)
if checkAddress(w3, address):
continue
address = Web3.toChecksumAddress(address)
positions = getPositions(w3, address)
lastPos = lastPositions(positions, address)
obj = comparePositions(lastPos, positions)
if obj == None:
now = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
sys.stdout.write(
f"\r{now} -- TIMEOUT {TIMEOUT} SEC: No updates with {address} "
)
sys.stdout.flush()
time.sleep(TIMEOUT)
continue
telegramMsg, discordMsg, reply_markup = prepareMessage(w3, obj, address)
updateFile(positions, address)
telegramNotification(message=telegramMsg, reply_markup=reply_markup)
discordNotification(discordMsg)
def main():
while True:
mainLoop()
if __name__ == "__main__":
main()