The Wayback Machine - https://web.archive.org/web/20240103130222/https://github.com/vnpy
Skip to content
View vnpy's full-sized avatar
🎯
Focusing
🎯
Focusing

Highlights

  • Pro
Block or Report

Block or report vnpy

Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
vnpy/README.md

VeighNa - By Traders, For Traders.

💬 Want to read this in english ? Go here

VeighNa是一套基于Python的开源量化交易系统开发框架,在开源社区持续不断的贡献下一步步成长为多功能量化交易平台,自发布以来已经积累了众多来自金融机构或相关领域的用户,包括私募基金、证券公司、期货公司等。

🚀 🚀 🚀 面向专业交易员的【VeighNa Elite量化终端】已经正式发布,针对专业交易员群体在海量策略并发、智能移仓换月、算法拆单执行、多账户交易支持等方面的需求提供了完善支持。了解更详细的信息请扫描下方二维�?�关注后,点击菜单�?�的【社区交流 -> Elite会员服务】即可

在使用VeighNa进行二次开发(策略、模块等)的过程中有任何疑问,请查看VeighNa项目文档,如果�?法解决请前往官方社区论坛的【提问求助】板块寻求帮助,也欢迎在【经验分享】板块分享�?的使用心得!

针对VeighNa的金融机构用户,创建了一个专门的【VeighNa机构用户群】(QQ群号:676499931),主要分享机构应用方面相关的问题,如:银行间市场接入、资管O32系统、分布式部署等内容。请注意本群只对金融机构用户开放,�?群时请注明:姓名-机构-部门。

