This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
117 lines (96 loc) · 5.19 KB
/
main.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
from time import sleep
import pandas as pd
from get_information import getTop1000, getBinanceSymbols, getCoinbaseSymbols, getCoinbaseCustodySymbols
import datetime
import time
from params import SEND_TELE ,VIEW_NUM, token, chat_id, SEND_TELEGRAM_FAIL_INTERVAL, SEND_INTERVAL
import telegram as telegram
from tabulate import tabulate
from helper_functions import durationToSeconds
pd.set_option('display.float_format', '{:.2g}'.format)
try:
bot = telegram.Bot(token=token)
except Exception as e:
print("Error initializing telegram bot")
print(e)
quit()
def send_message(message):
while True:
try:
bot.send_message(chat_id=chat_id,text=message)
break
except Exception as e:
print("Error:",e)
print("Retrying to send tele message in",SEND_TELEGRAM_FAIL_INTERVAL,"s")
sleep(SEND_TELEGRAM_FAIL_INTERVAL)
def predictCoinbase():
msg1 = ''
in_cbc_not_cb = [symbol for symbol in cbc_symbols if symbol not in coinbase_symbols] # In CB custody but not CB
df_cbc_cb = top_1000.query('Symbol in @in_cbc_not_cb')
filtered = df_cbc_cb[0:VIEW_NUM].drop(columns=['Coin','24h Volume','Mkt Cap'])
msg1 += "We have "+str(len(in_cbc_not_cb))+" symbols in CB Custody but not CB\n\n"
msg1 += tabulate(filtered,tablefmt="pipe", headers="keys", showindex=False) + '\n ---------------------------------------------------------------------------------\n\n'
msg2 = ''
in_binance_not_coinbase = [symbol for symbol in binance_symbols if symbol not in coinbase_symbols]
df_ibncb = top_1000.query('Symbol in @in_binance_not_coinbase') # Finds symbols in binance but not coinbase
filtered = df_ibncb[0:VIEW_NUM].drop(columns=['Coin','24h Volume','Mkt Cap'])
msg2 += "We have "+str(len(in_binance_not_coinbase))+" tokens in binance but NOT IN coinbase\n\n"
msg2 += tabulate(filtered,tablefmt="pipe", headers="keys", showindex=False) + '\n ---------------------------------------------------------------------------------\n\n'
msg3 = ''
top_1000_not_cb = top_1000.query('Symbol not in @coinbase_symbols') # Top 1000 filter against CB symbols
filtered = top_1000_not_cb[0:VIEW_NUM].drop(columns=['Coin','24h Volume','Mkt Cap'])
msg3 += "We have "+str(len(top_1000_not_cb))+" tokens in top 1000 but NOT IN coinbase\n\n"
msg3 += tabulate(filtered,tablefmt="pipe", headers="keys", showindex=False) + '\n ---------------------------------------------------------------------------------\n\n'
if SEND_TELE:
send_message(msg1)
send_message(msg2)
send_message(msg3)
else:
print(msg1,'\n',msg2,'\n',msg3)
return
def predictBinance():
msg = ''
in_coinbase_not_binance = [symbol for symbol in coinbase_symbols if symbol not in binance_symbols]
df_icbnb = top_1000.query('Symbol in @in_coinbase_not_binance').drop(columns=['Coin','24h Volume','Mkt Cap'])
msg += "We have "+str(len(in_coinbase_not_binance))+" tokens in coinbase but NOT IN binance\n(If there are missing values its likely shitcoins that arent top 1k)\n\n"
msg+= tabulate(df_icbnb,tablefmt="pipe", headers="keys", showindex=False) + '\n ---------------------------------------------------------------------------------\n\n'
top_1000_not_binance = top_1000.query('Symbol not in @binance_symbols') # Usage of query to get non-listed symbols
filtered = top_1000_not_binance[0:VIEW_NUM].drop(columns=['Coin','24h Volume','Mkt Cap'])
msg += "We have "+str(len(top_1000_not_binance))+" tokens in top 1000 but NOT IN binance\n\n"
msg += tabulate(filtered,tablefmt="pipe", headers="keys", showindex=False) + '\n ---------------------------------------------------------------------------------\n\n'
if SEND_TELE: send_message(msg)
else: print(msg)
return
def updateAll():
global top_1000
global binance_symbols
global coinbase_symbols
global cbc_symbols
global start_extract
global last_updated
global extract_time
start_extract = time.time()
top_1000 = getTop1000()
binance_symbols = getBinanceSymbols()
coinbase_symbols = getCoinbaseSymbols()
cbc_symbols = getCoinbaseCustodySymbols()
last_updated = time.time()
print("Successfully updated all")
return
top_1000 = binance_symbols = coinbase_symbols = cbc_symbols = last_updated = extract_time = start_extract = 0 # Initialize relevant variables
# Initial send
updateAll()
predictCoinbase()
predictBinance()
SEND_INTERVAL = durationToSeconds(SEND_INTERVAL) # Convert string to seconds for sleep usage
init_dt = datetime.datetime.now() # Used to determine total time program ran
if SEND_TELE:
while True:
print("Extract time:",last_updated-start_extract,'/ Time ran:',datetime.datetime.now()-init_dt)
while time.time() - last_updated < SEND_INTERVAL:
print("Sleeping for:",SEND_INTERVAL-time.time()+last_updated,'seconds')
sleep(SEND_INTERVAL-time.time()+last_updated) # Sleeps for the remainder of 1s
pass # Loop until 1s has passed to getPrices again
updateAll()
predictCoinbase()
predictBinance()