# astrader **Repository Path**: public26/astrader ## Basic Information - **Project Name**: astrader - **Description**: 支持A股交易的简易交易执行框架,轻量化、模块化,支持接入mini qmt - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 3 - **Created**: 2025-12-27 - **Last Updated**: 2026-05-12 ## Categories & Tags **Categories**: stocks **Tags**: None ## README # astrader ![logo](./docs/img/logo.png) ### Introduction A simple trading execution framework supporting A-share trading, lightweight and modular, suitable for personal use, supporting mini qmt ### Software Architecture #### 1.1 Overall Architecture - **Backend**: Python + FastAPI + Trading Engine - **Frontend**: Vue 3 + Vite - **Database**: SQLite/MySQL - **Configuration File**: YAML format #### 1.2 Core Modules - **Trading Engine**: Responsible for executing trading strategies - **API Service**: Provides frontend data query interface - **Monitoring Page**: Displays trading status and strategy running conditions ### Installation Tutorial #### 1. Environment Preparation ##### 1.1 System Requirements - Python 3.11+ - Node.js 16+ - npm 8+ - qmt mini api, placed in the thirdparty/ directory (thirdparty/xtquant) ##### 1.2 Dependency Installation ###### Backend Dependencies ```bash # Enter the project root directory cd /path/to/astrader # Install Python dependencies pip install -r requirements.txt ``` ###### Frontend Dependencies ```bash # Enter the frontend directory cd /path/to/astrader/frontend # Install npm dependencies npm install # Build production version npm run build ``` #### 2. Configuration Management ##### 2.1 Configuration File Structure - Configuration files are located in the `config/` directory - It is recommended to use an independent configuration file for production environment, such as `config_prd.yaml` - Configuration files include the following main parts: - `base`: Basic configuration (holidays, trading time, logs, etc.) - `engine`: Engine configuration (strategy ID list, etc.) - `hq`: Market data configuration - `trade`: Trading configuration - `strategies`: Strategy configuration ##### 2.2 Key Configuration Items - `engine.strategyids`: List of running strategy IDs - `base.logging`: Log configuration - `trade`: Trading account configuration - `strategies`: Detailed strategy configuration #### 3. Service Startup ##### 3.1 Trading Engine Startup ###### Direct Run ```bash # Start the trading engine with specified configuration file python run.py config/config_prd.yaml prd_logs ``` ##### 3.2 API Service Startup ###### Method 1: Direct Run ```bash # Start FastAPI service python main.py ``` ##### 3.3 Frontend Deployment In production deployment, you can use npm to compile into static files, and in development mode, you can use npm run dev to start ###### Method 1: Mount Static Files to FastApi ```python # Add static file service frontend_dist = os.path.join(os.path.dirname(os.path.abspath(__file__)), "frontend", "dist") # Mount the entire dist directory as static file service app.mount("/", StaticFiles(directory=frontend_dist, html=True), name="static") ``` ###### Method 2: Use Nginx to Deploy Static Files ```nginx server { listen 80; server_name your-domain.com; location / { root /path/to/astrader/frontend/dist; index index.html; try_files $uri $uri/ /index.html; } # API proxy location /api { proxy_pass http://localhost:8800; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } ``` ###### Method 3: Use Node.js Static Server ```bash # Install serve tool npm install -g serve # Start static server serve -s /path/to/astrader/frontend/dist -l 80 ``` ###### Method 4: Start in Development Mode ```bash /path/to/astrader/frontend npm run dev ``` ### Log Management #### 1 Log Location - Trading engine logs: In the `logs/` directory, classified by date and strategy ID - API service logs: Output to console by default, can be configured to file # Install serve tool ```bash npm install -g serve # Start static server serve -s /path/to/astrader/frontend/dist -l 80 ``` ### Log Management #### 1 Log Location - Trading engine logs: In the `logs/` directory, classified by date and strategy ID - API service logs: Output to console by default, can be configured to file - Frontend logs: Browser console, it is recommended to turn off debug logs in production environment #### 2 Log Levels - `INFO` level is recommended for production environment - `DEBUG` level can be used for debugging - Can be set through `base.logging.level` in the configuration file ### Monitoring and Maintenance #### 1 Health Check - API service provides health check interface: `http://localhost:8800/health` - Can be used to monitor service status #### 2 Common Problem Troubleshooting - **Trading engine unresponsive**: Check log files to see if there are error messages - **API service inaccessible**: Check port occupancy, view service logs - **Frontend page blank**: Check browser console for errors, confirm if API service is normal - **Strategy not executing**: Check if strategy configuration is correct, confirm if strategy ID is in `engine.strategyids` ### Contribution Guide 1. Fork this repository 2. Create a new Feat_xxx branch 3. Submit code 4. Create a new Pull Request ### Final Words 1. Welcome to join QQ exchange group (190095620) for communication and learning 2. Scan to join ![QQ Group QR Code](./docs/img/qq.png) ## Disclaimer 1. This project (astrader) is an open-source framework supporting A-share trading, for learning and research purposes only, and does not constitute any investment advice or trading guidance. 2. This project is developed based on mini qmt API. Before using this project, please ensure that you have complied with the service terms and usage agreements of relevant financial institutions. 3. The author is not responsible for any trading results, financial losses, or legal liabilities arising from the use of this project. Users shall bear all trading risks and legal liabilities. 4. This project may contain errors or imperfections, and the author does not guarantee its accuracy, completeness, or reliability. 5. Any trading operations based on this project are independently decided by the users, and have nothing to do with the author. 6. Users shall comply with relevant national laws and regulations, and shall not use this project for any illegal activities. By using this project, you agree to all the terms of the above disclaimer.