-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
69 lines (45 loc) · 1.48 KB
/
api.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
import requests
import json
from telegram.ext import Updater, InlineQueryHandler, CommandHandler
from telegram.ext.dispatcher import run_async
import time
import re
def stockPrice(firm):
#using the AlphaVantage API
parameters = {
'function': 'TIME_SERIES_INTRADAY',
'symbol': firm,
'interval': '5min',
'apikey': 'YOUR TOKEN HERE',
}
response = requests.get('https://www.alphavantage.co/query?', params=parameters)
stakes = response.json()["Time Series (5min)"]
lst = []
for key in stakes.keys():
lst.append(stakes[key]["1. open"])
if(lst[0]>lst[1]):
return True
def jprint(obj):
# create a formatted string of the Python JSON object
text = json.dumps(obj, sort_keys=True, indent=4)
print(text)
@run_async
def bop(update, context):
while (True):
if(stockPrice('^GDAXI')):
chat_id = update.message.chat_id
context.bot.sendMessage(chat_id=chat_id, text='DER DAX IST GESTIEGEN HURRA')
time.sleep(300)
else :
chat_id = update.message.chat_id
context.bot.sendMessage(chat_id=chat_id, text='DER DAX IST GESUNKEN')
time.sleep(300)
def main():
updater = Updater('Your Telegram Bot Token Here', use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('stock', bop))
#dp.add_handler(MessageHandler(Filters.all, callback_method))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()