功能特点

  1. 多功能量化交易平台(trader),整合了多种交易接口,并针对具体策略算法和功能开发提供了简洁易用的API,用于快速构建交易员所需的量化交易应用。

  2. 覆盖国内外所拥有的下述交易品种的交易接口(gateway):

    • 国内市场

      • CTP(ctp):国内期货、期权

      • CTP Mini(mini):国内期货、期权

      • CTP证券(sopt):ETF期权

      • 飞马(femas):国内期货

      • 恒生UFT(uft):国内期货、ETF期权

      • 易盛(esunny):国内期货、黄金TD

      • 顶点飞创(sec):ETF期权

      • 顶点HTS(hts):ETF期权

      • 中泰XTP(xtp):国内证券(A股)、ETF期权

      • 华鑫奇点(tora):国内证券(A股)、ETF期权

      • 国泰君安(hft):国内证券(A股、两融)

      • 东证OST(ost):国内证券(A股)

      • 东方财富EMT(emt):国内证券(A股)

      • 飞�?(sgit):黄金TD、国内期货

      • 金仕达黄金(ksgold):黄金TD

      • 融航(rohon):期货资管

      • 杰宜斯(jees):期货资管

      • 中汇亿达(comstar):银行间市场

      • 掘金(gm):国内证券(仿真)

      • 恒生云UF(uf):国内证券(仿真)

      • TTS(tts):国内期货(仿真)

    • 海外市场

      • Interactive Brokers(ib):海外证券、期货、期权、贵金属等

      • 易盛9.0外盘(tap):海外期货

      • 直达期货(da):海外期货

    • 特殊应用

      • RQData行情(rqdata):跨市场(股票、指数、ETF、期货)实时行情

      • RPC服务(rpc):跨进程通讯接口,用于分布式架构

  3. 覆盖下述各类量化策略的交易应用(app):

    • cta_strategy:CTA策略引擎模块,在保持易用性的同时,允许用户针对CTA类策略运行过程中委托的报撤行为进行细粒度控制(降低交易滑点、实现高频策略)

    • cta_backtester:CTA策略回测模块,�?需使用Jupyter Notebook,直接使用图形界面进行策略回测分析、参数优化等相关工作

    • spread_trading:价差交易模块,支持自定义价差,实时计算价差行情和持仓,支持价差算法交易以及自动价差策略两种模式

    • option_master:期权交易模块,针对国内期权市场设计,支持多种期权定价模型、隐含波动率曲面计算、希腊值风险跟踪等功能

    • portfolio_strategy:组合策略模块,面向同时交易多合约的量化策略(Alpha、期权套利等),提供历史数据回测和实盘自动交易功能

    • algo_trading:算法交易模块,提供多种常用的智能交易算法:TWAP、Sniper、Iceberg、BestLimit等

    • script_trader:脚本策略模块,面向多�?�的类量化策略和计算任务设计,同时也可以在命令行中实现REPL指令形式的交易,不支持回测功能

    • paper_account:本地仿真模块,纯本地化实现的仿真模拟交易功能,基于交易接口获取的实时行情进行委托撮合,提供委托成交推送以及持仓记录

    • chart_wizard:K线图表模块,基于RQData数据服务(期货)或者交易接口获取历史数据,并结合Tick推送显示实时行情变化

    • portfolio_manager:交易组合管理模块,以独立的策略交易组合(子账户)为基础,提供委托成交记录管理、交易仓位自动跟踪以及每日盈亏实时统计功能

    • rpc_service:RPC服务模块,允许将某一进程启动为服务端,作为统一的行情和交易路由通道,允许多客户端同时连接,实现多进程分布式系统

    • data_manager:历史数据管理模块,通过�?�形目录查看数据库中已有的数据概况,选择任意时间段数据查看字段细节,支持CSV文件的数据导入和导出

    • data_recorder:行情记录模块,基于图形界面进行配置,�?�据需求实时录制Tick或者K线行情到数据库中,用于策略回测或者实盘初始化

    • excel_rtd:Excel RTD(Real Time Data)实时数据服务,基于pyxll模块实现在Excel中获取各类数据(行情、合约、持仓等)的实时推送更新

    • risk_manager:风险管理模块,提供包括交易流控、下单数量、活动委托、撤单总数等规则的统计和限制,有效实现前端风控功能

    • web_trader:Web服务模块,针对B-S架构需求设计,实现了提供主动函数调用(REST)和被动数据推送(Websocket)的Web服务器

  4. Python交易API接口封装(api),提供上述交易接口的底层对接实现。

    • REST Client(rest):基于协程异步IO的高性能REST API客户端,采用事件消息循环的编程模型,支持高并发实时交易请求发送

    • Websocket Client(websocket):基于协程异步IO的高性能Websocket API客户端,支持和REST Client共用事件循环并发运行

  5. 简洁易用的事件驱动引擎(event),作为事件驱动型交易程序的�?�心。

  6. 对接各类数据库的适配器接口(database):

    • SQL类

      • SQLite(sqlite):轻量级单文件数据库,�?需安装和配置数据服务程序,VeighNa的默认选项,适合入门新手用户

      • MySQL(mysql):主流的开源关系型数据库,文档资料极为丰富,且可替换其他NewSQL兼容实现(如TiDB)

      • PostgreSQL(postgresql):特性更为丰富的开源关系型数据库,支持通过扩展插件来新增功能,只推荐熟手使用

    • NoSQL类

      • DolphinDB(dolphindb):一款高性能分布式时序数据库,适用于对速度要求极高的低延时或实时性任务

      • Arctic(arctic):高性能金融时序数据库,采用了分块化储存、LZ4压缩等性能优化方案,以实现时序数据的高效读写

      • TDengine(taos):分布式、高性能、支持SQL的时序数据库,带有内建的缓存、流式计算、数据订阅等系统功能,能大幅减少�?�发和运维的复杂度

      • TimescaleDB(timescaledb):基于PostgreSQL开发的一款时序数据库,以插件化扩展的形式安装,支持自动按空间和时间对数据进行分区

      • MongoDB(mongodb):基于分布式文件储存(bson�?�式)的文档式数据库,内置的热数据内存缓存提供更快读写速度

      • InfluxDB(influxdb):针对TimeSeries Data专门设计的时序数据库,列式数据储存提供极高的读写效率和外围分析应用

      • LevelDB(leveldb):由Google推出的高性能Key/Value数据库,基于LSM算法实现进程内存储引擎,支持数十亿级别的海量数据

  7. 对接下述各类数据服务的适配器接口(datafeed):

    • 迅投�?�(xt):股票、期货、期权、基金、债券

    • 米筐RQData(rqdata):股票、期货、期权、基金、债券、黄金TD

    • 恒生UData(udata):股票、期货、期权

    • TuShare(tushare):股票、期货、期权、基金

    • 万得Wind(wind):股票、期货、基金、债券

    • 天软Tinysoft(tinysoft):股票、期货、基金、债券

    • 同花顺iFinD(ifind):股票、期货、基金、债券

    • 天勤TQSDK(tqsdk):期货

  8. 跨进程通讯�?�准组件(rpc),用于实现分布式部署的复杂交易系统。

  9. Python高性能K线图表(chart),支持大数据量图表显示以及实时数据更新功能。

  10. 社区论坛知乎专�?�,内容包括VeighNa项目的开发教程和Python在量化交易领域的应用�?�究等内容。

  11. 官方交流群262656087(QQ),管理严�?�(定期清除长期潜水的成员),入群费将捐�?给VeighNa社区基金。

