Created
December 16, 2024 05:11
-
-
Save Abhayparashar31/85b851150dd09363fdd31ffb62131a3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import yfinance as yf | |
from win10toast import ToastNotifier | |
# Define the stock symbol and the percentage threshold | |
stock_symbol = "AAPL" | |
threshold_percentage = 0.010 # Set the desired threshold percentage | |
toaster = ToastNotifier() | |
initial_data = yf.download(stock_symbol, period="1d") | |
initial_price = initial_data["Close"].iloc[0] | |
while True: | |
try: | |
# Get the current stock price | |
current_data = yf.download(stock_symbol, period="1d") | |
current_price = current_data["Close"].iloc[-1] | |
# Calculate the price difference percentage | |
price_diff_percentage = ((current_price - initial_price) / initial_price) * 100 | |
# Compare the price difference with the threshold percentage | |
if price_diff_percentage <= -threshold_percentage: | |
message = f"Stock price for {stock_symbol} has decreased by {price_diff_percentage:.2f}%; Current Price is: {current_price}" | |
toaster.show_toast("Stock Alert", message, duration=10) | |
# Wait for 5 minutes before checking the price again | |
time.sleep(300) | |
except Exception as e: | |
print("An error occurred:", str(e)) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment