-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpriceAlarm.py
40 lines (33 loc) · 1.89 KB
/
priceAlarm.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
import os
import time
import yfinance as yf
from winotify import Notification, audio
tickers = ["AAPL", "TSLA", "AMD", "TQQQ"]
upper_limits = [200, 260, 180, 55]
lower_limits = [190, 200, 100, 30]
while True:
last_prices = [yf.Ticker(ticker).history(period="1d")["Close"].iloc[-1] for ticker in tickers]
print(last_prices)
time.sleep(2) #change interval for longer delays
for i in range(len(tickers)):
# If stock price hit upper limit
if last_prices[i] > upper_limits[i]:
toast = Notification(app_id="Stock Alarm Bot",
title ="Price Alert for " + tickers[i],
msg=f"{tickers[i]} has reached a price of {last_prices[i]:.2f}. You might want to sell.",
icon=os.path.join(os.getcwd(),"sell.png"),
duration="long")
toast.add_actions(label="Go to IBKR", launch ="https://www.interactivebrokers.ca/en/home.php") #Change the broker according to your preference
toast.set_audio(audio.LoopingAlarm6, loop=False)
toast.show()
# If stock price hit lower limit
elif last_prices[i] < lower_limits[i]:
toast = Notification(app_id="Stock Alarm Bot",
title ="Price Alert for " + tickers[i],
msg=f"{tickers[i]} has reached a price of {last_prices[i]:.2f}. You might want to buy.",
icon=os.path.join(os.getcwd(),"buy.png"),
duration="long")
toast.add_actions(label="Go to IBKR", launch ="https://www.interactivebrokers.ca/en/home.php")
toast.set_audio(audio.LoopingAlarm8, loop=False)
toast.show()
time.sleep(1) #To enable 2 notification to display at the same time