@@ -6,60 +6,138 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66
77QUANTAXIS is a quantitative financial framework written in Python that provides a comprehensive suite of tools for financial data analysis, backtesting, and trading strategy development. The project is organized into multiple modular components for different aspects of quantitative finance.
88
9+ ** Version** : 2.0.0 (incompatible upgrade from 1.x)
10+ ** Author** : @yutiansut (When making changes, attribute to @yutiansut @quantaxis , not Claude)
11+
12+ ## Related Projects Ecosystem
13+
14+ - [ QAUltra-cpp] ( https://github.com/QUANTAXIS/qaultra-cpp ) - C++ implementation of QUANTAXIS
15+ - [ QAUltra-rs] ( https://github.com/QUANTAXIS/qautlra-rs ) - Rust implementation (partially open source)
16+ - [ QADataSwap] ( https://github.com/QUANTAXIS/qadataswap ) - Cross-language communication framework (Rust/C++/Python)
17+ - [ QAExchange-RS] ( https://github.com/yutiansut/qaexchange-rs ) - Exchange implementation + self-developed HTAP hybrid database
18+
19+ ## Core Concept: QIFI Protocol
20+
21+ ** CRITICAL** : QIFI (Quantaxis Differential Information Flow for Finance Integration) is the unified account structure used throughout QUANTAXIS. All accounts, orders, positions, and trades exist within the QIFI structure stored in MongoDB.
22+
23+ ### QIFI Structure
24+ The QIFI protocol decouples strategy logic from account implementation. A QIFI account contains:
25+ - ` accounts ` : Account balances, margins, risk metrics
26+ - ` orders ` : Order book with status tracking
27+ - ` positions ` : Position details (long/short, today/history, P&L)
28+ - ` trades ` : Executed trades
29+ - ` events ` : Time-stamped event log
30+ - ` broker_name ` : Trading counter identifier
31+
32+ ** Key principle** : Strategies request resources (backtest/simulation/live accounts) and read QIFI fields directly without knowing the underlying implementation. See ` QUANTAXIS/QIFI/qifi.md ` for the complete specification and ` examples/qifiaccountexample.py ` for usage.
33+
934## Architecture
1035
1136The codebase is structured into distinct modules under the ` QUANTAXIS/ ` package:
1237
1338- ** QAFetch** : Multi-market data acquisition and storage (MongoDB/ClickHouse)
39+ - Supports stocks (TDX, Tushare), futures (CTP), crypto (Binance, Huobi, OKEx)
40+ - Unified interface across multiple data sources with fallback support
1441- ** QAUtil** : Trading time utilities, calendars, market identification, and dataframe conversions
1542- ** QIFI/QAMarket** : Unified multi-market, multi-language account system
16- - ` qifiaccount ` : Standard account system consistent across languages ( Python/Rust/C++)
43+ - ` QifiAccount ` : Standard account system consistent across Python/Rust/C++
1744 - ` qifimanager ` : Multi-account management system
1845 - ` qaposition ` : Single asset position management for precise long/short control
19- - ` marketpreset ` : Market preset classes for futures/stocks/crypto metadata
46+ - ` marketpreset ` : Market preset classes for futures/stocks/crypto metadata (margins, fees, tick sizes)
2047- ** QAFactor** : Factor research suite for factor analysis, management, and combination
21- - ** QAData** : Multi-asset, multi-market data structures for real-time and backtesting
48+ - ** QAData** : Multi-asset, multi-market data structures (QA_DataStruct_ * ) for real-time and backtesting
49+ - Supports Stock/Future/Index/Crypto for Day/Min/Tick data
50+ - Resampling capabilities (tick→1min→5min→day)
2251- ** QAIndicator** : Custom indicator framework with batch market-wide application
2352- ** QAEngine** : Custom thread/process base classes for async and distributed computing
24- - ** QAPubSub** : MQ-based message queue supporting 1-1, 1-n, n-n message distribution
53+ - ` QA_Thread ` , ` QA_AsyncThread ` , ` QA_Worker ` for parallel task execution
54+ - ** QAPubSub** : MQ-based message queue (RabbitMQ) supporting 1-1, 1-n, n-n message distribution
2555- ** QAStrategy** : CTA/arbitrage backtesting suite with QIFI mode support
2656- ** QAWebServer** : Tornado-based web server for microservice architecture
2757- ** QASchedule** : Background task scheduling built on QAWebServer
58+ - Supports dynamic task assignment and DAG-based pipelines
2859- ** QAAnalysis** : Analysis and reporting tools
2960- ** QACmd** : Command-line interface and utilities
3061- ** QASU** : System utilities and maintenance tools
3162
3263## Development Commands
3364
65+ ### Prerequisites
66+
67+ QUANTAXIS requires MongoDB, ClickHouse, and RabbitMQ. The easiest way to set up the stack is with Docker:
68+
69+ ``` bash
70+ # Start all required services (MongoDB, ClickHouse, Redis, RabbitMQ)
71+ cd docker
72+ docker-compose -f just_database.yaml up -d
73+
74+ # Services will be available at:
75+ # - MongoDB: localhost:27017
76+ # - ClickHouse: localhost:9000 (native), localhost:8123 (HTTP)
77+ # - Redis: localhost:6379
78+ # - RabbitMQ: localhost:5672 (AMQP), localhost:15672 (management UI)
79+ ```
80+
3481### Installation
3582``` bash
3683pip install -e .
3784# Or install requirements first:
3885pip install -r requirements.txt
3986```
4087
88+ ### Initial Data Setup
89+ ``` bash
90+ # Initialize and populate database with market data
91+ python config/data_init.py
92+
93+ # Update various market data types
94+ python config/update_all.py # Update all markets
95+ python config/update_data.py # Update stock data
96+ python config/update_future.py # Update futures data
97+ python config/update_fin.py # Update financial data
98+ ```
99+
41100### Code Quality
42101``` bash
43102# Linting (uses pylint with configuration in .pylintrc)
44103pylint QUANTAXIS/
45104
46105# The project has a comprehensive .pylintrc configuration file
106+ # CI/CD runs on GitHub Actions (see .github/workflows/)
47107```
48108
49109### Console Commands
50- The package provides several console entry points:
51- - ` quantaxis ` - Main CLI command
52- - ` quantaxisq ` - TDX data fetching
53- - ` qarun ` - Strategy runner
54- - ` qawebserver ` - Web server launcher
110+ After installation, the following commands are available system-wide:
111+
112+ ``` bash
113+ # Main CLI interface
114+ quantaxis
115+
116+ # TDX (TongDaXin) market data fetching
117+ quantaxisq
118+
119+ # Run strategies
120+ qarun
121+
122+ # Start QUANTAXIS web server (microservices)
123+ qawebserver
124+ ```
125+
126+ ### Docker Deployment
127+
128+ Multiple Docker images are available for different use cases:
55129
56- ### Data Management
57130``` bash
58- # Update market data (various scripts in config/)
59- python config/update_data.py
60- python config/update_all.py
61- python config/update_future.py
62- python config/update_fin.py
131+ # Full development environment with Jupyter
132+ docker pull daocloud.io/quantaxis/qa-jupyter
133+
134+ # Base runtime environment
135+ docker pull daocloud.io/quantaxis/qa-base
136+
137+ # Event message queue (RabbitMQ)
138+ docker pull daocloud.io/quantaxis/qaeventmq
139+
140+ # For Kubernetes deployments, see docker/k8s_deploy_qaservice/
63141```
64142
65143## Key Dependencies
@@ -80,9 +158,61 @@ The project supports integration with QUANTAXIS Rust version through:
80158
81159## Database Architecture
82160
83- - ** MongoDB** : Primary data storage for market data and account information
84- - ** ClickHouse** : High-performance analytics database for large-scale data analysis
85- - Support for tick/L2 order/transaction data formats
161+ QUANTAXIS uses a multi-database architecture for different use cases:
162+
163+ - ** MongoDB** : Primary data storage
164+ - Market data (stocks, futures, crypto): day/min/tick OHLCV
165+ - QIFI account structures (accounts, orders, positions, trades)
166+ - Factor data and research results
167+ - Default database name: ` quantaxis `
168+
169+ - ** ClickHouse** : High-performance OLAP database
170+ - Large-scale historical data analysis
171+ - QIFI account storage with better compression
172+ - Tabular data and factor analysis
173+ - Supports tick/L2 order/transaction data formats
174+
175+ - ** Redis** : Cache and real-time data
176+ - Session management
177+ - Real-time market data cache
178+
179+ - ** RabbitMQ** (via QAPubSub): Message queue
180+ - Real-time order flow
181+ - Task distribution and collection
182+ - Event-driven architecture support
183+
184+ ## What's New in 2.0
185+
186+ Version 2.0 is a ** breaking upgrade** from 1.x with major architectural changes:
187+
188+ ** Data Layer** :
189+ - Added ClickHouse support for self-hosted data distribution
190+ - Support for tabular data and factor-based data structures
191+ - Native support for tick/L2 order/transaction formats
192+
193+ ** Microservices** :
194+ - New QAWebServer module (Tornado-based)
195+ - Dynamic task scheduling via QASchedule
196+ - DAG-based pipeline support
197+ - QAPubSub module for RabbitMQ integration
198+
199+ ** Account System** :
200+ - Removed legacy QAARP account system (no longer maintained)
201+ - Complete migration to QIFI protocol
202+ - Multi-market/cross-market account models
203+ - Support for margin trading (futures, stocks) and options (in development)
204+
205+ ** Live/Simulation Trading** :
206+ - Unified QIFI interface for all trading modes
207+ - CTP interface support (futures and options)
208+ - Stock trading via QMT integration
209+ - Parent-child account order distribution and tracking (OMS)
210+ - Order gateway with risk management rules
211+
212+ ** Multi-Language Support** :
213+ - Communication with QUANTAXIS Rust version via Apache Arrow
214+ - Consistent QIFI account structures across Python/Rust/C++
215+ - Factor computation using Rust job workers
86216
87217## Configuration Files
88218
@@ -93,12 +223,67 @@ The project supports integration with QUANTAXIS Rust version through:
93223
94224## Examples and Usage
95225
96- Check the ` examples/ ` directory for:
97- - ` qifiaccountexample.py ` : QIFI account system usage
98- - ` factoranalysis.py ` : Factor analysis workflows
99- - ` scheduleserver.py ` : Task scheduling examples
100- - ` featureanalysis.ipynb ` : Jupyter notebook examples
226+ The ` examples/ ` directory contains practical usage examples:
227+
228+ ``` bash
229+ # QIFI account usage (backtest mode with ClickHouse)
230+ python examples/qifiaccountexample.py
231+
232+ # Factor analysis workflow
233+ python examples/factoranalysis.py
234+
235+ # Task scheduling server setup
236+ python examples/scheduleserver.py
237+
238+ # ClickHouse QIFI integration
239+ python examples/test_ckread_qifi.py
240+
241+ # Jupyter notebooks in examples/ for interactive analysis
242+ ```
243+
244+ ### Basic QIFI Account Example
245+ ``` python
246+ from QUANTAXIS .QIFI .QifiAccount import QIFI_Account
247+
248+ # Create account (backtest mode, using ClickHouse)
249+ account = QIFI_Account(
250+ username = ' testx' ,
251+ password = ' 123456' ,
252+ model = ' BACKTEST' ,
253+ nodatabase = False ,
254+ dbname = ' ck' ,
255+ clickhouse_port = 9000
256+ )
257+
258+ # Initialize and send order
259+ account.initial()
260+ order = account.send_order(" 000001" , 200 , 20 , 1 , datetime = ' 2021-09-30' )
261+
262+ # Execute trade
263+ account.make_deal(order)
264+
265+ # Get positions
266+ positions = list (account.position_qifimsg.values())
267+
268+ # Settle at day end
269+ account.settle()
270+ ```
101271
102272## Version Support
103273
104- Python 3.5-3.10 supported (see setup.py for version validation).
274+ ** Python** : 3.5-3.10 supported (see setup.py:40 for version validation)
275+
276+ ## Community and Support
277+
278+ - ** QQ Group** : 563280067 ([ Join link] ( https://jq.qq.com/?_wv=1027&k=4CEKGzn ) )
279+ - ** Developer Group** : 773602202 (requires GitHub ID for code contributors)
280+ - ** Production Deployment Group** : 945822690 (for multi-account local deployment)
281+ - ** Discord** : https://discord.gg/mkk5RgN
282+ - ** Forum** : [ QUANTAXIS Club] ( http://www.yutiansut.com:3000 ) (highest priority for support)
283+ - ** GitHub Issues** : [ Report bugs and request features] ( https://github.com/QUANTAXIS/QUANTAXIS/issues )
284+
285+ ## Documentation
286+
287+ - [ QABook Release] ( https://github.com/QUANTAXIS/QUANTAXIS/releases/download/latest/quantaxis.pdf ) - Comprehensive documentation (PDF)
288+ - Project README (Chinese): ` README.md `
289+ - QIFI Protocol Specification: ` QUANTAXIS/QIFI/qifi.md `
0 commit comments