This project is a highly personalized, AI-powered Telegram trading companion bot. Nicknamed "The Bankruptcy Booster," it's designed to assist users in monitoring financial markets, analyzing their portfolio, and managing risk, all delivered in the tone of a trading floor buddy with a dark sense of humor.
-
AI Trading Companion:
- Powered by the Google Gemini AI, its distinct and strong personality is shaped by the
system_promptwithinconfig.py. - Features a built-in "trash talk" system with humorous and cynical responses that change based on market conditions, making interactions more engaging.
- Powered by the Google Gemini AI, its distinct and strong personality is shaped by the
-
Modular Analysis Engines:
engine_market.py: Handles market data analysis, fetching real-time quotes and news.engine_portfolio.py: Manages and calculates the real-time Profit and Loss (PnL) of the investment portfolio.engine_risk.py: Monitors global macroeconomic indicators and systemic market risks.
-
Brokerage Integration:
- Integrates with Fubon Securities via the
fubon.pymodule to fetch real-time portfolio data from the user's account.
- Integrates with Fubon Securities via the
-
Telegram Interface:
- Built with the
telebotframework, allowing for easy and convenient interaction on Telegram. - Includes a
/resetcommand to clear the AI's conversation history and start fresh.
- Built with the
-
Strict Safety Protocols:
- Implements a "Double-Check Protocol" that requires secondary user confirmation for all buy, sell, or position modification commands to prevent costly errors.
- Enforces a strict "Portfolio Reporting Format" to ensure clear, consistent, and accurate PnL reports every time.
-
Intelligent Model Management:
- Dynamically switches to the most suitable Gemini AI model based on the current market status (e.g., US or Taiwan market open hours).
- Includes an API failover mechanism that automatically switches to a backup model if a service becomes unstable, ensuring high availability.
-
Clone the Project:
git clone https://github.com/your-username/MarginCall_2X.git cd MarginCall_2X -
Create and Activate a Virtual Environment:
python -m venv venv source venv/bin/activate # For Windows: venv\Scripts\activate
-
Install Dependencies: Install the pinned runtime dependencies from
requirements.txt:pip install -r requirements.txt
-
Set Up Environment Variables: Copy the
.env.un~file to.envand fill in your personal credentials:cp .env.un~ .env
Then, edit the
.envfile with your information:TELEGRAM_BOT_TOKEN="Your_Telegram_Bot_Token" GEMINI_API_KEY="Your_Gemini_API_Key" # ...and any credentials required for the Fubon Securities API.
Once everything is set up, run the main script to start the bot:
python main.pyYou can then start chatting with your "Bankruptcy Booster" on Telegram.
The current shared runtime is organized under src/:
src/llm.py: shared Gemini client, shared cooldown table,quick_call()andchat_with_tools()src/database.py: shared SQLite lock plus WAL-enabled connection helperssrc/symbols.py: shared ticker normalizationsrc/tools.py: tool logging wrapper plus grouped tool registration
Useful commands:
# Run the focused unit tests
python -m unittest test_brain_memory.py test_refactor_runtime.py
# Start the Telegram bot
python main.pyThis project is for technical demonstration and proof-of-concept purposes only and does not constitute professional investment advice. All AI responses and data analysis are for reference only. Users are solely responsible for all risks and outcomes of investment decisions made based on this project. Please conduct thorough research and risk assessment before making any real trades.