| Crates.io | quant1x |
| lib.rs | quant1x |
| version | 0.7.5 |
| created_at | 2025-09-27 11:39:31.804904+00 |
| updated_at | 2025-12-05 02:52:48.327844+00 |
| description | Cross-language standard library for quantitative trading |
| homepage | https://github.com/quant1x/quant1x |
| repository | https://gitee.com/quant1x/quant1x |
| max_upload_size | |
| id | 1857217 |
| size | 14,609,070 |
Quant1X 是一个多语言量化交易框架,支持 C++、Go、Rust、Python,提供完整的量化交易解决方案,包括数据处理、策略开发、回测引擎、实时交易等功能。
| 语言 | 版本要求 | 推荐版本 |
|---|---|---|
| Python | 3.12+ | 3.12.x |
| Go | 1.25+ | 1.25.x |
| Rust | 1.88+ | 1.90+ (2021) |
| C++ | C++20 | GCC 13+/Clang 17+/MSVC 14.3+ |
| python | golang | rust | c++ |
|---|---|---|---|
| 3.12.x | 1.25.x | 1.90+/2021 | gcc13+/clang17+/msvc14.3+ |
安装brew时需要注意避免使用root权限
cp examples/quant1x.yaml ~/.quant1x/quant1x.yaml
cp examples/quant1x.yaml ~/.q1x/quant1x.yaml
cp examples/quant1x.yaml ~/.q1x-rust/quant1x.yaml
python的运行环境可能存在多个版本冲突的问题,那么怎么来解决多版本的共存的问题呢?使用pyenv。
brew install pyenv
pyenv versions
我的电脑返回以下版本信息
system
3.8.16
* 3.12.9 (set by /Users/${USERNAME}/.pyenv/version)
pyenv install -l
pyenv install 3.12.9
安装python完成之后, python类库管理工具pip已经默认安装完成了
| 工具 | 功能 |
|---|---|
| pip | 类似maven、gradle、go mod的类库管理工具 |
| pip-autoremove | 自动删除类库所有依赖库 |
| pipreqs | 项目/类库交叉依赖检测 |
windows
cd ~\AppData\Roaming\pip
notepad.exe pip.ini
*nix
cd ~/.pip
vim pip.conf
输入以下内容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
python环境中依赖管理的配置文件为requirements.txt,类似java的maven pom.xml、golang的go.mod。
pip install -r requirements.txt
pip freeze > requirements.txt
pip install pipreqs
pipreqs ./ --encoding utf8
pip install --upgrade setuptools wheel twine
python setup.py sdist bdist_wheel
twine upload --repository testpypi dist/*
twine upload dist/*
import matplotlib
matplotlib.matplotlib_fname() #输出matplotlib包所在的配置文件的路径
我选择了SimHei中文字体, 复制到fonts/ttf/目录下
cp -r /Users/${USERNAME}/Library/Fonts/SimHei.ttf fonts/ttf/
cd ~/.matplotlib
rm -rf *
环境设定
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPRIVATE=gitee.com
# 安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 更新到最新版本
rustup update
q1x 二进制本仓库在 Cargo.toml 中声明了一个名为 q1x 的可执行二进制(路径为 main.rs)。下面是构建与常见运行示例:
cargo build --bin q1x
cargo build --release --bin q1x
# 打印程序帮助(包含子命令和选项)
cargo run --bin q1x -- --help
main.rs 中使用的 clap 定义):# 管理服务(install/uninstall/start/stop/status/run)
cargo run --bin q1x -- service install
cargo run --bin q1x -- service start
# 更新缓存数据(calendar / servers / all / base / features)
cargo run --bin q1x -- update --all
cargo run --bin q1x -- update --calendar
你也可以直接运行已构建的二进制查看实际帮助文本,例如:
# Debug 二进制
.\target\debug\q1x.exe --help
# Release 二进制
.\target\release\q1x.exe --help
下面是我在本地运行 target/release/q1x.exe --help 捕获到的输出(供参考):
quant1x - Rust edition
--------------------------------------------------------------------------------
Version : 0.6.10
Author : Quant1X Team
--------------------------------------------------------------------------------
Usage: q1x.exe [OPTIONS] [COMMAND]
Commands:
service Manage the service.
update Update cached data (base / features)
help Print this message or the help of the given subcommand(s)
Options:
--version
Print build version information and exit
--verbose
显示日志信息到终端
--debug
打开日志的调试模式
-h, --help
Print help (see a summary with '-h')
说明与注意事项:
q1x 二进制是一个可与库(crate)协同工作的前端:它会尝试调用库中暴露的初始化与子命令钩子(如 quant1x::global_init, quant1x::datasets_init, quant1x::engine_daemon 等)。如果你直接从源码运行,确保启用了需要的 feature 或在编译时链接到库中实现这些函数的 crate。service 子命令与提升参数(--pipe, --elevated-out, --elevated-pipe)交互以支持以服务/守护进程模式运行。具体行为由 engine::daemon 的实现决定。--release 构建并根据目标平台交叉编译或在对应平台上构建以避免 -march/native 引入不可移植的指令集。如果需要,我可以:
q1x 添加示例配置和 systemd/Windows service 安装脚本。engine::daemon 的实现)。本项目的 C/C++ 代码以 C++20 为目标,强烈建议在开发/构建阶段使用较新的编译器和现代构建工具以获得最佳性能与可维护性。
推荐工具链与版本
常用依赖(示例)
Linux/macOS 快速安装(示例)
Ubuntu / Debian:
macOS (Homebrew):
Windows(Visual Studio)
-DCMAKE_TOOLCHAIN_FILE=<vcpkg-root>/scripts/buildsystems/vcpkg.cmake。构建示例(以仓库根目录为例)
使用 Ninja + Clang/GCC(跨平台推荐):
使用 Visual Studio(Windows):
建议的编译选项(可在 CMakeLists 或构建命令中添加)
关于性能与编译器选择(说明)
调试与分析工具
依赖管理(vcpkg 简短示例)
克隆并引导 vcpkg:
git clone https://github.com/microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh # Linux/macOS
.\vcpkg\bootstrap-vcpkg.bat # Windows (PowerShell/CMD)
在 CMake 调用中添加 toolchain 文件:
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake ..
平台特定注意事项
x64-windows)来安装二进制依赖。ubuntu:22.04)。如果你希望我为项目添加一个方便的 CMake 构建示例(例如 top-level build 脚本和 CI job 示例),我可以继续创建并把它加入仓库。
附加:C++ 具体构建与测试示例
依赖安装(protobuf/其他)示例:
protobuf 推荐使用 3.21.11(高版本可能依赖 abseil,引入额外复杂性):
# 下载并解压源码
wget https://gh-proxy.com/github.com/protocolbuffers/protobuf/releases/download/v21.11/protobuf-cpp-3.21.11.zip
unzip protobuf-cpp-3.21.11.zip && cd protobuf-3.21.11
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=$HOME/runtime -Dprotobuf_BUILD_TESTS=OFF -G "Unix Makefiles" ../
make -j$(nproc) && make install
Windows (MSVC) 编译示例:
mkdir build; cd build
cmake -DCMAKE_INSTALL_PREFIX=d:/runtime -G "Visual Studio 17 2022" -A x64 ..
cmake --build . --config Release
其它依赖安装(vcpkg 举例):
vcpkg install yaml-cpp zlib asio xtensor mimalloc spdlog fmt duktape benchmark catch2 flatbuffers capnproto
项目快速编译(Debug 示例):
cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -S . -B cmake-build-debug
cmake --build cmake-build-debug --target q1x -j 18
安装主程序示例:
ninja -C cmake-build-debug install
运行测试(ctest):
ctest --test-dir cmake-build-debug --output-on-failure
运行示例程序:
./cmake-build-debug/bin/q1x --help
欢迎贡献代码!请遵循以下步骤:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)本项目采用 Apache 2.0 许可证 - 查看 LICENSE 文件了解详情。
注意: 本项目仅用于学习和研究目的,不构成投资建议。在实际交易前,请充分了解风险并咨询专业人士。