Skip to content

Repository files navigation

TradingBot

TradingBot is a flexible and extensible platform for developing, backtesting, and deploying automated trading strategies. It supports real-time, virtual, and historical backtesting environments. All trading activities are recorded for performance analysis. The accompanying dashboard provides a comprehensive view of strategy performance, including portfolio metrics, interactive charts with trade indicators, and detailed order history.

✨ Features

  • Strategy Management: Create and manage multiple trading strategies with customizable parameters.
  • Multiple Trading Modes:
    • Backtesting: Test strategies against historical market data.
    • Virtual Trading: Paper trade with real-time market data without risking real capital.
    • Live Trading: Deploy profitable strategies to trade with a real brokerage account.
  • Performance Dashboard:
    • Visualize portfolio performance over time.
    • Interactive candlestick charts with buy/sell signals and strategy metadata.
    • Detailed transaction logs for each portfolio.
  • Extensible Strategy Framework: Easily implement new trading strategies by extending a base strategy class.
  • AI-Powered Strategy Improvement: Download portfolio data to get suggestions for strategy improvements from a Large Language Model (LLM).

🏗️ Architecture

The application is composed of a Python backend, a database, and a web-based dashboard.

  • Backend (main.py): A Python server that exposes a REST API for the dashboard and handles all core logic, including strategy execution, portfolio management, and data processing.
  • Dashboard: A web interface for users to interact with the system. It allows for creating strategies, running backtests, and analyzing performance.
  • Database: A persistent store for all user-created strategies, portfolios, and trade orders.

Core Modules

  • Strategy: Defines the base interface for all trading strategies. Each strategy implements logic to process market data (on_tick) and determine whether to buy, sell, or hold.
  • Portfolio: Manages the state of a trading account, including its value, positions, and historical data. It executes trades based on signals from its assigned strategy.
  • Backtest: Orchestrates the process of running a strategy against historical data. It feeds historical ticks to a portfolio and records the resulting performance.
  • Orders: Handles the creation and storage of trade orders. It includes logic to place orders with a real brokerage API for live trading.

🚀 Getting Started

(This section is a placeholder. You can add installation and setup instructions here.)

  1. Clone the repository:
    git clone <repository-url>
    cd TradingBot
  2. Install backend dependencies:
    pip install -r requirements.txt
  3. Install frontend dependencies:
    cd dashboard
    npm install
  4. Run the application:
    # Run backend
    python main.py
    
    # Run frontend
    cd dashboard
    npm start

📋 API Endpoints

The backend exposes several endpoints to be consumed by the dashboard.

  • get_strategy_objects: Returns a list of available strategy classes (e.g., BollingerBand).
  • create_strategy_db: Creates a new strategy instance in the database.
  • get_strategies_from_db: Retrieves all user-created strategies from the database.
  • get_portfolios_by_strategy: Fetches portfolios associated with a specific strategy.
  • get_orders_by_portfolio: Gets all orders for a given portfolio.
  • backtest_strategy: Initiates a new backtest for a given strategy, creating a new portfolio.
  • deploy_strategy: Deploys a portfolio for virtual or live trading.

🗄️ Database Schema

  • strategies
    • id: Primary Key
    • name: User-defined name for the strategy instance.
    • strategy_class_name: The name of the strategy class (e.g., "BollingerBand").
    • parameters: JSON object of modified parameters.
  • portfolios
    • id: Primary Key
    • name: User-defined name for the portfolio.
    • strategy_id: Foreign Key to strategies.
    • starting_value: The initial capital.
    • current_value: The current market value of the portfolio.
  • orders
    • id: Primary Key
    • portfolio_id: Foreign Key to portfolios.
    • stock: The stock ticker.
    • order_type: backtest, virtual, or real.
    • transaction_type: buy or sell.
    • price: Execution price.
    • timestamp: Time of the transaction.
    • portfolio_value: The value of the portfolio at the time of the order.
    • metadata: JSON object for strategy-specific data to display on the chart.

🤝 Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs, feature requests, or improvements.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A full-stack, AI-powered algorithmic trading platform. Develop, backtest, and deploy trading strategies using Python (FastAPI, PyTorch, Transformers) and a React dashboard. Features advanced strategies including Deep Q-Networks (DQN) and Large Language Models (LLM) for real-time market analysis and execution.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages