Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions Mastermind/mastermind.py

This file was deleted.

34 changes: 34 additions & 0 deletions Stock_Trading_News_Alerter/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Stock Trading News Alerter

Description:
A Python-based tool designed to monitor stock prices of any company.
Initially demonstrated with Tesla (TSLA), now adaptable for any stock symbol.
Utilizes APIs from Alpha Vantage and NewsAPI for real-time financial and news data.
Sends SMS alerts for significant stock price changes via the Twilio API.

Features:
Monitors stock prices of user-specified companies.
Compares daily closing prices to identify significant percentage changes.
Fetches relevant news if stock price change exceeds a certain threshold.
Automated SMS updates for stock price changes and related news.

Pre-requisites:
Python installation.
Python modules: requests, twilio.
API keys from Alpha Vantage, NewsAPI, and Twilio.
Twilio account with a virtual number and a verified phone number.

Setup Instructions:
Install required Python modules.
Obtain API keys by signing up for Alpha Vantage, NewsAPI, and Twilio.
Clone the repository.
Input API keys and phone numbers in the script variables.

Usage:
Execute the script.
Input the desired stock symbol and company name when prompted.
Receive SMS alerts for selected stock's significant price changes and news.

Enhancements:
Adaptability to monitor any stock symbol as per user input.
Enhanced user interaction with prompts for stock symbol and company name.
65 changes: 65 additions & 0 deletions Stock_Trading_News_Alerter/stock alerter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import requests
from twilio.rest import Client

# User inputs for stock and company
STOCK_NAME = input("Enter the stock symbol (e.g., TSLA for Tesla): ").upper()
COMPANY_NAME = input("Enter the full company name (e.g., Tesla Inc): ")

# Twilio and API configurations
VIRTUAL_TWILIO_NUMBER = "your virtual twilio number"
VERIFIED_NUMBER = "your own phone number verified with Twilio"
STOCK_API_KEY = "YOUR OWN API KEY FROM ALPHAVANTAGE"
NEWS_API_KEY = "YOUR OWN API KEY FROM NEWSAPI"
TWILIO_SID = "YOUR TWILIO ACCOUNT SID"
TWILIO_AUTH_TOKEN = "YOUR TWILIO AUTH TOKEN"

# API Endpoints
STOCK_ENDPOINT = "https://www.alphavantage.co/query"
NEWS_ENDPOINT = "https://newsapi.org/v2/everything"

# Get yesterday's closing stock price
stock_params = {
"function": "TIME_SERIES_DAILY",
"symbol": STOCK_NAME,
"apikey": STOCK_API_KEY,
}

response = requests.get(STOCK_ENDPOINT, params=stock_params)
data = response.json()["Time Series (Daily)"]
data_list = [value for (key, value) in data.items()]
yesterday_data = data_list[0]
yesterday_closing_price = yesterday_data["4. close"]

# Get the day before yesterday's closing stock price
day_before_yesterday_data = data_list[1]
day_before_yesterday_closing_price = day_before_yesterday_data["4. close"]

# Calculate the difference in price
difference = float(yesterday_closing_price) - float(day_before_yesterday_closing_price)
up_down = "🔺" if difference > 0 else "🔻"

# Calculate the percentage difference
diff_percent = round((difference / float(yesterday_closing_price)) * 100)

# Check for significant change and get news
if abs(diff_percent) > 1:
news_params = {
"apiKey": NEWS_API_KEY,
"qInTitle": COMPANY_NAME,
}

news_response = requests.get(NEWS_ENDPOINT, params=news_params)
articles = news_response.json()["articles"]
three_articles = articles[:3]

# Create a formatted list of the first 3 articles
formatted_articles = [f"{STOCK_NAME}: {up_down}{diff_percent}%\nHeadline: {article['title']}. \nBrief: {article['description']}" for article in three_articles]

# Send each article as a separate message via Twilio
client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)
for article in formatted_articles:
message = client.messages.create(
body=article,
from_=VIRTUAL_TWILIO_NUMBER,
to=VERIFIED_NUMBER
)