{"id":19544432,"url":"https://github.com/nighty3098/investingassistant","last_synced_at":"2025-10-08T18:27:55.660Z","repository":{"id":259179638,"uuid":"875641274","full_name":"Nighty3098/InvestingAssistant","owner":"Nighty3098","description":"📊 Telegram is an investment assistant bot with neural network and other functions","archived":false,"fork":false,"pushed_at":"2025-07-01T07:02:44.000Z","size":21784,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-01T08:23:46.691Z","etag":null,"topics":["ai","investing","investing-analysis","investing-com","neural-network","pyrogram","pyrogram-bot","telegram","telegram-bot","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nighty3098.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-20T14:16:49.000Z","updated_at":"2025-07-01T07:02:48.000Z","dependencies_parsed_at":"2024-11-10T14:19:52.070Z","dependency_job_id":"cdb07aa0-cdf4-42bb-b649-a762b9ac7e17","html_url":"https://github.com/Nighty3098/InvestingAssistant","commit_stats":null,"previous_names":["nighty3098/investingassistant"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Nighty3098/InvestingAssistant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nighty3098%2FInvestingAssistant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nighty3098%2FInvestingAssistant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nighty3098%2FInvestingAssistant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nighty3098%2FInvestingAssistant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nighty3098","download_url":"https://codeload.github.com/Nighty3098/InvestingAssistant/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nighty3098%2FInvestingAssistant/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266263057,"owners_count":23901353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","investing","investing-analysis","investing-com","neural-network","pyrogram","pyrogram-bot","telegram","telegram-bot","tensorflow"],"created_at":"2024-11-11T03:28:48.295Z","updated_at":"2025-10-08T18:27:50.616Z","avatar_url":"https://github.com/Nighty3098.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cbr\u003e\n    \u003cimg src=\"header.png\" /\u003e\n    \u003cbr\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/Nighty3098/InvestingAssistant/stargazers\"\u003e\n    \u003cbr\u003e\u003cbr\u003e\n    \u003ca href=\"https://discord.gg/6xEc5WFK\"\u003e\u003cimg src=\"https://img.shields.io/discord/1238858182403559505.svg?label=Discord\u0026logo=Discord\u0026style=for-the-badge\u0026color=f5a7a0\u0026logoColor=FFFFFF\u0026labelColor=1c1c29\"\u003e\u003c/img\u003e\u003c/a\u003e\n    \u003cbr\u003e\u003cbr\u003e\n    \u003cimg class=\"badge\" src=\"https://img.shields.io/github/issues/Nighty3098/InvestingAssistant?style=for-the-badge\u0026color=dbb6ed\u0026logoColor=ffffff\u0026labelColor=1c1c29\"  style=\"border-radius: 5px;\"/\u003e\n    \u003cimg class=\"badge\" src=\"https://img.shields.io/github/stars/Nighty3098/InvestingAssistant?style=for-the-badge\u0026color=eed49f\u0026logoColor=D9E0EE\u0026labelColor=1c1c29\" style=\"border-radius: 5px;\"/\u003e\n    \u003cimg src=\"https://img.shields.io/github/commit-activity/t/Nighty3098/InvestingAssistant?style=for-the-badge\u0026color=a6e0b8\u0026logoColor=D9E0EE\u0026labelColor=171b22\" style=\"border-radius: 5px;\"/\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\u003cbr\u003e\u003cbr\u003e\n\n# StockBot Documentation 📈\n\n**Version 1.0** | **Last Updated: May 06, 2025**\n\n---\n\n\u003e [!IMPORTANT]\n\u003e ONLY FOR PYTHON 3.12\n\n## 📖 Overview\n\nStockBot is a Telegram bot designed to provide users with stock market insights, including price predictions, news parsing, and fundamental analysis. Built using the **Pyrogram** library, the bot integrates with a deep learning model for stock price forecasting, a news parser for real-time market updates, and a database for user and stock management. The bot supports user authentication, stock tracking, and admin controls, with a token-based system for accessing premium features.\n\nThe project leverages **TensorFlow** for stock price predictions, **yfinance** for financial data, and **BeautifulSoup** for web scraping. It includes asynchronous news parsing, real-time notifications, and report generation in Excel format.\n\n---\n\n## 🚀 Features\n\n- **User Management**: Register, manage, and delete user accounts with admin controls for banning/unbanning and role assignment.\n- **Stock Tracking**: Add/remove stocks to a user's watchlist and retrieve detailed stock information.\n- **Price Prediction**: Forecast stock prices for the next 60 days using a pre-trained deep learning model.\n- **News Parsing**: Fetch and filter news from Investing.com, notifying users of articles relevant to their tracked stocks.\n- **Fundamental Analysis**: Provide buy/sell recommendations based on financial metrics like P/E ratio, ROE, and risk factors.\n- **Report Generation**: Generate Excel reports with stock data for user analysis.\n- **Token System**: Limit access to premium features (e.g., price predictions) using a token-based system.\n- **Admin Panel**: Manage users, assign admin roles, send tokens, and monitor system activity.\n- **Multilingual Support**: Planned language selection (currently in development).\n- **Asynchronous Processing**: Handle news parsing and notifications concurrently using asyncio.\n\n---\n\n## 🛠️ Requirements\n\nTo run StockBot, ensure the following dependencies are installed:\n\nInstall dependencies:\n\n```bash\npip install -r req.txt\n```\n\nAdditionally, you need:\n- A Telegram Bot Token (obtained via [BotFather](https://t.me/BotFather)).\n- API ID and API Hash from [my.telegram.org](https://my.telegram.org).\n- A pre-trained stock prediction model (`best_model.keras`) and scaler (`stock_scaler.save`).\n\n---\n\n## 📂 Project Structure\n\n```\ngit clone https://github.com/Nighty3098/InvestingAssistant --recurse-submodules\ncd InvestingAssistant\npoetry shell\npoetry install\ncd src\n```\n\n---\n\n## ⚙️ Configuration\n\n1. **Environment Variables**:\n   Create a `config.py` file with the following:\n\n   ```python\n   API_ID = \"your_api_id\"  # From my.telegram.org\n   API_HASH = \"your_api_hash\"  # From my.telegram.org\n   BOT_TOKEN = \"your_bot_token\"  # From BotFather\n   app = Client(\"StockBot\", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)\n   data_file = \"data.db\"  # SQLite database file\n   log_file = \"bot.log\"  # Log file\n   logger = ...  # Configure logging (see main.py)\n   ```\n\n2. **Database**:\n   The bot uses SQLite (`data.db`) to store user data, stocks, and tokens. The `db.py` module handles table creation and queries.\n\n3. **Model Files**:\n   Ensure `best_model.keras` and `stock_scaler.save` are in `IPSA_MODEL/price/`. These are required for price predictions.\n\n---\n\n## 🏃‍♂️ Running the Bot\n\n1. **Start the Bot**:\n   Run the main script:\n\n   ```bash\n   python main.py\n   ```\n\n2. **Interact with the Bot**:\n   - Open Telegram and start a chat with your bot.\n   - Use the `/start` command to initialize the bot.\n   - If unregistered, you'll be prompted to register.\n   - Registered users see the main menu; admins see the admin panel.\n\n3. **Outputs**:\n   - `client_data/`: Stores generated reports (`*.xlsx`) and forecast plots (`*.png`).\n   - `logs/`: Contains bot logs (`bot.log`).\n   - `data.db`: SQLite database with user and stock data.\n\n---\n\n## 📱 Bot Commands and Features\n\n### Commands\n\n| Command         | Description                          | Access       |\n|-----------------|--------------------------------------|--------------|\n| `/start`        | Initialize the bot and show menu     | All users    |\n| `/send_tokens`  | Send tokens to a user                | Admins only  |\n\n### Callback Queries\n\nThe bot uses inline keyboards for navigation. Key actions include:\n\n- **User Actions**:\n  - `register_user`: Register a new user.\n  - `my_stocks`: View tracked stocks.\n  - `add_stocks`/`remove_stocks`: Manage stock watchlist.\n  - `get_price`: Request a stock price prediction (requires tokens).\n  - `news`: Fetch news for a specified period (admin-only or in development).\n  - `settings`: Access settings (e.g., set city, language).\n  - `remove_account`: Delete user account.\n  - `to_main`: Return to the main menu.\n\n- **Admin Actions**:\n  - `admin_panel`: Access the admin panel.\n  - `users_menu`: List all users with details (ID, tokens, role, status).\n  - `add_admin`/`rm_admin`: Add/remove admin role for a user.\n  - `ban_user`/`unblock_user`: Ban/unban a user.\n\n### State Management\n\nThe bot uses a `user_states` dictionary to track user input states (e.g., `adding`, `removing`, `price`, `news`). This ensures proper handling of text inputs based on the current context.\n\n---\n\n## 🧠 Core Components\n\n### 1. StockPredictor (`price_core.py`)\n\n- **Purpose**: Predicts stock prices for the next 60 days using a pre-trained TensorFlow model.\n- **Key Methods**:\n  - `predict_future(ticker)`: Generates 60-day price forecasts.\n  - `analyze(ticker, threshold=0.05)`: Provides a forecast summary with expected price change.\n  - `predict_plt(ticker, user_id)`: Creates a plot of historical and forecasted prices.\n- **Dependencies**: TensorFlow, yfinance, Matplotlib, joblib.\n- **Output**: Forecast message, price change percentage, and a plot (`client_data/forecast_{user_id}_{ticker}.png`).\n\n### 2. NewsParser (`parsing.py`)\n\n- **Purpose**: Scrapes news from Investing.com and filters articles relevant to user-tracked stocks.\n- **Key Methods**:\n  - `is_stocks_in_news(url, user_id, ...)`: Checks if tracked stocks are mentioned in an article.\n  - `get_news_text(url)`: Extracts article text.\n  - `parse_investing_news(url, period, user_id)`: Parses news articles within a specified period.\n  - `start_parsing(period, user_id)`: Aggregates news from multiple sources.\n  - `check_new_articles(user_id)`: Asynchronously checks for new articles every 2 minutes.\n- **Dependencies**: BeautifulSoup, requests, user-agent.\n- **Output**: Formatted news messages with title, summary, URL, and price influence prediction.\n\n### 3. AdvicePredictor (`create_report.py`)\n\n- **Purpose**: Provides buy/sell recommendations based on fundamental analysis.\n- **Key Methods**:\n  - `analyze_fundamentals(ticker)`: Scores stocks based on P/E ratio, ROE, debt-to-equity, revenue growth, beta, and risk metrics.\n  - `analyze(ticker, forecast_growth)`: Generates a recommendation with risk assessment.\n- **Dependencies**: yfinance, pandas.\n- **Output**: Recommendation message (e.g., \"STRONG BUY\", \"SELL\") with risk details.\n\n### 4. ReportTable (`create_report.py`)\n\n- **Purpose**: Generates Excel reports with stock data.\n- **Key Methods**:\n  - `download_data(ticker)`: Fetches stock data via yfinance.\n  - `save_report(data)`: Saves data to an Excel file.\n- **Dependencies**: pandas, yfinance.\n- **Output**: Excel file (`client_data/{ticker}_report.xlsx`).\n\n### 5. Database (`db.py`)\n\n- **Purpose**: Manages user data, stocks, tokens, and admin roles using SQLite.\n- **Key Functions** (assumed based on usage):\n  - `check_user_account(user_id)`: Checks if a user is registered.\n  - `check_user_ban(username)`: Checks if a user is banned.\n  - `is_admin(user_id)`: Verifies admin status.\n  - `get_users_stocks(user_id)`: Retrieves a user's tracked stocks.\n  - `update_tokens(user_id, amount)`: Updates user tokens.\n  - `add_city_to_db(user_id, city)`: Stores user city for timezone handling.\n- **Output**: SQLite database (`data.db`).\n\n---\n\n## 📈 Usage Example\n\n1. **User Interaction**:\n   - User sends `/start`.\n   - If unregistered, they click \"Register\" (`register_user` callback).\n   - Registered users see the main menu with options like \"My Stocks\", \"Get Price\", \"News\", and \"Settings\".\n   - To add a stock, user selects \"My Stocks\" → \"Add Stocks\", enters a ticker (e.g., \"AAPL\"), and confirms.\n   - To get a price prediction, user selects \"Get Price\", enters a ticker, and receives a forecast plot and report (if tokens are available).\n\n2. **Admin Interaction**:\n   - Admin sends `/start` and sees the admin panel.\n   - They can list users (`users_menu`), ban/unban users (`ban_user`/`unblock_user`), or send tokens (`/send_tokens username tokens`).\n   - Admin can add/remove other admins (`add_admin`/`rm_admin`).\n\n3. **News Notifications**:\n   - Users receive news updates for tracked stocks every 2 minutes (if relevant articles are found).\n   - News includes a title, summary, URL, and predicted price influence.\n\n---\n\n## 🛡️ Security and Limitations\n\n### Security Features\n- **User Authentication**: Checks user registration and ban status before granting access.\n- **Admin Controls**: Restricts sensitive actions (e.g., banning users, sending tokens) to admins.\n- **Token System**: Limits API-heavy features (e.g., price predictions) to prevent abuse.\n- **Logging**: Comprehensive logging for debugging and monitoring (`bot.log`).\n\n### Limitations\n- **API Limits**: yfinance and Investing.com have request limits, which may cause failures during high usage.\n- **News Parsing**: Limited to Investing.com sources and may miss relevant articles from other platforms.\n- **Model Accuracy**: Price predictions depend on the pre-trained model's quality and may not account for sudden market events.\n- **Language Support**: Multilingual support is in development and not fully implemented.\n- **Error Handling**: Some errors (e.g., network failures) may not be gracefully handled for users.\n\n---\n\n## 📝 Notes\n\n- **Model Dependency**: Ensure `best_model.keras` and `stock_scaler.save` are available. Train the model using the provided stock prediction script if needed.\n- **Timezone Handling**: News parsing uses user-specified cities for timezone conversion. Default timezone may cause inaccuracies if not set.\n- **Token Management**: Admins must manually assign tokens using `/send_tokens`. Consider automating token allocation in future updates.\n- **Scalability**: For large user bases, consider optimizing database queries and news parsing with caching or parallel processing.\n- **Extensibility**: Add support for more news sources, technical indicators, or real-time market data feeds.\n\n---\n\n## 📚 References\n\n- Pyrogram Documentation: [https://docs.pyrogram.org/](https://docs.pyrogram.org/)\n- TensorFlow Documentation: [https://www.tensorflow.org/](https://www.tensorflow.org/)\n- yfinance Documentation: [https://github.com/ranaroussi/yfinance](https://github.com/ranaroussi/yfinance)\n- BeautifulSoup Documentation: [https://www.crummy.com/software/BeautifulSoup/](https://www.crummy.com/software/BeautifulSoup/)\n- Investing.com: [https://www.investing.com/](https://www.investing.com/)\n\nFor support, open an issue on the project repository or contact the development team.\n\n---\n\n**🤖 Built with Pyrogram and TensorFlow**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnighty3098%2Finvestingassistant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnighty3098%2Finvestingassistant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnighty3098%2Finvestingassistant/lists"}