Skip to content

Commit

Permalink
Merge pull request vnpy#2843 from vnpy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vnpy authored Feb 19, 2021
2 parents f8f76e6 + af760d2 commit f0ee1dc
Show file tree
Hide file tree
Showing 62 changed files with 2,883 additions and 1,590 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 2.1.9版本

## 修复
1. 修复BarGenerator的小时线合成时,出现同一个小时的K线重复推送两次的问题
2. 修复遗传算法优化时,因为lru_cache缓存导致的新一轮优化结果不变的问题
3. 修复RestClient发起请求时,由于requests库底层使用OpenSSL导致的WinError 10054 WSAECONNRESET的问题
4. 修复okexf、okexs、okexo三个接口收取TICK行情时,盘口数据解析错误的问题
5. 修复程序中频繁捕捉到异常时,异常捕捉对话框反复执行导致卡死的问题
6. 修复币安的现货和合约接口请求抛出SSLError异常时,未捕捉导致程序卡死的问题
7. 修复活动委托监控组件ActiveOrderMonitor,保存CSV时会将所有委托数据一起保存的问题
8. 修复XtpGateway重复发起登录操作时,出现的系统崩溃问题
9. 修复XtpGateway的股票市价委托类型映射错误问题
10. 修复DeribitGateway中对于Stop Market类型委托的支持问题,同时过滤掉Stop Limit类型委托
11. 修复BinancesGateway中,由于成交数量浮点数精度问题导致的上层应用模块(CtaStrategy)数据计算错误
12. 修复BinancesGateway中,由于合约持仓类型(应该是净仓,而非多空仓)错误,导致的上层应用模块(SpreadTrading)数据计算错误
13. 修复HuobisGateway中,初始化查询活动委托时,由于请求过快导致的限流错误

## 调整
1. 对XTP接口的行情价格数据基于合约最小价格跳动进行取整,资金保留2位小数
2. BaseMonitor保存CSV文件时,表头改为图形界面显示的中文(之前是数据的字段名英文)
3. 初始化TWAP算法时,对每轮委托数量取整到合约最小交易数量
4. 将原vnpy.trader.database中的数据库客户端拆分到独立的vnpy.database模块下
5. 对SQLite/MySQL/PostgreSQL/MongoDB/InfluxDB客户端进行代码重构优化,增加K线数据整体情况BarOverview查询功能

## 新增
1. 新增BaseMonitor数据监控UI组件(以及其子类),自动保存列宽的功能
2. 增加华鑫奇点ToraGateway对于FENS服务器连接和资金账户登录的支持,之前只支持前置机连接和用户代码登录
3. 增加火币永续合约HuobisGateway对于USDT本位合约的支持
4. 增加InfluxDB数据库客户端vnpy.database.influx对于Tick数据储存和加载的支持
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>

<p align="center">
<img src ="https://img.shields.io/badge/version-2.1.8-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/version-2.1.9-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/platform-windows|linux|macos-yellow.svg"/>
<img src ="https://img.shields.io/badge/python-3.7-blue.svg" />
<img src ="https://img.shields.io/github/workflow/status/vnpy/vnpy/Python%20application/master"/>
Expand Down Expand Up @@ -164,6 +164,22 @@ vn.py是一套基于Python的开源量化交易系统开发框架,于2015年1

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

6. 对接各类数据库的标准化管理客户端(vnpy.database):

* SQL类

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

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

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

* NoSQL类

* MongoDB(mongodb):基于分布式文件储存(bson格式)的非关系型数据库,内置的热数据内存缓存提供更快读写速度

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

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

7. Python高性能K线图表(vnpy.chart),支持大数据量图表显示以及实时数据更新功能。
Expand All @@ -174,7 +190,7 @@ vn.py是一套基于Python的开源量化交易系统开发框架,于2015年1

## 环境准备

* 推荐使用vn.py团队为量化交易专门打造的Python发行版[VNStudio-2.1.8](https://download.vnpy.com/vnstudio-2.1.8.exe),内置了最新版的vn.py框架以及VN Station量化管理平台,无需手动安装
* 推荐使用vn.py团队为量化交易专门打造的Python发行版[VNStudio-2.1.9](https://download.vnpy.com/vnstudio-2.1.9.exe),内置了最新版的vn.py框架以及VN Station量化管理平台,无需手动安装
* 支持的系统版本:Windows 7以上/Windows Server 2008以上/Ubuntu 18.04 LTS
* 支持的Python版本:Python 3.7 64位(**注意必须是Python 3.7 64位版本**

Expand Down
6 changes: 3 additions & 3 deletions docs/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main():

接口配置相关保存在json文件中,放在如图C盘用户目录下的.vntrader文件夹内。

![](https://vnpy-community.oss-cn-shanghai.aliyuncs.com/forum_experience/yazhang/gateway/.vntrader.png)
![](https://s3.ax1x.com/2021/01/18/s678IA.png)

所以要修改接口配置文件,用户即可以在图形化界面VN Trader内修改,也可以直接在.vntrader修改json文件。
另外将json配置文件分离于vnpy的好处在于:避免每次升级都要重新配置json文件。
Expand Down Expand Up @@ -142,14 +142,14 @@ main_engine.add_gateway(CtpGateway)
- 经纪商编号:brokerid
- 交易服务器地址:td_address
- 行情服务器地址:md_address
- 产品名称:product_info
- 产品名称:app_id
- 授权编码:auth_code

&nbsp;

#### 获取账号

- 仿真账号:从SimNow网站上获取。只需输入手机号码和短信验证即可。(短信验证有时只能在工作日正常工作时段收到)SimNow的用户名为6位纯数字,经纪商编号为9999,并且提供2套环境用于盘中仿真交易以及盘后的测试。
- 仿真账号:从SimNow网站上获取。只需输入手机号码和短信验证即可。(短信验证有时只能在工作日正常工作时段收到)SimNow的用户名(InvestorID)为6位纯数字,经纪商编号为9999,并且提供2套环境用于盘中仿真交易以及盘后的测试。

- 实盘账号:在期货公司开户,通过联系客户经理可以开通。用户名为纯数字,经纪商编号也是4位纯数字。(每个期货公司的经纪商编号都不同)另外,实盘账号也可以开通仿真交易功能,同样需要联系客户经理。

Expand Down
4 changes: 2 additions & 2 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ VNStudio是vn.py团队自行打包的一键安装版本,整合了:
&nbsp;

#### 4.启动VN Trader
在文件夹tests\trader中找到run.py文件。按住“Shift” + 鼠标右键进入cmd窗口,输入下面命令即可启动VN Trader。
在github文件夹examples\vn_trader中找到run.py文件。按住“Shift” + 鼠标右键进入cmd窗口,输入下面命令即可启动VN Trader。
```
python run.py
```
Expand Down Expand Up @@ -149,7 +149,7 @@ bash install.sh
&nbsp;

### 4.启动VN Trader
在文件夹tests\trader中找到run.py文件。右键进入终端,输入下面命令即可启动VN Trader。
在github文件夹examples\vn_trader中找到run.py文件。右键进入终端,输入下面命令即可启动VN Trader。
```
python run.py
```
3 changes: 2 additions & 1 deletion examples/candle_chart/run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from datetime import datetime

from vnpy.trader.ui import create_qapp, QtCore
from vnpy.trader.database import database_manager
from vnpy.trader.constant import Exchange, Interval
from vnpy.trader.database import database_manager
from vnpy.chart import ChartWidget, VolumeItem, CandleItem


if __name__ == "__main__":
app = create_qapp()

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ QScintilla==2.11.4
plotly
quickfix
trading-calendars
influxdb
2 changes: 1 addition & 1 deletion vnpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.8"
__version__ = "2.1.9"
4 changes: 4 additions & 0 deletions vnpy/api/rest/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import requests


# Use SSL from Python stdlib instead of OpenSSL to avoid [10054 WSAECONNRESET] error
requests.packages.urllib3.contrib.pyopenssl.extract_from_urllib3()


CALLBACK_TYPE = Callable[[dict, "Request"], Any]
ON_FAILED_TYPE = Callable[[int, "Request"], Any]
ON_ERROR_TYPE = Callable[[Type, Exception, TracebackType, "Request"], Any]
Expand Down
22 changes: 15 additions & 7 deletions vnpy/api/xtp/vnxtp/vnxtpmd/vnxtpmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,13 @@ void MdApi::processDepthMarketData(Task *task)
data["turnover"] = task_data->turnover;
data["avg_price"] = task_data->avg_price;
data["trades_count"] = task_data->trades_count;
data["ticker_status"] = task_data->ticker_status;
data["data_type"] = (int)task_data->data_type;
data["r4"] = task_data->r4;

//Solve UDP protocol error text
string status = task_data->ticker_status;
data["ticker_status"] = status.substr(0, 4);

pybind11::list ask;
pybind11::list bid;
pybind11::list ask_qty;
Expand Down Expand Up @@ -1078,18 +1081,23 @@ void MdApi::processUnSubscribeAllOptionTickByTick(Task *task)
///主动函数
///-------------------------------------------------------------------------------------

void MdApi::createQuoteApi(int client_id, string save_file_path)
void MdApi::createQuoteApi(int client_id, string save_file_path, int log_level)
{
this->api = QuoteApi::CreateQuoteApi(client_id, save_file_path.c_str());
this->api->RegisterSpi(this);

if (!this->api)
{
this->api = QuoteApi::CreateQuoteApi(client_id, save_file_path.c_str(), XTP_LOG_LEVEL(log_level));
this->api->RegisterSpi(this);
}
};


void MdApi::init()
{
this->active = true;
this->task_thread = thread(&MdApi::processTask, this);
if (!this->active)
{
this->active = true;
this->task_thread = thread(&MdApi::processTask, this);
}
};

void MdApi::release()
Expand Down
2 changes: 1 addition & 1 deletion vnpy/api/xtp/vnxtp/vnxtpmd/vnxtpmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class MdApi : public QuoteSpi
//req:主动函数的请求字典
//-------------------------------------------------------------------------------------

void createQuoteApi(int client_id, string save_file_path);
void createQuoteApi(int client_id, string save_file_path, int log_level);

void release();

Expand Down
17 changes: 11 additions & 6 deletions vnpy/api/xtp/vnxtp/vnxtptd/vnxtptd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,17 +1411,22 @@ void TdApi::processQueryCreditExcessStock(Task *task)
///主动函数
///-------------------------------------------------------------------------------------

void TdApi::createTraderApi(int client_id, string save_file_path)
void TdApi::createTraderApi(int client_id, string save_file_path, int log_level)
{
this->api = TraderApi::CreateTraderApi(client_id, save_file_path.c_str());
this->api->RegisterSpi(this);
if (!this->api)
{
this->api = TraderApi::CreateTraderApi(client_id, save_file_path.c_str(), XTP_LOG_LEVEL(log_level));
this->api->RegisterSpi(this);
}
};

void TdApi::init()

{
this->active = true;
this->task_thread = thread(&TdApi::processTask, this);
if (!this->active)
{
this->active = true;
this->task_thread = thread(&TdApi::processTask, this);
}
};

void TdApi::release()
Expand Down
2 changes: 1 addition & 1 deletion vnpy/api/xtp/vnxtp/vnxtptd/vnxtptd.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class TdApi : public TraderSpi
//req:主动函数的请求字典
//-------------------------------------------------------------------------------------

void createTraderApi(int client_id, string save_file_path);
void createTraderApi(int client_id, string save_file_path, int log_level);

void release();

Expand Down
Binary file modified vnpy/api/xtp/vnxtpmd.pyd
Binary file not shown.
Binary file modified vnpy/api/xtp/vnxtptd.pyd
Binary file not shown.
18 changes: 15 additions & 3 deletions vnpy/app/algo_trading/algos/twap_algo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from vnpy.trader.utility import round_to
from vnpy.trader.constant import Offset, Direction
from vnpy.trader.object import TradeData
from vnpy.trader.object import TradeData, TickData
from vnpy.trader.engine import BaseEngine

from vnpy.app.algo_trading import AlgoTemplate
Expand Down Expand Up @@ -53,14 +54,24 @@ def __init__(

# Variables
self.order_volume = self.volume / (self.time / self.interval)
contract = self.get_contract(self.vt_symbol)
if contract:
self.order_volume = round_to(self.order_volume, contract.min_volume)

self.timer_count = 0
self.total_count = 0
self.traded = 0

self.last_tick = None

self.subscribe(self.vt_symbol)
self.put_parameters_event()
self.put_variables_event()

def on_tick(self, tick: TickData):
""""""
self.last_tick = tick

def on_trade(self, trade: TradeData):
""""""
self.traded += trade.volume
Expand All @@ -86,9 +97,10 @@ def on_timer(self):
return
self.timer_count = 0

tick = self.get_tick(self.vt_symbol)
if not tick:
if not self.last_tick:
return
tick = self.last_tick
self.last_tick = None

self.cancel_all()

Expand Down
20 changes: 12 additions & 8 deletions vnpy/app/algo_trading/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ def update_tick(self, tick: TickData):

def update_order(self, order: OrderData):
""""""
if self.active:
if order.is_active():
self.active_orders[order.vt_orderid] = order
elif order.vt_orderid in self.active_orders:
self.active_orders.pop(order.vt_orderid)
if order.is_active():
self.active_orders[order.vt_orderid] = order
elif order.vt_orderid in self.active_orders:
self.active_orders.pop(order.vt_orderid)

self.on_order(order)
self.on_order(order)

def update_trade(self, trade: TradeData):
""""""
if self.active:
self.on_trade(trade)
self.on_trade(trade)

def update_timer(self):
""""""
Expand Down Expand Up @@ -117,6 +115,9 @@ def buy(
offset: Offset = Offset.NONE
):
""""""
if not self.active:
return

msg = f"委托买入{vt_symbol}{volume}@{price}"
self.write_log(msg)

Expand All @@ -139,6 +140,9 @@ def sell(
offset: Offset = Offset.NONE
):
""""""
if not self.active:
return

msg = f"委托卖出{vt_symbol}{volume}@{price}"
self.write_log(msg)

Expand Down
1 change: 1 addition & 0 deletions vnpy/app/cta_backtester/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
BacktestingEngine, OptimizationSetting, BacktestingMode
)


APP_NAME = "CtaBacktester"

EVENT_BACKTESTER_LOG = "eBacktesterLog"
Expand Down
6 changes: 3 additions & 3 deletions vnpy/app/cta_backtester/ui/widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import csv
from datetime import datetime, timedelta
from tzlocal import get_localzone
from copy import copy

import numpy as np
Expand All @@ -14,6 +13,7 @@
from vnpy.event import Event, EventEngine
from vnpy.chart import ChartWidget, CandleItem, VolumeItem
from vnpy.trader.utility import load_json, save_json
from vnpy.trader.database import DB_TZ

from ..engine import (
APP_NAME,
Expand Down Expand Up @@ -441,8 +441,8 @@ def start_downloading(self):
start_date.year(),
start_date.month(),
start_date.day(),
tzinfo=get_localzone()
)
start = DB_TZ.localize(start)

end = datetime(
end_date.year(),
Expand All @@ -451,8 +451,8 @@ def start_downloading(self):
23,
59,
59,
tzinfo=get_localzone()
)
end = DB_TZ.localize(end)

self.backtester_engine.start_downloading(
vt_symbol,
Expand Down
Loading

0 comments on commit f0ee1dc

Please sign in to comment.