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.
- 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).
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.
- 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.
(This section is a placeholder. You can add installation and setup instructions here.)
- Clone the repository:
git clone <repository-url> cd TradingBot
- Install backend dependencies:
pip install -r requirements.txt
- Install frontend dependencies:
cd dashboard npm install - Run the application:
# Run backend python main.py # Run frontend cd dashboard npm start
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.
- strategies
id: Primary Keyname: 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 Keyname: User-defined name for the portfolio.strategy_id: Foreign Key tostrategies.starting_value: The initial capital.current_value: The current market value of the portfolio.
- orders
id: Primary Keyportfolio_id: Foreign Key toportfolios.stock: The stock ticker.order_type:backtest,virtual, orreal.transaction_type:buyorsell.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.
Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs, feature requests, or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.