qka 1.0.4.dev1__tar.gz → 1.0.5.dev20__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/.gitignore +173 -172
  2. qka-1.0.5.dev20/PKG-INFO +335 -0
  3. qka-1.0.5.dev20/README.md +274 -0
  4. qka-1.0.5.dev20/docs/api/brokers.md +166 -0
  5. qka-1.0.5.dev20/docs/api/core.md +124 -0
  6. qka-1.0.5.dev20/docs/api/utils.md +97 -0
  7. qka-1.0.5.dev20/docs/getting-started/concepts.md +199 -0
  8. qka-1.0.5.dev20/docs/getting-started/first-strategy.md +176 -0
  9. qka-1.0.5.dev20/docs/getting-started/installation.md +99 -0
  10. qka-1.0.5.dev20/docs/index.md +67 -0
  11. qka-1.0.5.dev20/docs/user-guide/backtest.md +342 -0
  12. qka-1.0.5.dev20/docs/user-guide/data.md +243 -0
  13. qka-1.0.5.dev20/docs/user-guide/trading.md +272 -0
  14. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/mkdocs.yml +4 -41
  15. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/pyproject.toml +4 -0
  16. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/__init__.py +4 -12
  17. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/brokers/client.py +37 -8
  18. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/brokers/server.py +81 -18
  19. qka-1.0.5.dev20/qka/core/__init__.py +19 -0
  20. qka-1.0.5.dev20/qka/core/backtest.py +117 -0
  21. qka-1.0.5.dev20/qka/core/broker.py +215 -0
  22. qka-1.0.5.dev20/qka/core/data.py +180 -0
  23. qka-1.0.5.dev20/qka/core/strategy.py +33 -0
  24. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/utils/__init__.py +0 -5
  25. qka-1.0.4.dev1/PKG-INFO +0 -122
  26. qka-1.0.4.dev1/README.md +0 -65
  27. qka-1.0.4.dev1/docs/A/350/202/241/345/270/202/345/234/272/350/257/201/345/210/270/344/273/243/347/240/201/345/221/275/345/220/215/350/247/204/345/210/231.md +0 -276
  28. qka-1.0.4.dev1/docs/api/brokers/index.md +0 -106
  29. qka-1.0.4.dev1/docs/api/core/config.md +0 -200
  30. qka-1.0.4.dev1/docs/api/core/events.md +0 -253
  31. qka-1.0.4.dev1/docs/api/core/index.md +0 -98
  32. qka-1.0.4.dev1/docs/api/index.md +0 -73
  33. qka-1.0.4.dev1/docs/api/mcp/index.md +0 -83
  34. qka-1.0.4.dev1/docs/api/utils/index.md +0 -97
  35. qka-1.0.4.dev1/docs/api/utils/logger.md +0 -317
  36. qka-1.0.4.dev1/docs/api/utils/tools.md +0 -468
  37. qka-1.0.4.dev1/docs/enhanced_features_phase1.md +0 -472
  38. qka-1.0.4.dev1/docs/examples/index.md +0 -143
  39. qka-1.0.4.dev1/docs/getting-started/concepts.md +0 -349
  40. qka-1.0.4.dev1/docs/getting-started/first-strategy.md +0 -335
  41. qka-1.0.4.dev1/docs/getting-started/installation.md +0 -214
  42. qka-1.0.4.dev1/docs/index.md +0 -182
  43. qka-1.0.4.dev1/docs/user-guide/backtest.md +0 -465
  44. qka-1.0.4.dev1/docs/user-guide/config.md +0 -322
  45. qka-1.0.4.dev1/docs/user-guide/data.md +0 -283
  46. qka-1.0.4.dev1/docs/user-guide/events.md +0 -414
  47. qka-1.0.4.dev1/docs/user-guide/logging.md +0 -522
  48. qka-1.0.4.dev1/docs/user-guide/strategy.md +0 -340
  49. qka-1.0.4.dev1/docs/user-guide/trading.md +0 -512
  50. qka-1.0.4.dev1/examples/basic_test.py +0 -135
  51. qka-1.0.4.dev1/examples/enhanced_features_demo.py +0 -261
  52. qka-1.0.4.dev1/examples/simple_backtest_demo.py +0 -44
  53. qka-1.0.4.dev1/examples/simple_demo.py +0 -111
  54. qka-1.0.4.dev1/qka/core/__init__.py +0 -17
  55. qka-1.0.4.dev1/qka/core/backtest.py +0 -329
  56. qka-1.0.4.dev1/qka/core/config.py +0 -230
  57. qka-1.0.4.dev1/qka/core/data/__init__.py +0 -38
  58. qka-1.0.4.dev1/qka/core/data/akshare.py +0 -106
  59. qka-1.0.4.dev1/qka/core/data/base.py +0 -219
  60. qka-1.0.4.dev1/qka/core/data/qmt.py +0 -64
  61. qka-1.0.4.dev1/qka/core/events.py +0 -365
  62. qka-1.0.4.dev1/qka/core/plot.py +0 -218
  63. qka-1.0.4.dev1/qka/utils/tools.py +0 -397
  64. qka-1.0.4.dev1//345/267/245/344/275/234/350/277/233/345/272/246/350/256/260/345/275/225.md +0 -217
  65. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/.github/workflows/docs.yml +0 -0
  66. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/.github/workflows/release.yml +0 -0
  67. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/.vscode/settings.json +0 -0
  68. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/CHANGELOG.md +0 -0
  69. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/LICENSE +0 -0
  70. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/brokers/__init__.py +0 -0
  71. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/brokers/trade.py +0 -0
  72. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/mcp/__init__.py +0 -0
  73. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/mcp/api.py +0 -0
  74. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/mcp/server.py +0 -0
  75. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/utils/anis.py +0 -0
  76. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/utils/logger.py +0 -0
  77. {qka-1.0.4.dev1 → qka-1.0.5.dev20}/qka/utils/util.py +0 -0