注:以上关于功能特点的说明为�?�据说明文档发布时情况罗列,后续可能存在更新或调整。若功能描述同实际存在出入,欢迎通过Issue联系进行调整。

环境准备

  • 推荐使用VeighNa团队为量化交易专门打�?的Python发行版VeighNa Studio-3.9.0,集成内置了VeighNa框架以及VeighNa Station量化管理平台,�?需手动安装
  • 支持的系统版本:Windows 10以上 / Windows Server 2016以上 / Ubuntu 20.04 LTS以上
  • 支持的Python版本:Python 3.7/ 3.8 / 3.9 / 3.10 64位(推荐使用Python 3.10

安装步骤

这里下载Release发布版本,解压后运行以下命令安装:

Windows

install.bat

Ubuntu

bash install.sh

Macos

bash install_osx.sh

注意:setup.cfg中列举了VeighNa框架安装所需的依赖库,requirements.txt中给出了这些依赖库的推荐安装版本。

使用指南

  1. SimNow注册CTP仿真账号,并在该页面获取经纪商代�?�以及交易行情服务器地址。

  2. VeighNa社区论坛注册获得VeighNa Station账号密�?�(论坛账号密�?�即是)

  3. 启动VeighNa Station(安装VeighNa Studio后会在桌面自动创建快捷方式),输入上一步的账号密�?�登录

  4. 点击底部的VeighNa Trader按钮,开始�?的交易!!!

注意:

  • 在VeighNa Trader的运行过程中请勿关闭VeighNa Station(会自动退出)

脚本运行

除了基于VeighNa Station的图形化启动方式外,也可以在任意目录下创建run.py,写入以下示例代�?�:

from vnpy.event import EventEngine
from vnpy.trader.engine import MainEngine
from vnpy.trader.ui import MainWindow, create_qapp

from vnpy_ctp import CtpGateway
from vnpy_ctastrategy import CtaStrategyApp
from vnpy_ctabacktester import CtaBacktesterApp


def main():
    """Start VeighNa Trader"""
    qapp = create_qapp()

    event_engine = EventEngine()
    main_engine = MainEngine(event_engine)
    
    main_engine.add_gateway(CtpGateway)
    main_engine.add_app(CtaStrategyApp)
    main_engine.add_app(CtaBacktesterApp)

    main_window = MainWindow(main_engine, event_engine)
    main_window.showMaximized()

    qapp.exec()


if __name__ == "__main__":
    main()

在该目录下打开CMD(按住Shift->点击�?�?�右键->在此处打开命令窗口/PowerShell)后运行下列命令启动VeighNa Trader:

python run.py

贡献代�?�

VeighNa使用Github托管其源代�?�,如果希望贡献代�?�请使用github的PR(Pull Request)的流程:

  1. 创建 Issue - 对于较大的改动(如新功能,大型重构等)建议先开issue讨论一下,较小的improvement(如文档改进,bugfix等)直接发PR即可

  2. Fork VeighNa - 点击右上角Fork按钮

  3. Clone�?自己的fork: git clone https://github.com/$userid/vnpy.git

    • 如果�?的fork已经过时,需要手动sync:同步方法
  4. dev创建�?自己的feature branch: git checkout -b $my_feature_branch dev

  5. 在$my_feature_branch上修改并将修改push到�?的fork上

  6. 创建从�?的fork的$my_feature_branch分支到主项目的dev分支的[Pull Request] - 在此点击compare across forks,选择需要的fork和branch创建PR

  7. 等待review, 需要继续改进,或者被Merge!

在提交代�?�的时候,请遵守以下规则,以提高代�?�质量:

  • 使用flake8检查�?的代�?�,确保没有error和warning。在项目�?�目录下运行flake8即可。

其他内容

版权说明

MIT

Pinned

  1. vnpy vnpy Public

    基于Python的开源量化交易平台开发框架

    Python 22.5k 8.3k

2,026 contributions in the last year

3 contributions on January 1st.No contributions on January 8th.5 contributions on January 15th.No contributions on January 22nd.No contributions on January 29th.1 contribution on February 5th.12 contributions on February 12th.2 contributions on February 19th.No contributions on February 26th.2 contributions on March 5th.1 contribution on March 12th.5 contributions on March 19th.3 contributions on March 26th.No contributions on April 2nd.No contributions on April 9th.No contributions on April 16th.30 contributions on April 23rd.No contributions on April 30th.5 contributions on May 7th.1 contribution on May 14th.2 contributions on May 21st.2 contributions on May 28th.9 contributions on June 4th.4 contributions on June 11th.3 contributions on June 18th.6 contributions on June 25th.No contributions on July 2nd.29 contributions on July 9th.10 contributions on July 16th.No contributions on July 23rd.No contributions on July 30th.6 contributions on August 6th.No contributions on August 13th.No contributions on August 20th.1 contribution on August 27th.6 contributions on September 3rd.No contributions on September 10th.No contributions on September 17th.7 contributions on September 24th.3 contributions on October 1st.No contributions on October 8th.No contributions on October 15th.5 contributions on October 22nd.No contributions on October 29th.No contributions on November 5th.No contributions on November 12th.No contributions on November 19th.No contributions on November 26th.No contributions on December 3rd.1 contribution on December 10th.2 contributions on December 17th.1 contribution on December 24th.No contributions on December 31st.1 contribution on January 2nd.5 contributions on January 9th.No contributions on January 16th.7 contributions on January 23rd.No contributions on January 30th.2 contributions on February 6th.19 contributions on February 13th.8 contributions on February 20th.9 contributions on February 27th.8 contributions on March 6th.2 contributions on March 13th.3 contributions on March 20th.8 contributions on March 27th.7 contributions on April 3rd.6 contributions on April 10th.8 contributions on April 17th.8 contributions on April 24th.9 contributions on May 1st.12 contributions on May 8th.4 contributions on May 15th.10 contributions on May 22nd.2 contributions on May 29th.14 contributions on June 5th.7 contributions on June 12th.19 contributions on June 19th.3 contributions on June 26th.6 contributions on July 3rd.22 contributions on July 10th.7 contributions on July 17th.No contributions on July 24th.4 contributions on July 31st.3 contributions on August 7th.6 contributions on August 14th.9 contributions on August 21st.9 contributions on August 28th.9 contributions on September 4th.7 contributions on September 11th.1 contribution on September 18th.19 contributions on September 25th.7 contributions on October 2nd.4 contributions on October 9th.1 contribution on October 16th.3 contributions on October 23rd.No contributions on October 30th.7 contributions on November 6th.9 contributions on November 13th.6 contributions on November 20th.3 contributions on November 27th.No contributions on December 4th.15 contributions on December 11th.2 contributions on December 18th.7 contributions on December 25th.No contributions on January 1st.7 contributions on January 3rd.4 contributions on January 10th.4 contributions on January 17th.1 contribution on January 24th.2 contributions on January 31st.3 contributions on February 7th.8 contributions on February 14th.2 contributions on February 21st.7 contributions on February 28th.10 contributions on March 7th.7 contributions on March 14th.2 contributions on March 21st.9 contributions on March 28th.13 contributions on April 4th.8 contributions on April 11th.8 contributions on April 18th.8 contributions on April 25th.6 contributions on May 2nd.31 contributions on May 9th.No contributions on May 16th.5 contributions on May 23rd.11 contributions on May 30th.9 contributions on June 6th.9 contributions on June 13th.12 contributions on June 20th.7 contributions on June 27th.15 contributions on July 4th.18 contributions on July 11th.6 contributions on July 18th.4 contributions on July 25th.No contributions on August 1st.No contributions on August 8th.8 contributions on August 15th.3 contributions on August 22nd.3 contributions on August 29th.14 contributions on September 5th.19 contributions on September 12th.4 contributions on September 19th.No contributions on September 26th.2 contributions on October 3rd.1 contribution on October 10th.8 contributions on October 17th.6 contributions on October 24th.2 contributions on October 31st.2 contributions on November 7th.No contributions on November 14th.19 contributions on November 21st.9 contributions on November 28th.12 contributions on December 5th.16 contributions on December 12th.7 contributions on December 19th.1 contribution on December 26th.2 contributions on January 2nd.7 contributions on January 4th.2 contributions on January 11th.5 contributions on January 18th.No contributions on January 25th.3 contributions on February 1st.4 contributions on February 8th.23 contributions on February 15th.5 contributions on February 22nd.7 contributions on March 1st.17 contributions on March 8th.13 contributions on March 15th.29 contributions on March 22nd.3 contributions on March 29th.9 contributions on April 5th.4 contributions on April 12th.No contributions on April 19th.2 contributions on April 26th.4 contributions on May 3rd.4 contributions on May 10th.4 contributions on May 17th.6 contributions on May 24th.2 contributions on May 31st.21 contributions on June 7th.17 contributions on June 14th.1 contribution on June 21st.2 contributions on June 28th.6 contributions on July 5th.8 contributions on July 12th.18 contributions on July 19th.5 contributions on July 26th.2 contributions on August 2nd.No contributions on August 9th.No contributions on August 16th.1 contribution on August 23rd.2 contributions on August 30th.9 contributions on September 6th.18 contributions on September 13th.1 contribution on September 20th.16 contributions on September 27th.No contributions on October 4th.5 contributions on October 11th.2 contributions on October 18th.11 contributions on October 25th.4 contributions on November 1st.6 contributions on November 8th.No contributions on November 15th.7 contributions on November 22nd.1 contribution on November 29th.No contributions on December 6th.No contributions on December 13th.2 contributions on December 20th.9 contributions on December 27th.3 contributions on January 3rd.4 contributions on January 5th.8 contributions on January 12th.6 contributions on January 19th.No contributions on January 26th.7 contributions on February 2nd.6 contributions on February 9th.38 contributions on February 16th.4 contributions on February 23rd.17 contributions on March 2nd.9 contributions on March 9th.No contributions on March 16th.7 contributions on March 23rd.2 contributions on March 30th.9 contributions on April 6th.6 contributions on April 13th.7 contributions on April 20th.5 contributions on April 27th.22 contributions on May 4th.4 contributions on May 11th.12 contributions on May 18th.7 contributions on May 25th.6 contributions on June 1st.10 contributions on June 8th.10 contributions on June 15th.1 contribution on June 22nd.16 contributions on June 29th.7 contributions on July 6th.No contributions on July 13th.8 contributions on July 20th.10 contributions on July 27th.3 contributions on August 3rd.No contributions on August 10th.No contributions on August 17th.4 contributions on August 24th.6 contributions on August 31st.9 contributions on September 7th.14 contributions on September 14th.No contributions on September 21st.2 contributions on September 28th.3 contributions on October 5th.4 contributions on October 12th.10 contributions on October 19th.11 contributions on October 26th.8 contributions on November 2nd.3 contributions on November 9th.4 contributions on November 16th.7 contributions on November 23rd.No contributions on November 30th.19 contributions on December 7th.No contributions on December 14th.3 contributions on December 21st.No contributions on December 28th.11 contributions on January 6th.No contributions on January 13th.No contributions on January 20th.No contributions on January 27th.9 contributions on February 3rd.3 contributions on February 10th.6 contributions on February 17th.3 contributions on February 24th.23 contributions on March 3rd.13 contributions on March 10th.2 contributions on March 17th.17 contributions on March 24th.1 contribution on March 31st.13 contributions on April 7th.13 contributions on April 14th.10 contributions on April 21st.2 contributions on April 28th.17 contributions on May 5th.12 contributions on May 12th.5 contributions on May 19th.7 contributions on May 26th.1 contribution on June 2nd.5 contributions on June 9th.8 contributions on June 16th.17 contributions on June 23rd.11 contributions on June 30th.7 contributions on July 7th.7 contributions on July 14th.4 contributions on July 21st.1 contribution on July 28th.No contributions on August 4th.No contributions on August 11th.No contributions on August 18th.1 contribution on August 25th.2 contributions on September 1st.18 contributions on September 8th.3 contributions on September 15th.1 contribution on September 22nd.10 contributions on September 29th.No contributions on October 6th.3 contributions on October 13th.11 contributions on October 20th.1 contribution on October 27th.17 contributions on November 3rd.8 contributions on November 10th.6 contributions on November 17th.3 contributions on November 24th.No contributions on December 1st.20 contributions on December 8th.1 contribution on December 15th.8 contributions on December 22nd.No contributions on December 29th.3 contributions on January 7th.No contributions on January 14th.No contributions on January 21st.No contributions on January 28th.5 contributions on February 4th.5 contributions on February 11th.1 contribution on February 18th.4 contributions on February 25th.1 contribution on March 4th.5 contributions on March 11th.1 contribution on March 18th.No contributions on March 25th.1 contribution on April 1st.4 contributions on April 8th.No contributions on April 15th.2 contributions on April 22nd.3 contributions on April 29th.15 contributions on May 6th.No contributions on May 13th.No contributions on May 20th.No contributions on May 27th.No contributions on June 3rd.No contributions on June 10th.No contributions on June 17th.3 contributions on June 24th.No contributions on July 1st.22 contributions on July 8th.2 contributions on July 15th.1 contribution on July 22nd.No contributions on July 29th.No contributions on August 5th.No contributions on August 12th.No contributions on August 19th.3 contributions on August 26th.1 contribution on September 2nd.No contributions on September 9th.6 contributions on September 16th.5 contributions on September 23rd.3 contributions on September 30th.2 contributions on October 7th.No contributions on October 14th.No contributions on October 21st.No contributions on October 28th.No contributions on November 4th.No contributions on November 11th.No contributions on November 18th.No contributions on November 25th.1 contribution on December 2nd.9 contributions on December 9th.No contributions on December 16th.No contributions on December 23rd.1 contribution on December 30th.
Contribution Graph
Day of Week January February March April May June July August September October November December
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Less
No contributions.
Low contributions.
Medium-low contributions.
Medium-high contributions.
High contributions.
More

Contribution activity

January 2024

5 contributions in private repositories Jan 2 – Jan 3