Stock Monitoring and Notification Project
The system will be flexible and allow users to specify their own set of rules for price movements and triggers for notifications. This is a useful tool for anyone interested in keeping track of their investments and making informed decisions in the stock market.
Project Introduction
In this project, we will spy A-share market data from Tencent and Sina API. The functions will be able to retrieve both daily and minute-level data, and will allow users to specify the stock code, time range, and frequency of the data.
Program Design
API:Tencent Stock API
For the Tencent functions, we will be using the requests
library to make HTTP requests to the Tencent stock data API. The API will return the stock data in JSON format, which we will then parse and convert into a Pandas dataframe for easier manipulation.
The get_price_day_tx
function will be used to retrieve daily data, while the get_price_min_tx
function will be used to retrieve minute-level data. Users will be able to specify the stock code, end date (optional), number of periods to retrieve, and the frequency of the data (e.g. daily, weekly, monthly).
API:Sina Stock API
For the Sina function, we will be using the pandas_datareader
library to retrieve stock data from the Sina API. The get_price_sina
function will allow users to specify the stock code, start and end dates, and the frequency of the data.
Implementation
The Tencent functions will follow the steps outlined below:
- Define the function and parse the input parameters.
- Make the HTTP request to the Tencent API using the
requests
library. - Parse the JSON response and extract the relevant data.
- Convert the data into a Pandas dataframe.
- Return the dataframe to the user.
The Sina function will follow these steps:
- Define the function and parse the input parameters.
- Use the
pandas_datareader
library to retrieve the stock data from the Sina API. - Return the data to the user.
Demo Code
Use requests
get data from API
Use pandas
transfer data to table
|
|
Monitor the 2500-day moving average and the daily stock situation.
Send a notification email using smtplib
when the judgment conditions are met.
|
|
Set up Github Actions to run the script daily.
|
|