-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht_bot.py
43 lines (33 loc) · 1.33 KB
/
t_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
import telebot
from download import download
from find_interval import interval
import os
with open("BOT_KEY.txt", "r") as f:
BOT_KEY = f.read()
with open("telegram_chat_id.txt", "r") as f:
chatID = f.read()
bot = telebot.TeleBot(BOT_KEY)
@bot.message_handler(commands=['ping'])
def pong(message):
bot.send_message(message.chat.id, "pong")
@bot.message_handler(commands=['interval'])
def get_interval(message):
params = message.text.split("/interval ")[1].split(" -")
ticker = params[0].upper()
period = 1
timeframe = "D"
for p in params:
if p.startswith("tf "):
timeframe = p.split("tf ")[1]
elif p.startswith("p "):
period = int(p.split("p ")[1])
try:
download(ticker,period)
confidence_interval,expected_value = interval(f"data/{ticker}.M1.out",timeframe)
bot.send_message(message.chat.id,f"Expected price: {round(expected_value,5)}\n1% confidence interval: [{round(confidence_interval[1],5)}, {round(confidence_interval[2],5)}]\n0.1% confidence interval: [{round(confidence_interval[0],5)}, {round(confidence_interval[3],5)}]")
while not os.path.exists(f"data/{ticker}.M1.out"):
print("not found")
except Exception as e:
bot.send_message(message.chat.id, f"Error: {e}")
print("Start")
bot.infinity_polling()