- Introduction
- Available Commands
- How to Use
- How to Set Up the Bot
- Warning Price
- Database
- Open VScode tunnel
- Summarize Sound
- Summarize News
- LLM with RAG system
- Example Uses
- To-Do List
Welcome to the Mrzaizai2k Stock Assistant bot! This bot is designed to assist you with various stock-related tasks and analyses. Whether you want to calculate the payback time for a stock, find support and resistance levels, or receive warnings about specific market conditions, this bot has you covered.
Available commands
/start
: Initializes the bot and provides a welcome message./help
: Displays a list of available commands and their descriptions./pbt
: Calculates the payback time for a specific stock./snr
: Finds the closest support and resistance levels for a stock./findpbt
: Identifies stocks with favorable payback times./findmyfav
: Recommends stocks based on specified criteria./risk
: Calculates the number of stocks you can buy with a given loss/trade percentage and maximum loss/capital percentage./rate
: Provides a general rating for a stock./mulpattern
: Finds patterns of a stock on multiple dimensions (close, volume)./pattern
: Finds patterns of a stock based on closing prices./findbestmotif
: Identifies the best motifs across all stocks./buysellanalyze
: Picture of my Buy/Sell of a stock (FPTS data)/winlossanalyze
: Analyze my Win/Loss trading for the last 6 months (FPTS data)/watchlist
: See/change your watch list/summarynewsurl
: Summary news from arbitrary url
Only me commands
/remote
: Open remote tunnel to vscode on my latop./log
: Send the log file./scrape
: Manually scraping trading data and news/masterquest
: Answer the question with my master data in HCMUT (LLM + RAG system)/updatevectordb
: Update vector database for masterquest command
- Start a command with a forward slash ("/") followed by the desired command.
- Example:
/pbt
- Example:
- Follow the bot's prompts to enter additional information, such as stock symbols or dates.
- Wait for the bot to process your request. Some commands may take several minutes.
- Review the bot's responses for the calculated results, warnings, or recommended stocks.
Before running the Mrzaizai2k Stock Assistant Bot, follow these steps to set up the environment:
-
Clone the Repository:
- Close the Git repository to your local machine:
git clone [repository_url]
- Close the Git repository to your local machine:
-
Install Dependencies:
- Install selenium for linux: https://cloudbytes.dev/snippets/run-selenium-and-chrome-on-wsl2
- Navigate to the project directory and install the required packages using the provided
setup_win.txt
file:pip install -r setup_win.txt
-
Get TELEBOT_API Key:
- Go to BotFather on Telegram and create a new bot.
- Copy the generated
TELEBOT_API
key.
-
Create .env File:
- Create a new file named
.env
in the project root directory. - Add the following line to the file, replacing
YOUR_TELEBOT_API_KEY
with the key obtained from BotFather:TELEBOT_API=YOUR_TELEBOT_API_KEY TRADE_USER=YOUR_TRADING_USER TRADE_PASS=YOUR TRADING PASSWORD
- Create a new file named
-
Update Config:
- You have to update the config in
config/config.yaml
file. i.e time to warning, data path,... .txt
file to save long text like the/start
or/help
commands
- You have to update the config in
-
Run the Bot:
-
Execute the following command to run the Mrzaizai2k Stock Assistant Bot:
python src/stock_bot.py
-
Or you can run with Makefile on Linux:
make bot
-
-
Interact with the Bot:
- Once the bot is running, open Telegram and start interacting with the bot using the available commands.
The bot can also warning you about the stock in watchlist in times that you have set in config/config.yaml
. The time would be in format HH:MM
. Note: '06:50' not '6:50'
-
warning_macd
Function:- Purpose: This function generates warnings based on MACD (Moving Average Convergence Divergence) analysis for stocks in the provided watchlist.
- Warnings: Detects if a stock has crossed up or down based on MACD with a specified offset.
-
warningbigday
Function:- Purpose: Generates warnings for stocks with significant price movements (big days).
- Warnings: Identifies powerful increases or decreases in stock prices.
-
warningpricevsma
Function:- Purpose: Provides warnings based on the relationship between stock prices and Moving Averages (MA).
- Warnings: Detects if a stock has crossed up or down in relation to its Moving Average with a specified offset.
-
warningsnr
Function:- Purpose: Warns about stocks approaching or meeting support/resistance levels.
- Warnings: Identifies if a stock is meeting support or resistance levels within a specified tolerance percentage.
-
User database:
The chatbot utilizes a user database stored in
./memory
. When a new user executes the/watchlist
command, the chatbot automatically checks if the user is in the database. The database contains the following information:- user_id: Unique identifier for users.
- watch_list: List of stocks associated with each user.
- step: User's progress step in the chatbot's functionality.
This user database is a crucial component, enabling seamless interactions and personalized experiences for users. The database is actively used in various functions throughout the bot.
-
Scrape data trading:
The chatbot employs Selenium to scrape trading data from FTPS. The scraped data provides insights into buy/sell periods and facilitates analysis of win/loss trading patterns. The code for this functionality is available in src/trading_record.py. This feature enhances the chatbot's capability to provide valuable trading analytics. The code can be found in
src/trading_record.py
-
Scrape news:
The bot has the capability to scrape news specifically related to the stocks on your watchlist. Additionally, it can provide a brief summary of the top news, offering insights into the market before the trading session begins.
I have enhanced the crawling functionality using LangChain, allowing the bot to precisely extract news text from any given URL. This improvement ensures accurate and relevant information retrieval.
To quickly obtain a summary from a URL, you can utilize the /summarynewsurl command. This feature enhances user convenience and efficiency.
Currently, the news data is stored in a json file. However, I am planning to implement an update to MongoDB in the future. This transition aims to improve data management and accessibility.
As to this link, you need to first set up the tunnel in your code
curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz
tar -xf vscode_cli.tar.gz
Then use this command in CLI
./code tunnel
Or in the src/stock_bot.py
result = subprocess.run(command, check=True, text=True)
Whenever you want to run your bot remotely, but got this issue: "make sure that only one bot instance is running". Please kill bot first
make kill
make bot
The bot is in development to summarize all sounds from audio or voice
.It can recognize sounds with various formats such as .mp3, .wav,.ogg,.m4a
with Whisper
To setup Whisper
pip install git+https://github.com/openai/whisper.git
# on Ubuntu or Debian
sudo apt update && sudo apt install ffmpeg
Then I use Google Translate API to translate the text to English. All the code can be found src/summarize_text.py
The bot can also transform your text into to-do list using model TheBloke/Llama-2-7B-Chat-GGML
Input: "I want to go shoppng at 8 o'clock and call my parents tomorrow"
Output: ["Go shopping at 8 o'clock", "Call my parents tomorrow"]
It has the capability to understand and fix tasks, such as when you mention a task incorrectly and want to correct it. For example:
Input: "I want to go shopping at 8 o'clock, uhm, I'm sorry, at 9 o'clock."
Output: ["Go shopping at 9 o'clock."]
Update: I have updated the model to chatgpt turbo 3.5 Instruct to get better result in no time!
Personally, I use the Microsoft To Do app, so the bot will sync those tasks to my app! The information can be found in tod0.
The tod0
package is originally designed for CLI usage. However, I have modified it for my personal usage in Python. The source code can be found in src/Microsofttodo.py
. Remeber to take the token and client_id as this link
The bot has the capability to summarize news related to your watchlist stocks and the market. I utilize a lightweight Falconsai/text_summarization model and Langchain for summarization, enabling me to obtain a precise and swift summary from the news.
I leveraged Langchain and the beautifulsoup
package to crawl top news and news related to your stocks from two sites: Cafef and VnExpress, bringing you the summary of the market trend.
If you prefer a more direct approach, simply use the command /summarynewsurl
and paste the URL link. This will provide you with a summary of any site you desire.
The system can anwser the questions based on my doccuments (for my master courses). It will ask the port 8083 and get the response. Refer to my LLM with RAG repo for more information
Explore practical implementations and demonstrations of the chatbot's functions in the notebook
folder. These examples showcase real-world scenarios, illustrating how the chatbot can be effectively utilized for stock market monitoring.
- Update some features with langchain
- Upgrade the security
- Stock Prediction with TFT Model
- Update DataBase using PostGreSQL and MongoDB
- User_ID Encryption
- Back Testing Bot
- Make a youtube video about this bot
- Update to do list function
Note: Ensure that you have Python installed on your machine and the necessary permissions to install packages and run scripts.
Feel free to explore the various commands and leverage the bot for your stock-related analyses. If you have any questions or encounter issues, type /help
for assistance. Happy investing!