Skip to content

Commit

Permalink
Update Version 3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shinny-pack authored and shinny-mayanqiong committed Jun 21, 2024
1 parent 4f6b37c commit 53f7aaf
Show file tree
Hide file tree
Showing 30 changed files with 304 additions and 84 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: 3.5.10
Version: 3.6.0
Summary: TianQin SDK
Home-page: https://www.shinnytech.com/tqsdk
Author: TianQin
Expand Down
7 changes: 4 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.githubpages', 'autodocsumm']
extensions = ["nbsphinx", 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.githubpages', 'autodocsumm', ]
smartquotes = False

# 设置 graphviz_dot 路径
Expand Down Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = u'3.5.10'
version = u'3.6.0'
# The full version, including alpha/beta/rc tags.
release = u'3.5.10'
release = u'3.6.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -63,6 +63,7 @@
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
nbsphinx_execute = 'never' # 无输出的notebook cell将不会被运行,有输出的将在make过程中保留

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
Expand Down
1 change: 1 addition & 0 deletions doc/demo/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
option_base.rst
algorithm.rst
strategy.rst
jupyter.rst

14 changes: 14 additions & 0 deletions doc/demo/jupyter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _demo_jupyter:

Jupyter 示例
====================================================

.. contents:: 目录


.. toctree::
:maxdepth: 2
:caption: Contents:

notebooks/demo

116 changes: 116 additions & 0 deletions doc/demo/notebooks/demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "## 获取实时行情",
"id": "cf67a7321f3bb1f9"
},
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-06-19T02:43:38.474676Z",
"start_time": "2024-06-19T02:43:37.562702Z"
}
},
"source": [
"from tqsdk import TqApi, TqSim, TqAuth\n",
"auth = TqAuth('快期账户', '快期密码')"
],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"在使用天勤量化之前,默认您已经知晓并同意以下免责条款,如果不同意请立即停止使用:https://www.shinnytech.com/blog/disclaimer/\n"
]
}
],
"execution_count": 1
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-19T02:43:40.994847Z",
"start_time": "2024-06-19T02:43:38.476915Z"
}
},
"cell_type": "code",
"source": "api = TqApi(TqSim(), auth=auth)",
"id": "1e9889a79d1712c6",
"outputs": [],
"execution_count": 2
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-19T02:43:41.019471Z",
"start_time": "2024-06-19T02:43:40.996711Z"
}
},
"cell_type": "code",
"source": "q = api.get_quote('SHFE.rb2410')",
"id": "2882551c574b0eb",
"outputs": [],
"execution_count": 3
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-19T02:43:41.025745Z",
"start_time": "2024-06-19T02:43:41.021628Z"
}
},
"cell_type": "code",
"source": "print(q.datetime, q.last_price)",
"id": "61778b7e63c12fd7",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2024-06-19 10:43:40.500000 3639\n"
]
}
],
"execution_count": 4
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-06-19T02:43:41.051300Z",
"start_time": "2024-06-19T02:43:41.027038Z"
}
},
"cell_type": "code",
"source": "api.close()",
"id": "d399ddff6ba9fc70",
"outputs": [],
"execution_count": 5
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-------------------------------------------------
天勤量化的核心是TqSdk开发包, 在安装天勤量化 (TqSdk) 前, 你需要先准备适当的环境和Python包管理工具, 包括:

* Python >=3.6.4,3.7,3.8,3.9 版本
* Python >=3.7,3.8,3.9,3.10,3.11,3.12 版本
* Windows 7 以上版本, Mac Os, 或 Linux


Expand Down
1 change: 1 addition & 0 deletions doc/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
targetpostask.rst
backtest.rst
web_gui.rst
jupyter.rst
35 changes: 35 additions & 0 deletions doc/usage/jupyter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _jupyter:

在 Jupyter Notebook 中使用 TqSdk
====================================================

本文档将介绍如何在 Jupyter Notebook 中使用 TqSdk。与普通代码类似,直接导入 TqSdk 并使用即可。

安装 Jupyter Notebook
----------------------------------------------------

Jupyter Notebook 是一个开源项目,能够在交互式编程环境中提供丰富的可视化表达,可以创建和共享代码和文档。

可以使用以下命令安装 Jupyter Notebook:

```bash
pip install jupyter
```

更多 Jupyter Notebook 安装文档请参考

`Jupyter Notebook 安装文档 <https://jupyter.org/install/>`_ ::
`Jupyter Notebook 文档 <https://jupyter-notebook.readthedocs.io/en/latest//>`_ ::


安装 TqSdk
----------------------------------------------------

请参考 :ref:`安装文档 <tqsdk_install>` 。


在 Jupyter Notebook 中使用 TqSdk
----------------------------------------------------

请参考 :ref:`示例 <demo_jupyter>` 。

6 changes: 3 additions & 3 deletions doc/usage/option_trade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ TqSdk 内提供了完善的期权查询函数 :py:meth:`~tqsdk.TqApi.query_optio
ls = api.query_options("SHFE.au2012", strike_price=340)
print(ls) # 标的为 "SHFE.au2012" 、行权价为 340 的期权

ls = api.query_options("SSE.510300", exchange_id="CFFEX")
ls = api.query_options("SSE.510300")
print(ls) # 中金所沪深300股指期权

ls = api.query_options("SSE.510300", exchange_id="SSE")
ls = api.query_options("SSE.510300")
print(ls) # 上交所沪深300etf期权

ls = api.query_options("SSE.510300", exchange_id="SSE", exercise_year=2020, exercise_month=12)
ls = api.query_options("SSE.510300", exercise_year=2020, exercise_month=12)
print(ls) # 上交所沪深300etf期权, 限制条件 2020 年 12 月份行权


Expand Down
8 changes: 8 additions & 0 deletions doc/version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

版本变更
=============================
3.6.0 (2024/06/21)

* 增加:支持在 Jupyter 中使用 Tqsdk,详情参考 :ref:`jupyter`
* 修复:tafunc 中部分计算函数对 :py:meth:`~tqsdk.TqApi.get_kline_data_series`、:py:meth:`~tqsdk.TqApi.get_tick_data_series` 返回的 duration 列单位处理错误的问题
* 优化:tqsdk 内部 task 的取消机制,避免了部分 task 无法正常取消的问题
* docs: 修正文档,支持的 python 版本为 3.7, 3.8, 3.9, 3.10, 3.11, 3.12


3.5.10 (2024/05/27)

* 修复:某些情况下网络连接发生超时错误时,可能无法重连的问题
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='tqsdk',
version="3.5.10",
version="3.6.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__ = '3.5.10'
__version__ = '3.6.0'
6 changes: 2 additions & 4 deletions tqsdk/algorithm/twap.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ async def _insert_order(self, volume, end_time, strict_end_time, exit_immediatel
if exit_immediately and volume_left == 0:
break
finally:
self._order_task._task.cancel()
await asyncio.gather(self._order_task._task, return_exceptions=True)
await self._api._cancel_task(self._order_task._task)
while not trade_chan.empty():
v = await trade_chan.recv()
volume_left = volume_left - (v if self._direction == "BUY" else -v)
Expand All @@ -240,8 +239,7 @@ async def _insert_order_active(self, volume):
break
finally:
await trade_chan.close()
self._order_task._task.cancel()
await asyncio.gather(self._order_task._task, return_exceptions=True)
await self._api._cancel_task(self._order_task._task)

def _get_volume_list(self):
if self._volume < self._max_volume_each_order:
Expand Down
Loading

0 comments on commit 53f7aaf

Please sign in to comment.