{"id":41701550,"url":"https://github.com/sric0880/awesome-livetrading-backtest-libraries","last_synced_at":"2026-01-24T21:00:13.244Z","repository":{"id":255316453,"uuid":"849201098","full_name":"sric0880/awesome-livetrading-backtest-libraries","owner":"sric0880","description":"对GitHub上最靓的回测和实盘交易系统一个稍微详细的描述和分析. 持续更新中... more detailed description of the popular and awesome backtesting and livetrading system in github.","archived":false,"fork":false,"pushed_at":"2024-11-30T06:02:46.000Z","size":8,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-30T07:19:48.174Z","etag":null,"topics":["backtest","backtesting","backtesting-engine","bt","livetrade","livetrading","online-trading-tools","quantitative-finance","systematic-trading"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sric0880.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-29T06:52:46.000Z","updated_at":"2024-11-30T06:02:50.000Z","dependencies_parsed_at":"2024-11-30T07:19:49.219Z","dependency_job_id":"c723a01e-5997-41aa-84a3-bab1737d49ee","html_url":"https://github.com/sric0880/awesome-livetrading-backtest-libraries","commit_stats":null,"previous_names":["sric0880/awesome-livetrading-backtest-libraries"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sric0880/awesome-livetrading-backtest-libraries","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sric0880%2Fawesome-livetrading-backtest-libraries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sric0880%2Fawesome-livetrading-backtest-libraries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sric0880%2Fawesome-livetrading-backtest-libraries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sric0880%2Fawesome-livetrading-backtest-libraries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sric0880","download_url":"https://codeload.github.com/sric0880/awesome-livetrading-backtest-libraries/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sric0880%2Fawesome-livetrading-backtest-libraries/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28736798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T19:23:36.361Z","status":"ssl_error","status_checked_at":"2026-01-24T19:23:28.966Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backtest","backtesting","backtesting-engine","bt","livetrade","livetrading","online-trading-tools","quantitative-finance","systematic-trading"],"created_at":"2026-01-24T21:00:11.706Z","updated_at":"2026-01-24T21:00:13.216Z","avatar_url":"https://github.com/sric0880.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# 开源交易系统说明\n\n# Backtesting \u0026 Live Trading\n\n## backtrader\n\nhttps://github.com/backtrader/backtrader \n\n**【Star 13.9k】【完成度高】【架构完整】【复杂策略】【强烈推荐】【event-driven】**\n\n自己看代码去，值得学习。因为通用性强，支持特性多，速度就一般般，尤其是当数据特别大的时候。虽然支持非常复杂的策略，但还是需要修改底层源码。同样支持实盘，用实盘做期货和数字货币毫无压力。\n\n## aat\n\nhttps://github.com/AsyncAlgoTrading/aat\n\n**【Star 652】【很多TODO】【架构基本完整】【可借鉴】【event-driven】**\n\n- `asyncio` 框架\n- 将主要的结构体用`C++`实现，通过`pybind11`绑定，主要结构有order, trade, position, order book,  instrument, account。逻辑实现还是在`Python`\n- 本地维护一个订单薄【应该是行情系统做的事】\n- Manager+事件分发架构。对于任何事件，依次执行`PortfolioManager.onXXX(event)`, `RiskManager.onXXX(event)`, `OrderManager.onXXX(event)`\n- PortfolioManager：和投资组合优化无关【应该叫PositionManager，头寸管理器】\n- RiskManager：TODO\n- Exchange：继承MarketData（市场行情数据）和OrderEntry（下单）两个模块。已经实现\n    - 【实盘】coinbase接口\n    - 【实盘】IB 接口\n    - 【实盘，美股市场】IEX Cloud https://iexcloud.io/\n    - 【回测】csv本地数据接口\n    - 【模拟】synthetic 合成市场，模拟订单薄\n- 整个交易系统靠Exchange.MarketData.tick(trade)驱动，这里的trade表示市场的成交，用来更新本地的订单薄，根据订单薄来下单【高频】【不支持K线驱动】\n\n\n## QUANTAXIS\n\nhttps://github.com/yutiansut/QUANTAXIS\n\n**【Star 8.2k】【完成度不高】【简单策略】【event-driven】**\n\n主要思想：将数据流拆分成微服务，用消息列队全部串起来，下单也做成服务。\n\nPython版本代码质量不高，长期未更新。数据用MongoDB、clickhouse保存。订单、持仓、仓位管理都在文件`QifiAccount.py` 。账户运行时数据，需要跟数据库做同步【增加了不一致的可能性】。\n\n只能用于国内A股和期货。\n\nwebsocket用来远程控制、设置定时任务和查询收益统计。\n\n策略逻辑都在QAStrategy中，实现各种回调函数on_xxx_bar。\n\n消息队列用于实盘，订阅数据、下单。订单列队由第三方服务器[天勤量化 open-trade-gateway](https://github.com/shinnytech/open-trade-gateway)来接受，数据列队由[QUANTAXIS_RealtimeCollector](https://github.com/yutiansut/QUANTAXIS_RealtimeCollector)来分发。【本人觉得完全没必要用消息列队，反而增加了延迟】，期货数据接口来自[ctpbee](https://github.com/ctpbee/ctpbee)，A股没有写。\n\n还有一个大问题，他订单只要发送到消息列队，就默认一定全部成交，但实际可能会失败【导致数据不一致】。\n\n## VNPY\n\nhttps://github.com/vnpy/vnpy\n\n**【Star 25.6k】【完成度高】【架构完整】【复杂策略】【强烈推荐】【event-driven】**\n\n优点：接口非常丰富。官方文档非常详细，一直在维护中。虽然官方分了很多的模块，但是大致可以分为几类：\n\n- 交易接口类（gateway/api）：丰富\n- 数据接口类（database/datafeed）：丰富\n- RPC：交易接口、数据接口都可以包装成服务，远程调用（或者再封装成HTTP接口，使用FastAPI Restful，或者封装成websocket），RPC使用的是zmq（ZeroMQ）。\n    - 服务器：[vnpy_webtrader](https://github.com/vnpy/vnpy_webtrader)\n    - 客户端：[vnpy_rest](https://github.com/vnpy/vnpy_rest)，[vnpy_websocket](https://github.com/vnpy/vnpy_websocket)\n- UI界面（chart/studio）\n- 策略类（app）：很多示例【包括实盘和回测】\n- 管理类（engine）：\n    - OmsEngine【核心】：虽然它叫订单管理系统，但是集所有功能于一身，它管理着所有的订单、成交、持仓、账户信息、当前价格、合约、盘口。不管跑多少个策略，策略下的单，都在这个系统里面。\n    - [PortfolioEngine](https://github.com/vnpy/vnpy_portfoliomanager) 计算持仓盈亏的\n    - RiskEngine：风控。只提供最基本的一些风控。在下单之前，做一系列检查：\n        - 单笔委托数量超过最大设定值\n        - 今日成交量超过最大设定值\n        - 今日撤单量超过最大设定值\n        - 每n秒最大下单量\n        - 每n秒最大撤单量\n        - 在途订单量超过最大设定值\n- 回测类（BacktesterEngine）：包括参数优化optimization。重新写了一套管理订单、成交、持仓、盈亏的逻辑，和实盘代码是完全分开的。\n\n缺点：一个模块就是一个project，导致模块之间的有很多重复代码，维护起来就是灾难性的，尤其是策略类的模块，看似拆分很细扩展性强，实则效率低下。比如他每种类型的策略的回测，都要重写BacktestingEngine.py，然而其中大部分代码都是一样的。这种不同策略分不同模块的做法，实际上是一种偷懒行为，新建新类型的策略，只要复制粘贴就行。\n\n应该一个模块一个Python文件，然后全部放在一个project里面，再把重复代码提炼出来。策略和回测逻辑，是可以抽象出来很多公共的底层逻辑的。其实回测和实盘之间都有很多共同的逻辑可以通用，这一点上[backtrader](https://github.com/backtrader/backtrader) 做的可以。\n\n# Live Trading Only\n\n## stock\n\nhttps://github.com/myhhub/stock\n\n**【A股】【schedule-driven】**\n\n- `cron`定时任务拉取东财、同花顺网站数据，做了一套数据展示的网站。\n- 交易引擎（改的 [easyquant](https://github.com/shidenggui/easyquant) ）就是简单的定时任务（开盘、收盘、间隔半分钟/1分钟/5分钟…触发一次），交易接口使用 [easytrader](https://github.com/shidenggui/easytrader)。\n\n## easytrader\n\nhttps://github.com/shidenggui/easytrader\n\n**【A股】**\n\n- 使用 [pywinauto](https://github.com/pywinauto/pywinauto) 对下单软件GUI进行识别和控制，实现无人监控自动下单。\n- 能复制`joinquant`, `ricequant`, `雪球` 的模拟盘操作到实盘。\n\n## easyquant\n\nhttps://github.com/shidenggui/easyquant\n\n**【A股】【event-driven】【schedule-driven】**\n\n- 交易引擎简单的定时任务+实时行情回调，交易接口使用 [easytrader](https://github.com/shidenggui/easytrader)，行情数接口使用[easyquotation](https://github.com/shidenggui/easyquotation)。\n\n# Backtesting Only\n\n## Backtesting.py\n\n**【Star 5.3k】【值得借鉴】【轻量级】【复杂策略】【schedule-driven】**\n\nhttps://kernc.github.io/backtesting.py/\n\n- 使用[bokeh](https://bokeh.org/) 绘图\n- 主要类：`_Data`、`_Indicator`、`Strategy`、`Order`、`Position`、`Trade`、`_Broker`、`Backtest`。只支持单一的Data。\n- 指标在Init的时候，提前算好了\n- 支持止盈止损，支持追踪止损\n- 架构类似[backtrader](#backtrader)\n- 指标优化，使用`scikit-optimize`库\n\n## bt\n\nhttps://github.com/pmorissette/bt\n\n**【Star 2.1k】【值得借鉴】【复杂策略】【轻量级】【schedule-driven】**\n\n- 特色：algos中所有交易都**模块化**【算法交易】。策略和证券分别用节点`Node`表示，组成树状图，每个策略维持一个algos列表，运行策略即运行该策略上的algos列表，以及递归运行其子节点上的algos列表。algos 模块有：\n    - 时间间隔任务、定时任务\n    - 选股和权重\n    - 仓位再平衡\n    - 计算风险，用于展示\n- **只支持一个价格close**\n- 可实现：买入持有每月调仓、风险平价、固定收入、统计套利、Predicted Tracking Error Rebalance、父子策略、目标波动率、技术指标等\n- 非常丰富的测试用例，单元测试和基准测试bench\n\n## vectorbt\n\nhttps://github.com/polakowo/vectorbt\n\n**【Star 4.1k】【轻量级】【简单策略】【vectorized】**\n\n- 数据提前加载，开平仓信号提前计算好，支持多参数（参数优化 ），然后批量回测。\n- 各种数据、数组的处理函数，指标的计算，全部使用numba加速。\n- `generic.splitters`模块机器学习数据集划分算法：`RangeSplitter`, `RollingSplitter`, `ExpandingSplitter`。\n- `labels`模块：可以给训练集打标签。\n- `portfolio`模块：提前计算好仓位，订单、信号都会影响到仓位，都要提前算好\n- `records`模块：稀疏数组\n- `signals`模块：生成开仓和平仓信号\n\n## zipline-reloaded\n\nhttps://github.com/stefan-jansen/zipline-reloaded\n\n**【Star 1.2k】【完成度高】【架构完整】【强烈推荐】【schedule-driven】**\n\n代码质量很高，文档和注释非常完整。只支持Daily和Minute。文档说也支持实盘，但是并没有实盘的接口和案例。\n\n核心模块三大类：\n- 数据类，底层是用数据库和bcolz，数据格式：按fields分开，比如一个close数据是二维的ndarray，行是时间，列是assets\n- Pipeline数据处理流程类，将数据计算分为多个节点（Term）组成单向无环图，支持各种因子、指标、算法等计算\n- 交易引擎类，使用bar来驱动运行\n\n## qlib\n\nhttps://github.com/microsoft/qlib\n\n**【Star 15.1k】【Microsoft出品】【AI】【重量级】【强烈推荐】【schedule-driven】**\n\nAI助力的投研平台，从最底层到上层依次讲解：\n\n- Infrastructure layer 基础设施层，包含：数据服务器，模型训练器，模型存储和管理器。\n    - 数据服务器\n        - 整个流程支持配置化\n        - 原始数据来源各种网站，提供数据HTTP下载的各种网站，数据以二进制文件形式存储在本地，供上层数据分析。qlib对每一列单独存储，本质是调用`numpy.array.tofile()` 接口保存为文件。可以参考`scripts/dump_bin.py`\n        - 额外还有一个项目[qlib-server](https://github.com/microsoft/qlib-server)，远程提供数据和缓存。使用 [Flask-SocketIO](https://flask-socketio.readthedocs.io/) 框架。\n        - XXXProvider：实现获取数据的接口。主要有两大类，Client和Local，Client是连接远程qlib-server的接口，Local是从本地文件加载的接口\n        - DataLoader：从provider中 或者 文件中 获取数据。数据主要有 **日历**，**instruments（证券信息）**，**features（特征，多列字段组合为一个特征）**。**丰富的查询接口，支持条件过滤，支持formulaic表达式（`rule_expression`）**\n        - DataHandler：数据预处理，由处理器`processors`组成\n        - Dataset：是已经处理好，可供机器学习或者推理的数据\n        - 有缓存机制，将中间结果缓存在本地文件，或者 内存。Redis用来提供分布式锁。\n    - 模型训练器\n        - 训练任务管理器，支持多进程，任务池\n        - 每次训练的结果保存为`record`，所有`record`会记录下来，用来分析模型的性能，进行调参。所有record通过`ExperimentManager`进行管理\n    - 预置了非常多机器学习模型\n- Learning Framework layer 机器学习框架 **PyTorch**\n    - 有监督学习和强化学习\n- Workflow layer 从市场数据→推理(预测)→构建投资组合(投资决策)→订单执行(回测)\n    - 回测**【复杂策略】【schedule-driven】**\n        - trade_strategy，做出投资决策`BaseTradeDecision`，买或卖。策略可以包含一个**投资组合优化器【仓位管理】，比如说指数增强策略。**\n        - trade_executor，执行决策。支持嵌套执行器和嵌套策略。比如说日内策略，外层是日策略，决定是否开仓，开仓哪些品种，内层是1分钟策略，决定每分钟买入或卖出量（TWAP）。基于预测模型的策略也叫`SignalStrategy`。内嵌策略可以理解为【**算法交易】**。\n- Interface layer 分析报告\n    - 回测结果\n        - `PortfolioMetrics` 总资产、现金、收益率、持仓市值、换手率等。可以绘制出`report_graph`、`risk_analysis_graph`等图表\n        - `Indicator` 算法交易过程中记录的一些指标，比如完成率`ffr`，基准价格`base_price`，超出基准价百分比`price advantage`等\n    - 风险模型：`RiskModel`、`POETCovEstimator`、`ShrinkCovEstimator`、`StructuredCovEstimator`\n    - 预测模型分析报告\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsric0880%2Fawesome-livetrading-backtest-libraries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsric0880%2Fawesome-livetrading-backtest-libraries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsric0880%2Fawesome-livetrading-backtest-libraries/lists"}