@@ -1,172 +1,173 @@
1
- # Byte-compiled / optimized / DLL files
2
- __pycache__/
3
- *.py[cod]
4
- *$py.class
5
-
6
- # C extensions
7
- *.so
8
-
9
- # Distribution / packaging
10
- .Python
11
- build/
12
- develop-eggs/
13
- dist/
14
- downloads/
15
- eggs/
16
- .eggs/
17
- lib/
18
- lib64/
19
- parts/
20
- sdist/
21
- var/
22
- wheels/
23
- share/python-wheels/
24
- *.egg-info/
25
- .installed.cfg
26
- *.egg
27
- MANIFEST
28
-
29
- # PyInstaller
30
- # Usually these files are written by a python script from a template
31
- # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
- *.manifest
33
- *.spec
34
-
35
- # Installer logs
36
- pip-log.txt
37
- pip-delete-this-directory.txt
38
-
39
- # Unit test / coverage reports
40
- htmlcov/
41
- .tox/
42
- .nox/
43
- .coverage
44
- .coverage.*
45
- .cache
46
- nosetests.xml
47
- coverage.xml
48
- *.cover
49
- *.py,cover
50
- .hypothesis/
51
- .pytest_cache/
52
- cover/
53
-
54
- # Translations
55
- *.mo
56
- *.pot
57
-
58
- # Django stuff:
59
- *.log
60
- local_settings.py
61
- db.sqlite3
62
- db.sqlite3-journal
63
-
64
- # Flask stuff:
65
- instance/
66
- .webassets-cache
67
-
68
- # Scrapy stuff:
69
- .scrapy
70
-
71
- # Sphinx documentation
72
- docs/_build/
73
-
74
- # PyBuilder
75
- .pybuilder/
76
- target/
77
-
78
- # Jupyter Notebook
79
- .ipynb_checkpoints
80
-
81
- # IPython
82
- profile_default/
83
- ipython_config.py
84
-
85
- # pyenv
86
- # For a library or package, you might want to ignore these files since the code is
87
- # intended to run in multiple environments; otherwise, check them in:
88
- # .python-version
89
-
90
- # pipenv
91
- # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
- # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
- # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
- # install all needed dependencies.
95
- #Pipfile.lock
96
-
97
- # poetry
98
- # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
- # This is especially recommended for binary packages to ensure reproducibility, and is more
100
- # commonly ignored for libraries.
101
- # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
-
103
- # uv
104
- .venv/
105
- .uv/
106
- __pypackages__/
107
- .uvrc.local
108
- #poetry.lock
109
-
110
- # pdm
111
- # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
- #pdm.lock
113
- # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
- # in version control.
115
- # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
- .pdm.toml
117
- .pdm-python
118
- .pdm-build/
119
-
120
- # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
- __pypackages__/
122
-
123
- # Celery stuff
124
- celerybeat-schedule
125
- celerybeat.pid
126
-
127
- # SageMath parsed files
128
- *.sage.py
129
-
130
- # Environments
131
- .env
132
- .venv
133
- env/
134
- venv/
135
- ENV/
136
- env.bak/
137
- venv.bak/
138
-
139
- # Spyder project settings
140
- .spyderproject
141
- .spyproject
142
-
143
- # Rope project settings
144
- .ropeproject
145
-
146
- # mkdocs documentation
147
- /site
148
-
149
- # mypy
150
- .mypy_cache/
151
- .dmypy.json
152
- dmypy.json
153
-
154
- # Pyre type checker
155
- .pyre/
156
-
157
- # pytype static type analyzer
158
- .pytype/
159
-
160
- # Cython debug symbols
161
- cython_debug/
162
-
163
- # PyCharm
164
- # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
- # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
- # and can be added to the global gitignore or merged into this file. For a more nuclear
167
- # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
- #.idea/
169
-
170
- *.ipynb
171
- uv.lock
172
- output
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+
103
+ # uv
104
+ .venv/
105
+ .uv/
106
+ __pypackages__/
107
+ .uvrc.local
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ *.ipynb
171
+ uv.lock
172
+ output
173
+ datadir
@@ -0,0 +1,335 @@
1
+ Metadata-Version: 2.4
2
+ Name: qka
3
+ Version: 1.0.5.dev20
4
+ Summary: 快捷量化助手(Quick Quantitative Assistant)- 简洁易用的A股量化交易框架
5
+ Project-URL: Home, https://github.com/zsrl/qka
6
+ Project-URL: Documentation, https://zsrl.github.io/qka
7
+ Project-URL: Repository, https://github.com/zsrl/qka
8
+ Project-URL: Issues, https://github.com/zsrl/qka/issues
9
+ Author-email: myc <mayuanchi1029@gmail.com>
10
+ License: MIT License
11
+
12
+ Copyright (c) 2024 量化投资技术
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.10
35
+ Classifier: Programming Language :: Python :: 3.11
36
+ Classifier: Programming Language :: Python :: 3.12
37
+ Requires-Python: >=3.10
38
+ Requires-Dist: akshare>=1.16.93
39
+ Requires-Dist: dask[complete]>=2025.7.0
40
+ Requires-Dist: fastapi>=0.115.13
41
+ Requires-Dist: flask>=3.1.1
42
+ Requires-Dist: ipykernel>=6.29.5
43
+ Requires-Dist: mcp[cli]>=1.9.0
44
+ Requires-Dist: nbformat>=5.10.4
45
+ Requires-Dist: plotly>=6.1.1
46
+ Requires-Dist: pyarrow>=21.0.0
47
+ Requires-Dist: ta>=0.11.0
48
+ Requires-Dist: tqdm>=4.67.1
49
+ Requires-Dist: uvicorn>=0.34.3
50
+ Requires-Dist: xtquant>=241014.1.2
51
+ Provides-Extra: dev
52
+ Requires-Dist: hatch-vcs>=0.3.0; extra == 'dev'
53
+ Requires-Dist: mkdocs-material>=9.6.14; extra == 'dev'
54
+ Requires-Dist: mkdocs>=1.6.1; extra == 'dev'
55
+ Requires-Dist: mkdocstrings-python>=1.16.12; extra == 'dev'
56
+ Requires-Dist: mkdocstrings>=0.29.1; extra == 'dev'
57
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
58
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
59
+ Requires-Dist: python-semantic-release>=9.0.0; extra == 'dev'
60
+ Description-Content-Type: text/markdown
61
+
62
+ # QKA - 快量化
63
+
64
+ [![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
65
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
66
+ [![PyPI](https://img.shields.io/pypi/v/qka)](https://pypi.org/project/qka/)
67
+
68
+ **快捷量化助手(Quick Quantitative Assistant)** 是一个简洁易用、功能完整的A股量化交易框架,支持数据获取、策略回测、实盘交易等全流程量化交易功能。
69
+
70
+ ## 特性
71
+
72
+ - 🚀 **简洁易用**: 统一的API设计,降低量化交易门槛
73
+ - 📊 **数据丰富**: 支持Akshare数据源,提供多周期、多因子数据
74
+ - 🔄 **高效回测**: 基于时间序列的回测引擎,支持多股票横截面处理
75
+ - 💰 **实盘交易**: 集成QMT交易接口,支持实盘交易
76
+ - 📈 **可视化**: 内置Plotly图表,提供交互式回测结果展示
77
+ - 🔧 **模块化**: 高度模块化设计,易于扩展和维护
78
+ - 📝 **文档完整**: 提供详细的API文档和使用示例
79
+
80
+ ## 安装
81
+
82
+ ### 从PyPI安装
83
+
84
+ ```bash
85
+ pip install qka
86
+ ```
87
+
88
+ ### 从源码安装
89
+
90
+ ```bash
91
+ git clone https://github.com/zsrl/qka.git
92
+ cd qka
93
+ pip install -e .
94
+ ```
95
+
96
+ ## 快速开始
97
+
98
+ ### 1. 数据获取
99
+
100
+ ```python
101
+ import qka
102
+
103
+ # 创建数据对象
104
+ data = qka.Data(
105
+ symbols=['000001.SZ', '600000.SH'], # 股票代码列表
106
+ period='1d', # 日线数据
107
+ adjust='qfq' # 前复权
108
+ )
109
+
110
+ # 获取数据
111
+ df = data.get()
112
+ print(df.head())
113
+ ```
114
+
115
+ ### 2. 策略开发
116
+
117
+ ```python
118
+ import qka
119
+
120
+ class MyStrategy(qka.Strategy):
121
+ def __init__(self):
122
+ super().__init__()
123
+ self.cash = 100000 # 初始资金
124
+
125
+ def on_bar(self, date, get):
126
+ """每个bar的处理逻辑"""
127
+ # 获取当前价格数据
128
+ close_prices = get('close')
129
+
130
+ # 示例策略:当000001.SZ价格低于10元时买入
131
+ if '000001.SZ' in close_prices and close_prices['000001.SZ'] < 10:
132
+ # 买入1000股
133
+ self.broker.buy('000001.SZ', close_prices['000001.SZ'], 1000)
134
+ ```
135
+
136
+ ### 3. 回测分析
137
+
138
+ ```python
139
+ import qka
140
+
141
+ # 创建策略实例
142
+ strategy = MyStrategy()
143
+
144
+ # 创建回测引擎
145
+ backtest = qka.Backtest(data, strategy)
146
+
147
+ # 运行回测
148
+ backtest.run()
149
+
150
+ # 绘制收益曲线
151
+ backtest.plot("我的策略回测结果")
152
+ ```
153
+
154
+ ### 4. QMT实盘交易
155
+
156
+ #### 启动交易服务器
157
+
158
+ ```python
159
+ from qka.brokers.server import QMTServer
160
+
161
+ # 创建交易服务器
162
+ server = QMTServer(
163
+ account_id="YOUR_ACCOUNT_ID", # 你的账户ID
164
+ mini_qmt_path="YOUR_QMT_PATH" # QMT安装路径
165
+ )
166
+
167
+ # 启动服务器(会打印token供客户端使用)
168
+ server.start()
169
+ ```
170
+
171
+ #### 使用交易客户端
172
+
173
+ ```python
174
+ from qka.brokers.client import QMTClient
175
+
176
+ # 创建交易客户端
177
+ client = QMTClient(
178
+ base_url="http://localhost:8000", # 服务器地址
179
+ token="服务器打印的token" # 访问令牌
180
+ )
181
+
182
+ # 查询账户资产
183
+ assets = client.api("query_stock_asset")
184
+ print(assets)
185
+
186
+ # 下单交易
187
+ from xtquant import xtconstant
188
+ result = client.api(
189
+ "order_stock",
190
+ stock_code='600000.SH',
191
+ order_type=xtconstant.STOCK_BUY,
192
+ order_volume=1000,
193
+ price_type=xtconstant.FIX_PRICE,
194
+ price=10.5
195
+ )
196
+ ```
197
+
198
+ ## 核心模块
199
+
200
+ ### 数据模块 (qka.Data)
201
+
202
+ - **多数据源**: 支持Akshare、QMT等数据源
203
+ - **缓存机制**: 自动缓存数据,提高访问效率
204
+ - **并发下载**: 多线程并发下载,提升数据获取速度
205
+ - **数据标准化**: 统一数据格式,便于策略开发
206
+
207
+ ### 回测模块 (qka.Backtest)
208
+
209
+ - **时间序列**: 基于时间序列的回测引擎
210
+ - **多资产支持**: 支持多股票横截面数据处理
211
+ - **交易记录**: 完整的交易记录和持仓跟踪
212
+ - **可视化**: 交互式回测结果图表
213
+
214
+ ### 策略模块 (qka.Strategy)
215
+
216
+ - **抽象基类**: 提供策略开发的标准接口
217
+ - **事件驱动**: 基于bar的事件处理机制
218
+ - **交易接口**: 内置买入卖出操作接口
219
+ - **状态管理**: 自动管理资金和持仓状态
220
+
221
+ ### 经纪商模块 (qka.brokers)
222
+
223
+ - **QMT集成**: 完整的QMT交易接口封装
224
+ - **客户端/服务器**: 支持远程交易服务
225
+ - **订单管理**: 完整的订单生命周期管理
226
+ - **错误处理**: 完善的错误处理和日志记录
227
+
228
+ ### MCP模块 (qka.mcp)
229
+
230
+ - **模型服务**: 提供模型上下文协议支持
231
+ - **数据查询**: 支持Akshare数据查询工具
232
+ - **异步处理**: 基于异步IO的高性能处理
233
+
234
+ ### 工具模块 (qka.utils)
235
+
236
+ - **日志系统**: 结构化日志记录,支持文件和控制台输出
237
+ - **颜色输出**: 带颜色的控制台输出
238
+ - **工具函数**: 各种实用工具函数
239
+
240
+ ## 高级用法
241
+
242
+ ### 自定义因子计算
243
+
244
+ ```python
245
+ import pandas as pd
246
+
247
+ def calculate_ma_factor(df):
248
+ """计算移动平均因子"""
249
+ df['ma5'] = df['close'].rolling(5).mean()
250
+ df['ma20'] = df['close'].rolling(20).mean()
251
+ return df
252
+
253
+ data = qka.Data(
254
+ symbols=['000001.SZ'],
255
+ factor=calculate_ma_factor # 应用自定义因子
256
+ )
257
+ ```
258
+
259
+ ### 批量数据处理
260
+
261
+ ```python
262
+ # 批量处理多只股票
263
+ symbols = ['000001.SZ', '600000.SH', '000002.SZ', '600036.SH']
264
+ data = qka.Data(
265
+ symbols=symbols,
266
+ pool_size=20 # 增加并发数提高下载速度
267
+ )
268
+ ```
269
+
270
+ ### 事件驱动策略
271
+
272
+ ```python
273
+ class EventDrivenStrategy(qka.Strategy):
274
+ def on_bar(self, date, get):
275
+ close_prices = get('close')
276
+ volumes = get('volume')
277
+
278
+ # 基于成交量的事件
279
+ for symbol in close_prices.index:
280
+ if volumes[symbol] > volumes.mean() * 2: # 成交量放大
281
+ self.broker.buy(symbol, close_prices[symbol], 100)
282
+ ```
283
+
284
+ ## 配置说明
285
+
286
+ ### 数据缓存配置
287
+
288
+ ```python
289
+ from pathlib import Path
290
+
291
+ data = qka.Data(
292
+ symbols=['000001.SZ'],
293
+ datadir=Path("/path/to/cache") # 自定义缓存目录
294
+ )
295
+ ```
296
+
297
+ ## 常见问题
298
+
299
+ ### Q: 如何获取股票代码?
300
+ A: 可以使用Akshare获取股票列表:
301
+ ```python
302
+ import akshare as ak
303
+ stock_list = ak.stock_info_a_code_name()
304
+ ```
305
+
306
+ ### Q: 回测时如何设置手续费?
307
+ A: 目前版本默认无手续费,可以在策略中手动计算或扩展Broker类。
308
+
309
+ ### Q: 支持哪些数据周期?
310
+ A: 目前主要支持日线数据,可根据需要扩展分钟线、周线等。
311
+
312
+ ### Q: 如何添加新的数据源?
313
+ A: 继承Data类并实现相应的数据获取方法。
314
+
315
+ ## 许可证
316
+
317
+ 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
318
+
319
+ ## 联系方式
320
+
321
+ - 项目主页: [https://github.com/zsrl/qka](https://github.com/zsrl/qka)
322
+ - 问题反馈: [GitHub Issues](https://github.com/zsrl/qka/issues)
323
+
324
+ ## 致谢
325
+
326
+ 感谢以下开源项目的支持:
327
+
328
+ - [Akshare](https://github.com/akfamily/akshare) - 丰富的数据源
329
+ - [Plotly](https://plotly.com/python/) - 交互式图表
330
+ - [FastAPI](https://fastapi.tiangolo.com/) - 高性能API框架
331
+ - [xtquant](https://github.com/ShiMiaoYS/xtquant) - QMT Python接口
332
+
333
+ ---
334
+
335
+ **注意**: 量化交易存在风险,请在充分了解风险的情况下使用本框架。作者不对使用本框架产生的任何投资损失负责。