Skip to content

JUSTUSVMOS/MarginCall_2X

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

183 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MarginCall_2X - The Bankruptcy Booster

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.

Core Features

  • AI Trading Companion:

    • Powered by the Google Gemini AI, its distinct and strong personality is shaped by the system_prompt within config.py.
    • Features a built-in "trash talk" system with humorous and cynical responses that change based on market conditions, making interactions more engaging.
  • 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.py module to fetch real-time portfolio data from the user's account.
  • Telegram Interface:

    • Built with the telebot framework, allowing for easy and convenient interaction on Telegram.
    • Includes a /reset command to clear the AI's conversation history and start fresh.
  • 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.

Installation & Setup

  1. Clone the Project:

    git clone https://github.com/your-username/MarginCall_2X.git
    cd MarginCall_2X
  2. Create and Activate a Virtual Environment:

    python -m venv venv
    source venv/bin/activate  # For Windows: venv\Scripts\activate
  3. Install Dependencies: Install the pinned runtime dependencies from requirements.txt:

    pip install -r requirements.txt
  4. Set Up Environment Variables: Copy the .env.un~ file to .env and fill in your personal credentials:

    cp .env.un~ .env

    Then, edit the .env file 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.

Usage

Once everything is set up, run the main script to start the bot:

python main.py

You can then start chatting with your "Bankruptcy Booster" on Telegram.

Refactor Execution Guide

The current shared runtime is organized under src/:

  • src/llm.py: shared Gemini client, shared cooldown table, quick_call() and chat_with_tools()
  • src/database.py: shared SQLite lock plus WAL-enabled connection helpers
  • src/symbols.py: shared ticker normalization
  • src/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.py

Disclaimer

This 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.

About

兩倍速破產推進器

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages