Skip to content

Commit

Permalink
Update Version 2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shinny-pack authored and shinny-mayanqiong committed Aug 6, 2021
1 parent 4ce2488 commit ea9f7f6
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: tqsdk
Version: 2.7.2
Version: 2.8.0
Summary: TianQin SDK
Home-page: https://www.shinnytech.com/tqsdk
Author: TianQin
Expand Down
12 changes: 8 additions & 4 deletions doc/advanced/unanttended.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,26 @@ TqSdk可以在windows/linux或macosx环境下运行. 无论您选择使用window

在 windows 环境下配置策略的定时启动/停止
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在 windows 下, 通常使用计划任务来管理策略的定时启动/停止, 下面的说明以 Windows Server 2008 为例, 其它 windows 版本操作可能有少许差异.
在 windows 下, 通常使用计划任务来管理策略的定时启动/停止, 下面的说明以 Windows 10 为例, 其它 windows 版本操作可能有少许差异.


打开 windows 任务计划管理器

.. image:: ../images/win2008_start_scheduled_task.png
.. image:: ../images/win10_start_scheduled_task.png

点击 创建基本任务

.. image:: ../images/win10_start_scheduled_task_create.png


为每个策略添加一个策略启动任务, [程序或脚本]处填 python.exe, [添加参数]处填策略代码py文件名和参数, [起始于]处填策略代码目录

.. image:: ../images/win2008_scheduled_task_python.png
.. image:: ../images/win10_start_scheduled_task_python.png


最后添加一个任务, 用来停止所有策略进程. [程序或脚本]处填 taskkill, [添加参数]处填 /IM python.exe

.. image:: ../images/win2008_scheduled_task_kill.png
.. image:: ../images/win10_start_scheduled_task_taskkill.png


在 linux 环境下配置策略的定时启动/停止
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = u'2.7.2'
version = u'2.8.0'
# The full version, including alpha/beta/rc tags.
release = u'2.7.2'
release = u'2.8.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
Binary file added doc/images/win10_start_scheduled_task.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/win10_start_scheduled_task_create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/profession.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TqSdk 中大部分功能是供用户免费使用的, 同时我们也提供了 Tq

.. figure:: images/web_gui_backtest.png

对于 TqSdk 免费版本的用户如果想检验自己策略可以使用 :ref:`replay` 或申请模拟账户后模拟运行来检验 :ref:`sim_trading`
对于 TqSdk 免费版本的用户,每天可以进行3次回测,同时也可以使用 :ref:`replay` 或申请模拟账户后模拟运行来检验策略 :ref:`sim_trading`

股票行情
-------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/usage/backtest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

如果想使用策略回测该功能,可以点击 `天勤量化专业版 <https://www.shinnytech.com/tqsdk_professional/>`_ 申请使用或购买

对于 TqSdk 免费版本的用户如果想检验自己策略可以使用 :ref:`replay` 或申请模拟账户后模拟运行来检验 :ref:`sim_trading`
对于 TqSdk 免费版本的用户,每天可以进行3次回测,同时也可以使用 :ref:`replay` 或申请模拟账户后模拟运行来检验策略 :ref:`sim_trading`

执行策略回测
-------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions doc/version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

版本变更
=============================
2.8.0 (2021/08/05)

* 增加:**支持免费用户每日回测 3 次**


2.7.2 (2021/07/30)

* 增加:**支持在回测中使用 query 系列函数,查询结果为回测当天的合约信息**
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_tag(self):

setuptools.setup(
name='tqsdk',
version="2.7.2",
version="2.8.0",
description='TianQin SDK',
author='TianQin',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.7.2'
__version__ = '2.8.0'
3 changes: 0 additions & 3 deletions tqsdk/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ def __init__(self, start_dt: Union[date, datetime], end_dt: Union[date, datetime
async def _run(self, api, sim_send_chan, sim_recv_chan, md_send_chan, md_recv_chan):
"""回测task"""
self._api = api
if not self._api._auth._has_feature("tq_bt"):
raise Exception("您的账户不支持回测功能,需要购买专业版本后使用。升级网址:https://account.shinnytech.com")

# 下载历史主连合约信息
rsp = requests.get(os.getenv("TQ_CONT_TABLE_URL", "https://files.shinnytech.com/continuous_table.json"),
headers=self._api._base_headers,
Expand Down
17 changes: 16 additions & 1 deletion tqsdk/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from tqsdk.diff import _merge_diff, _get_obj
from tqsdk.entity import Entity
from tqsdk.exceptions import TqBacktestPermissionError
from tqsdk.utils import _generate_uuid

"""
Expand Down Expand Up @@ -67,6 +68,16 @@ def __init__(self, *args, **kwargs):
super(TqWebSocketClientProtocol, self).__init__(*args, **kwargs)
self.reader = TqStreamReader(limit=self.read_limit // 2, loop=self.loop)

async def handshake(self, *args, **kwargs) -> None:
try:
await super(TqWebSocketClientProtocol, self).handshake(*args, **kwargs)
except websockets.exceptions.InvalidStatusCode as e:
for h_key, h_value in self.response_headers.items():
if h_key == 'x-shinny-auth-check' and h_value == 'Backtest Permission Denied':
raise TqBacktestPermissionError(
"免费账户每日可以回测3次,今日暂无回测权限,需要购买专业版本后使用。升级网址:https://account.shinnytech.com") from None
raise

async def read_message(self):
message = await super().read_message()
self.reader._start_read_message = None
Expand Down Expand Up @@ -164,7 +175,8 @@ async def _run(self, api, url, send_chan, recv_chan):
# 希望做到的效果是遇到网络问题可以断线重连, 但是可能抛出的例外太多了(TimeoutError,socket.gaierror等), 又没有文档或工具可以理出 try 代码中所有可能遇到的例外
# 而这里的 except 又需要处理所有子函数及子函数的子函数等等可能抛出的例外, 因此这里只能遇到问题之后再补, 并且无法避免 false positive 和 false negative
except (websockets.exceptions.ConnectionClosed, websockets.exceptions.InvalidStatusCode,
websockets.exceptions.InvalidState, websockets.exceptions.ProtocolError, OSError) as e:
websockets.exceptions.InvalidState, websockets.exceptions.ProtocolError, OSError,
TqBacktestPermissionError) as e:
# 发送网络连接断开的通知,code = 2019112911
notify_id = _generate_uuid()
notify = {
Expand All @@ -183,6 +195,9 @@ async def _run(self, api, url, send_chan, recv_chan):
}
}]
})
if isinstance(e, TqBacktestPermissionError):
# 如果错误类型是用户无回测权限,直接返回
raise
finally:
if self._first_connect:
self._first_connect = False
Expand Down
10 changes: 10 additions & 0 deletions tqsdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,13 @@ class TqTimeoutError(Exception):
def __init__(self, message):
super().__init__(message)
self.message = message


class TqBacktestPermissionError(Exception):
"""
没有回测权限报错
"""

def __init__(self, message):
super().__init__(message)
self.message = message

0 comments on commit ea9f7f6

Please sign in to comment.