Skip to content

Commit

Permalink
Merge pull request vnpy#1037 from vnpy/dev
Browse files Browse the repository at this point in the history
v1.9.0发布前最后一次更新
  • Loading branch information
vnpy authored Aug 12, 2018
2 parents db1432f + cd1d939 commit 9e9d2dc
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 99 deletions.
99 changes: 55 additions & 44 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,101 @@

The vn.py project is an open-source quantitative trading framework that is developed by traders, for traders. The project is mainly written in Python and uses C++ for low-layer and performance sensitive infrastructure.

Using the vn.py project, institutional investors and professional traders, such as hedge funds, prop trading firms and investment banks, can easily develop complex trading strategies with the Event Engine Strategy Module, and automatically route their orders to the most desired destinations, including equity, commodity, forex and many other financial markets.
Using the vn.py project, institutional investors and professional traders, such as hedge funds, prop trading firms and investment banks, can easily develop complex trading strategies with the Event Engine Strategy Module, and automatically route their orders to the most desired destinations, including equity, commodity, forex, cryptocurrency and many other financial markets.

---
### Quick Start

### Project Structure
1. Prepare a computer with Windows 7/8/10/Server 2008 (64-bit) installed.

1. A large number of Broker and Market Data APIs, all in Python (vn.api):
2. Install [Anaconda 5.2.0](http://www.continuum.io/downloads), please make sure you download **Python 2.7 (32-bit)**.

**International Financial Markets**
3. Install [MongoDB](https://www.mongodb.org/downloads#production), please register MongoDB as Windows Service.

- Interactive Brokers(vn.ib)

- Shanghai Zhida Futures(vn.shzd)
4. Install [Visual C++ Redistributable Packages for VS2013 (32-bit)](https://www.microsoft.com/en-gb/download/details.aspx?id=40784).

**Chinese Futures Market**
5. Run **install.bat** to install vn.py and all dependencies.

- CTP(vn.ctp)
6. Go to folder **examples/CryptoTrader/** and edit those **ABC_connect.json** files with your exchange config. Taking BitMEX_connect.json as an example:
* apiKey: the API Key of your account provided by BitMEX
* secretKey: the Secret Key of your account provide by BitMEX
* sessionCount: number of sessions and threads you would like to use for RESTFul request
* symbols: symbols of contract you would like to receive data update from Websocket API

- Femas(vn.femas)
7. Change the "language" setting in **VT_setting.json** to "english" (otherwise you will see the GUI in Chinese).

- Kingstar Option(vn.ksotp)
8. Start CryptoTrader by running "python run.py", connect to BitMEX and then you are ready to trade!

- XSpeed(vn.xspeed)
### Project Structure

1. A large number of Broker and Market Data APIs, all in Python (vnpy.api):

**Chinese Equity Market**
**Cryptocurrency Market**

- LTS(vn.lts)

- QDP(vn.qdp)
- BitMEX (bitmex)

- CSHSHLP(vn.cshshlp)
- OKEX(okex)

**Chinese Precious Metal Market**
- Huobi Pro(huobi)

- SGIT(vn.sgit)
- Binance(binance)

- Kingstar Gold(vn.ksgold)
- Bitfinex (bitfinex)

- Coinbase Pro (coinbase)

**Cryptocurrency Market**
- FCoin (fcoin)

- OKCOIN(vn.okcoin)

- Huobi(vn.huobi)
- BigOne (bigone)

- Lhang(vn.lhang
- LBank(lbank

**Market Data**
- CCXT (ccxt)

- Datayes(vn.datayes)
**International Financial Markets**

2. Simple but powerful event engine module (vn.event), which can be used for developing complex quantitative trading strategies
- Interactive Brokers(ib)

- Shanghai Zhida Futures(shzd)

3. RPC framework (vn.rpc) which also supports pushing data from server to client, aimed at implementing distributed trading systems.
- Futu Securities (futu)

4. Ready to use trading platform (vn.trader), which has integrated all the trading APIs in vn.api, and provides easy to use strategy engines for developing different types of quantitative strategies and trading algorithms.
**Chinese Futures Market**

5. Tutorials about how to use vn.py to solve real world trading issues.
- CTP(ctp)

6. [Official Website](http://vnpy.org) and [Github Repository](http://www.github.com/vnpy/vnpy)
- Femas(femas)

- Kingstar Option(ksotp)

---
### Quick Start
- XSpeed(xspeed)

1. Prepare a computer with Windows 7 (64-bit) installed.
**Chinese Equity Market**

- LTS(lts)

- QDP(qdp)

2. Install [Anaconda](http://www.continuum.io/downloads), please make sure you download **Anaconda 4.0.0 Python 2.7 (32-bit)**.
- CSHSHLP(cshshlp)

- XSpeed Securities (sec)

**Chinese Precious Metal Market**

3. Install [MongoDB](https://www.mongodb.org/downloads#production)
- SGIT(sgit)

4. Install pymongo, just run "pip install pymongo" in cmd.
- Kingstar Gold(ksgold)

5. Register MongoDB as Windows Service and start it.

6. Install [Visual C++ Redistributable Packages for VS2013 (32-bit)](https://www.microsoft.com/en-gb/download/details.aspx?id=40784).
2. Simple but powerful event engine module (vnpy.event), which can be used for developing complex quantitative trading strategies

7. Click the "Download ZIP" button on this page to download the project source code, assume you unzip to C:\vnpy.
3. RPC framework (vnpy.rpc) which also supports pushing data from server to client, aimed at implementing distributed trading systems.

8. Install the IB TWS software and configure it to allow trading API connection.
4. Ready to use trading platform (vnpy.trader), which has integrated all the trading APIs in vnpy.api, and provides easy to use strategy engines for developing different types of quantitative strategies and trading algorithms.

9. Use sublime text or any other text editors you like, to change related details in C:\vnpy\vn.trader\gateway\ibGateway\IB_connect.json to your data.
5. Examples about how to use vn.py framework for solving real world trading issues (vnpy.examples).

10. Start IB TWS software and run C:\vnpy\vn.trader\vtMain.py, enjoy trading!
6. [Official Forum](http://www.vnpie.org) and [Github Repository](http://www.github.com/vnpy/vnpy)

---
### Contact
Expand Down
79 changes: 58 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,91 @@

vn.py是基于Python的开源量化交易程序开发框架,起源于国内私募的自主量化交易系统。2015年初项目启动时只是单纯的交易API接口的Python封装。随着业内关注度的上升和社区不断的贡献,目前已经成长为一套全功能的交易程序开发框架,用户群体也日渐多样化,包括私募基金、券商自营和资管、期货资管和子公司、高校研究机构和专业个人投资者等。

2018年中启动代号为vn.crypto的数字货币量化交易系统开发计划,目前已完成第一阶段的开发,提供针对数字货币交易所原生的REST/WebSocket API的高性能的Python接口封装设计、以及适合7x24小时长时间交易需求的算法交易AlgoTrading模块、面向币圈交易的前端应用示例CryptoTrader等,后续会进一步完善打造功能全面的数字货币量化交易平台。

---

### 项目结构

1. 丰富的Python交易API接口(vnpy.api),基本覆盖了国内外所有常规交易品种(股票、期货、期权、外汇、外盘、比特币),具体包括:
1. 丰富的Python交易API接口(vnpy.api),基本覆盖了国内外所有常规交易品种(股票、期货、期权、外汇、外盘、数字货币),具体包括:

- 传统金融

- CTP(ctp)

- 飞马(femas)

- 中泰证券XTP(xtp)

- 中信证券期权(cshshlp)

- 金仕达黄金(ksgold)

- 金仕达期权(ksotp)

- 飞鼠(sgit)

- 飞创(xspeed)

- CTP(ctp)
- 飞创证券(sec)

- 飞马(femas
- QDP(qdp

- 中泰证券XTP(xtp
- 上海直达期货(shzd

- 中信证券期权(cshshlp
- Interactive Brokers(ib

- 金仕达黄金(ksgold
- 福汇(fxcm

- 金仕达期权(ksotp)

- 飞鼠(sgit)
- 数字货币

- 飞创(xspeed)
- OKEX(okex)

- QDP(qdp)
- 火币(huobi)

- 上海直达期货(shzd)
- 币安(binance)

- Interactive Brokers(ib)
- BitMEX (bitmex)

- 福汇(fxcm)
- Bitfinex (bitfinex)

- OKCOIN(okcoin)
- Coinbase Pro (coinbase)

- 火币(huobi)
- FCoin (fcoin)

- BigOne (bigone)

- LBank(lbank)

- CCXT (ccxt)

- LBank(lbank)

2. 简洁易用的事件驱动引擎(vnpy.event),作为事件驱动型交易程序的核心

3. 支持服务器端数据推送的RPC框架(vnpy.rpc),用于实现多进程分布式架构的交易系统

4. 开箱即用的实盘交易平台框架(vnpy.trader),整合了多种交易接口,并针对具体策略算法和功能开发提供了简洁易用的API,用于快速构建交易员所需的量化交易程序,应用举例:
4. 开箱即用的量化交易平台(vnpy.trader),整合了多种交易接口,并针对具体策略算法和功能开发提供了简洁易用的API,用于快速构建交易员所需的量化交易程序,应用举例:

* 同时登录多个交易接口,在一套界面上监控多种市场的行情和多种资产账户的资金、持仓、委托、成交情况

* 支持跨市场套利(CTP期货和XTP证券)、境内外套利(CTP期货和IB外盘)、多市场数据整合实时预测走势(CTP的股指期货数据、IB的外盘A50数据、Wind的行业指数数据)等策略应用

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

* SpreadTrading,价差交易模块,根据用户的配置自动实现价差组合的深度行情以及持仓变化计算,同时内置的交易算法SniperAlgo可以满足大部分到价成交策略的需求,用户也可以基于AlgoTemplate开发更复杂的价差算法

* OptionMaster,期权交易模块,强大的期权投资组合管理功能,结合基于Cython开发的高效期权定价模型,支持毫秒级别的整体希腊值持仓风险计算,用户可以基于期权交易引擎OmEngine快速开发各类复杂期权交易应用

* 实盘行情记录,支持Tick和K线数据的落地,用于策略开发回测以及实盘运行初始化
* AlgoTrading,算法交易模块,提供多种常用的智能交易算法:TWAP、Sniper、BestLimit、Iceberg、Arbitrage等等,支持数据库配置保存、CSV文件加载启动以及RPC跨进程算法交易服务

* RiskManager,前端风控模块,负责在交易系统将任何交易请求发出到柜台前的一系列标准检查操作,支持用户自定义风控规则的扩展

* DataRecorder,实盘行情记录,支持Tick和K线数据的落地,用于策略开发回测以及实盘运行初始化

* RpcService,RPC跨进程调用服务,基于MainEngineProxy组件,用户可以如同开发单一进程应用搬开发多进程架构的复杂交易应用

* RtdService,EXCEL RTD服务组件,通过pyxll模块提供EXCEL表格系统对VnTrader系统内所有数据的访问和功能调用(未完成)

5. 数据相关的API接口(vnpy.data),用于构建和更新历史行情数据库,目前包括:

Expand All @@ -71,7 +107,7 @@ vn.py是基于Python的开源量化交易程序开发框架,起源于国内私

8. vn.py项目的Docker镜像(docker),目前尚未完成

9. [官网](http://vnpy.org)[知乎专栏](http://zhuanlan.zhihu.com/vn-py),内容包括vn.py项目的开发教程和Python在量化交易领域的应用研究等内容
9. [官方论坛](http://www.vnpie.com)[知乎专栏](http://zhuanlan.zhihu.com/vn-py),内容包括vn.py项目的开发教程和Python在量化交易领域的应用研究等内容

10. 官方交流QQ群262656087,管理较严格(定期清除长期潜水的成员)

Expand All @@ -84,7 +120,7 @@ vn.py是基于Python的开源量化交易程序开发框架,起源于国内私

1. 支持的操作系统:Windows 7/8/10/Server 2008
2. 安装[MongoDB](https://www.mongodb.org/downloads#production),并[将MongoDB配置为系统服务](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#configure-a-windows-service-for-mongodb-community-edition)
3. 安装[Anaconda](http://www.continuum.io/downloads)**注意必须是Python 2.7 32位版本**
3. 安装[Anaconda 5.2.0](http://www.continuum.io/downloads)**注意必须是Python 2.7 32位版本**
4. 安装[Visual C++ Redistributable Packages for VS2013 x86版本](https://support.microsoft.com/en-us/help/3138367/update-for-visual-c-2013-and-visual-c-redistributable-package)

**Ubuntu**
Expand Down Expand Up @@ -227,6 +263,7 @@ vn.py使用github托管其源代码,如果希望贡献代码请使用github的

捐赠方式:支付宝[email protected]*晓优)


计划长期维护一份捐赠清单,所以请在留言中注明是项目捐赠以及捐赠人的名字(当然想匿名的用户就随意了)。


Expand Down
6 changes: 5 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

本文件夹中的内容主要是关于如何在交易业务中使用vn.py的示例

* CryptoTrader:vn.crypto数字货币交易平台

* VnTrader:最常用的vn.py图形交易系统

* OptionMaster: 期权量化交易系统
Expand All @@ -24,4 +26,6 @@

* TushareDataService:TuShare历史行情服务(A股)

* FutuDataService:富途证券历史行情服务(美股、港股)
* FutuDataService:富途证券历史行情服务(美股、港股)

* CoinapiDataService:CoinAPI.io历史行情服务(数字货币)
2 changes: 1 addition & 1 deletion init.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

::安装Anaconda
choco install anaconda2 --version 4.0.0 --x86 -y --ignorechecksum --params="'/AddToPath=1'"
choco install anaconda2 --version 5.2.0 --x86 -y --ignorechecksum --params="'/AddToPath=1'"
setx PATH "%PATH%;C:\Program Files\Anaconda2\;C:\Program Files\Anaconda2\Scripts\"

::安装VC Redist
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ flask-restful
flask-cors
gevent-websocket
pyjwt
webbrowser
ccxt
2 changes: 1 addition & 1 deletion vnpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8

__version__ = '1.8.1'
__version__ = '1.9.0'
__author__ = 'Xiaoyou Chen'
23 changes: 0 additions & 23 deletions vnpy/api/README.md

This file was deleted.

11 changes: 11 additions & 0 deletions vnpy/trader/app/ctaStrategy/ctaBacktesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ def calculateBacktestingResult(self):
"""
self.output(u'计算回测结果')

# 检查成交记录
if not self.tradeDict:
self.output(u'成交记录为空,无法计算回测结果')
return {}

# 首先基于回测后的成交记录,计算每笔交易的盈亏
resultList = [] # 交易结果列表

Expand Down Expand Up @@ -971,6 +976,11 @@ def calculateDailyResult(self):
"""计算按日统计的交易结果"""
self.output(u'计算按日统计结果')

# 检查成交记录
if not self.tradeDict:
self.output(u'成交记录为空,无法计算回测结果')
return {}

# 将成交添加到每日交易结果中
for trade in self.tradeDict.values():
date = trade.dt.date()
Expand Down Expand Up @@ -1333,6 +1343,7 @@ def runHistoryDataServer():
hds.start()

print(u'按任意键退出')
hds.stop()
raw_input()

#----------------------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions vnpy/trader/app/spreadTrading/stEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,7 @@ def processTradeEvent(self, event):
spread.calculatePos()

# 推送价差持仓更新
event1 = Event(EVENT_SPREADTRADING_POS+spread.name)
event1.dict_['data'] = spread
self.eventEngine.put(event1)

event2 = Event(EVENT_SPREADTRADING_POS)
event2.dict_['data'] = spread
self.eventEngine.put(event2)
self.putSpreadPosEvent(spread)

#----------------------------------------------------------------------
def processPosEvent(self, event):
Expand Down

0 comments on commit 9e9d2dc

Please sign in to comment.