Skip to content

Commit 9830c30

Browse files
shinny-packshinny-mayanqiong
authored andcommitted
Update Version 3.0.2
1 parent 474aadc commit 9830c30

27 files changed

+235
-163
lines changed

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: tqsdk
3-
Version: 3.0.1
3+
Version: 3.0.2
44
Summary: TianQin SDK
55
Home-page: https://www.shinnytech.com/tqsdk
66
Author: TianQin

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
# built documents.
4949
#
5050
# The short X.Y version.
51-
version = u'3.0.1'
51+
version = u'3.0.2'
5252
# The full version, including alpha/beta/rc tags.
53-
release = u'3.0.1'
53+
release = u'3.0.2'
5454

5555
# The language for content autogenerated by Sphinx. Refer to documentation
5656
# for a list of supported languages.

doc/profession.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ TqSdk 提供了 :py:class:`~tqsdk.account.TqKqStock` 方法供用户来进行股
6363

6464
需要注意股票模拟交易下,get_account,get_order,get_position 会返回对应股票交易模型下的 objs ,如 :py:class:`~tqsdk.objs.SecurityAccount`, :py:class:`~tqsdk.objs.SecurityOrder`,:py:class:`~tqsdk.objs.SecurityPosition`
6565

66+
参考代码如下::
67+
68+
from tqsdk import TqApi, TqAuth, TqKqStock
69+
70+
tq_kq_stock = TqKqStock()
71+
api = TqApi(account=tq_kq_stock, auth=TqAuth("信易账户", "账户密码"))
72+
quote = api.get_quote("SSE.688529")
73+
print(quote)
74+
# 下单限价单
75+
order = api.insert_order("SSE.688529", volume=200, direction="BUY", limit_price=quote.ask_price1)
76+
while order.status == 'ALIVE':
77+
api.wait_update()
78+
print(order) # 打印委托单信息
79+
80+
print(api.get_account()) # 打印快期股票模拟账户信息
81+
82+
print(api.get_position("SSE.688529")) # 打印持仓信息
83+
84+
for trade in order.trade_records.values():
85+
print(trade) # 打印委托单对应的成交信息
86+
api.close()
87+
6688

6789
下载数据功能
6890
-------------------------------------------------

doc/quickstart.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060

6161
api = TqApi(auth=TqAuth("信易账户", "账户密码"))
6262

63-
获得上期所 ni2010 合约的行情引用::
63+
获得上期所 ni2206 合约的行情引用::
6464

65-
quote = api.get_quote("SHFE.ni2010")
65+
quote = api.get_quote("SHFE.ni2206")
6666

67-
现在, 我们获得了一个对象 quote. 这个对象总是指向 SHFE.ni2010 合约的最新行情. 我们可以通过 quote 的各个字段访问行情数据::
67+
现在, 我们获得了一个对象 quote. 这个对象总是指向 SHFE.ni2206 合约的最新行情. 我们可以通过 quote 的各个字段访问行情数据::
6868

6969
print (quote.last_price, quote.volume)
7070

@@ -93,9 +93,9 @@
9393

9494
使用K线数据
9595
-------------------------------------------------
96-
你很可能会需要合约的K线数据. 在TqSdk中, 你可以很方便的获得K线数据. 我们来请求 ni2010 合约的10秒线::
96+
你很可能会需要合约的K线数据. 在TqSdk中, 你可以很方便的获得K线数据. 我们来请求 ni2206 合约的10秒线::
9797

98-
klines = api.get_kline_serial("SHFE.ni2010", 10)
98+
klines = api.get_kline_serial("SHFE.ni2206", 10)
9999

100100
klines是一个pandas.DataFrame对象. 跟 api.get_quote() 一样, api.get_kline_serial() 也是返回K线序列的引用对象. K线序列数据也会跟实时行情一起同步自动更新. 你也同样需要用 api.wait_update() 等待数据刷新.
101101

doc/version.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
版本变更
44
=============================
5+
3.0.2 (2021/12/07)
6+
7+
* 修复:调用 :py:meth:`~tqsdk.api.TqApi.get_kline_serial` 接口获取股票前复权 Kline 时,复权计算结果可能出错的问题
8+
* 新增:节假日表添加 2022 年节假日信息
9+
* 新增:支持在 python 3.10 下使用 TqApi
10+
* web_gui:支持多账户下使用
11+
* docs:更新示例合约代码
12+
13+
514
3.0.1 (2021/11/26)
615

716
* 修复:调用 :py:meth:`~tqsdk.api.TqApi.query_symbol_info`,当参数中包含主连/指数合约会报错的问题

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_tag(self):
3636

3737
setuptools.setup(
3838
name='tqsdk',
39-
version="3.0.1",
39+
version="3.0.2",
4040
description='TianQin SDK',
4141
author='TianQin',
4242
author_email='tianqincn@gmail.com',

tqsdk/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.0.1'
1+
__version__ = '3.0.2'

tqsdk/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def __init__(self, account: Union[TqMultiAccount, TqAccount, TqSim, None] = None
296296
while self._data.get("mdhis_more_data", True) or trade_more_data:
297297
if not self.wait_update(deadline=deadline): # 等待连接成功并收取截面数据
298298
raise TqTimeoutError("接收数据超时,请检查客户端及网络是否正常")
299-
trade_more_data = self._account._get_trade_more_data_and_order_id(self, self._data)
299+
trade_more_data = self._account._get_trade_more_data_and_order_id(self._data)
300300
except:
301301
self.close()
302302
raise
@@ -3157,7 +3157,7 @@ def _setup_connection(self):
31573157

31583158
self._ws_md_recv_chan = ws_md_recv_chan # 记录 ws_md_recv_chan 引用
31593159

3160-
conn = TqConnect(md_logger)
3160+
conn = TqConnect(md_logger, conn_id="md")
31613161
self.create_task(conn._run(self, self._md_url, ws_md_send_chan, ws_md_recv_chan))
31623162

31633163
md_handler_logger = ShinnyLoggerAdapter(self._logger.getChild("MdReconnect"), url=self._md_url)
@@ -3288,6 +3288,7 @@ def _init_serial(self, root_list, width, default, adj_type):
32883288
"array": np.array(array, order="F"),
32893289
"init": False, # 是否初始化完成. 完成状态: 订阅K线后已获取所有主、副合约的数据并填满df序列.
32903290
"adj_type": adj_type,
3291+
"calc_ids_F": [], # 前复权已经计算过的id,每个 id 只计算一次
32913292
"update_row": 0, # 起始更新数据行
32923293
"all_attr": set(columns) | {"symbol" + str(i) for i in range(1, len(root_list))} | {"symbol", "duration"},
32933294
"extra_array": {},
@@ -3364,7 +3365,8 @@ def _update_serial_single(self, serial):
33643365
item = item.copy()
33653366
for c in cols:
33663367
item[c] = item[c] * self._dividend_cache[symbol]["back_factor"]
3367-
elif serial["adj_type"] == "F" and factor != 1.0:
3368+
elif serial["adj_type"] == "F" and factor != 1.0 and i not in serial['calc_ids_F']:
3369+
serial['calc_ids_F'].append(i)
33683370
for c in cols:
33693371
col_index = keys.index(c) + 2
33703372
array[:i, col_index] = array[:i, col_index] * factor

tqsdk/calendar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import pandas as pd
1515

1616

17-
# 2003-01-01 ~ 2021-12-31 节假日,不包含周末
18-
CHINESE_REST_DAYS = ['2003-01-01', '2003-01-30', '2003-01-31', '2003-02-03', '2003-02-04', '2003-02-05', '2003-02-06', '2003-02-07', '2003-05-01', '2003-05-02', '2003-05-05', '2003-05-06', '2003-05-07', '2003-10-01', '2003-10-02', '2003-10-03', '2003-10-06', '2003-10-07', '2004-01-01', '2004-01-19', '2004-01-20', '2004-01-21', '2004-01-22', '2004-01-23', '2004-01-26', '2004-01-27', '2004-01-28', '2004-05-03', '2004-05-04', '2004-05-05', '2004-05-06', '2004-05-07', '2004-10-01', '2004-10-04', '2004-10-05', '2004-10-06', '2004-10-07', '2005-01-03', '2005-02-07', '2005-02-08', '2005-02-09', '2005-02-10', '2005-02-11', '2005-02-14', '2005-02-15', '2005-05-02', '2005-05-03', '2005-05-04', '2005-05-05', '2005-05-06', '2005-10-03', '2005-10-04', '2005-10-05', '2005-10-06', '2005-10-07', '2006-01-02', '2006-01-03', '2006-01-30', '2006-01-31', '2006-02-01', '2006-02-02', '2006-02-03', '2006-05-01', '2006-05-02', '2006-05-03', '2006-05-04', '2006-05-05', '2006-10-02', '2006-10-03', '2006-10-04', '2006-10-05', '2006-10-06', '2007-01-01', '2007-01-02', '2007-01-03', '2007-02-19', '2007-02-20', '2007-02-21', '2007-02-22', '2007-02-23', '2007-05-01', '2007-05-02', '2007-05-03', '2007-05-04', '2007-05-07', '2007-10-01', '2007-10-02', '2007-10-03', '2007-10-04', '2007-10-05', '2007-12-31', '2008-01-01', '2008-02-06', '2008-02-07', '2008-02-08', '2008-02-11', '2008-02-12', '2008-04-04', '2008-05-01', '2008-05-02', '2008-06-09', '2008-09-15', '2008-09-29', '2008-09-30', '2008-10-01', '2008-10-02', '2008-10-03', '2009-01-01', '2009-01-02', '2009-01-26', '2009-01-27', '2009-01-28', '2009-01-29', '2009-01-30', '2009-04-06', '2009-05-01', '2009-05-28', '2009-05-29', '2009-10-01', '2009-10-02', '2009-10-05', '2009-10-06', '2009-10-07', '2009-10-08', '2010-01-01', '2010-02-15', '2010-02-16', '2010-02-17', '2010-02-18', '2010-02-19', '2010-04-05', '2010-05-03', '2010-06-14', '2010-06-15', '2010-06-16', '2010-09-22', '2010-09-23', '2010-09-24', '2010-10-01', '2010-10-04', '2010-10-05', '2010-10-06', '2010-10-07', '2011-01-03', '2011-02-02', '2011-02-03', '2011-02-04', '2011-02-07', '2011-02-08', '2011-04-04', '2011-04-05', '2011-05-02', '2011-06-06', '2011-09-12', '2011-10-03', '2011-10-04', '2011-10-05', '2011-10-06', '2011-10-07', '2012-01-02', '2012-01-03', '2012-01-23', '2012-01-24', '2012-01-25', '2012-01-26', '2012-01-27', '2012-04-02', '2012-04-03', '2012-04-04', '2012-04-30', '2012-05-01', '2012-06-22', '2012-10-01', '2012-10-02', '2012-10-03', '2012-10-04', '2012-10-05', '2013-01-01', '2013-01-02', '2013-01-03', '2013-02-11', '2013-02-12', '2013-02-13', '2013-02-14', '2013-02-15', '2013-04-04', '2013-04-05', '2013-04-29', '2013-04-30', '2013-05-01', '2013-06-10', '2013-06-11', '2013-06-12', '2013-09-19', '2013-09-20', '2013-10-01', '2013-10-02', '2013-10-03', '2013-10-04', '2013-10-07', '2014-01-01', '2014-01-31', '2014-02-03', '2014-02-04', '2014-02-05', '2014-02-06', '2014-04-07', '2014-05-01', '2014-05-02', '2014-06-02', '2014-09-08', '2014-10-01', '2014-10-02', '2014-10-03', '2014-10-06', '2014-10-07', '2015-01-01', '2015-01-02', '2015-02-18', '2015-02-19', '2015-02-20', '2015-02-23', '2015-02-24', '2015-04-06', '2015-05-01', '2015-06-22', '2015-09-03', '2015-09-04', '2015-10-01', '2015-10-02', '2015-10-05', '2015-10-06', '2015-10-07', '2016-01-01', '2016-02-08', '2016-02-09', '2016-02-10', '2016-02-11', '2016-02-12', '2016-04-04', '2016-05-02', '2016-06-09', '2016-06-10', '2016-09-15', '2016-09-16', '2016-10-03', '2016-10-04', '2016-10-05', '2016-10-06', '2016-10-07', '2017-01-02', '2017-01-27', '2017-01-30', '2017-01-31', '2017-02-01', '2017-02-02', '2017-04-03', '2017-04-04', '2017-05-01', '2017-05-29', '2017-05-30', '2017-10-02', '2017-10-03', '2017-10-04', '2017-10-05', '2017-10-06', '2018-01-01', '2018-02-15', '2018-02-16', '2018-02-19', '2018-02-20', '2018-02-21', '2018-04-05', '2018-04-06', '2018-04-30', '2018-05-01', '2018-06-18', '2018-09-24', '2018-10-01', '2018-10-02', '2018-10-03', '2018-10-04', '2018-10-05', '2018-12-31', '2019-01-01', '2019-02-04', '2019-02-05', '2019-02-06', '2019-02-07', '2019-02-08', '2019-04-05', '2019-05-01', '2019-05-02', '2019-05-03', '2019-06-07', '2019-09-13', '2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04', '2019-10-07', '2020-01-01', '2020-01-24', '2020-01-27', '2020-01-28', '2020-01-29', '2020-01-30', '2020-01-31', '2020-04-06', '2020-05-01', '2020-05-04', '2020-05-05', '2020-06-25', '2020-06-26', '2020-10-01', '2020-10-02', '2020-10-05', '2020-10-06', '2020-10-07', '2020-10-08', '2021-01-01', '2021-02-11', '2021-02-12', '2021-02-15', '2021-02-16', '2021-02-17', '2021-04-05', '2021-05-03', '2021-05-04', '2021-05-05', '2021-06-14', '2021-09-20', '2021-09-21', '2021-10-01', '2021-10-04', '2021-10-05', '2021-10-06', '2021-10-07']
17+
# 2003-01-01 ~ 2022-12-31 节假日,不包含周末
18+
CHINESE_REST_DAYS = ['2003-01-01', '2003-01-30', '2003-01-31', '2003-02-03', '2003-02-04', '2003-02-05', '2003-02-06', '2003-02-07', '2003-05-01', '2003-05-02', '2003-05-05', '2003-05-06', '2003-05-07', '2003-10-01', '2003-10-02', '2003-10-03', '2003-10-06', '2003-10-07', '2004-01-01', '2004-01-19', '2004-01-20', '2004-01-21', '2004-01-22', '2004-01-23', '2004-01-26', '2004-01-27', '2004-01-28', '2004-05-03', '2004-05-04', '2004-05-05', '2004-05-06', '2004-05-07', '2004-10-01', '2004-10-04', '2004-10-05', '2004-10-06', '2004-10-07', '2005-01-03', '2005-02-07', '2005-02-08', '2005-02-09', '2005-02-10', '2005-02-11', '2005-02-14', '2005-02-15', '2005-05-02', '2005-05-03', '2005-05-04', '2005-05-05', '2005-05-06', '2005-10-03', '2005-10-04', '2005-10-05', '2005-10-06', '2005-10-07', '2006-01-02', '2006-01-03', '2006-01-30', '2006-01-31', '2006-02-01', '2006-02-02', '2006-02-03', '2006-05-01', '2006-05-02', '2006-05-03', '2006-05-04', '2006-05-05', '2006-10-02', '2006-10-03', '2006-10-04', '2006-10-05', '2006-10-06', '2007-01-01', '2007-01-02', '2007-01-03', '2007-02-19', '2007-02-20', '2007-02-21', '2007-02-22', '2007-02-23', '2007-05-01', '2007-05-02', '2007-05-03', '2007-05-04', '2007-05-07', '2007-10-01', '2007-10-02', '2007-10-03', '2007-10-04', '2007-10-05', '2007-12-31', '2008-01-01', '2008-02-06', '2008-02-07', '2008-02-08', '2008-02-11', '2008-02-12', '2008-04-04', '2008-05-01', '2008-05-02', '2008-06-09', '2008-09-15', '2008-09-29', '2008-09-30', '2008-10-01', '2008-10-02', '2008-10-03', '2009-01-01', '2009-01-02', '2009-01-26', '2009-01-27', '2009-01-28', '2009-01-29', '2009-01-30', '2009-04-06', '2009-05-01', '2009-05-28', '2009-05-29', '2009-10-01', '2009-10-02', '2009-10-05', '2009-10-06', '2009-10-07', '2009-10-08', '2010-01-01', '2010-02-15', '2010-02-16', '2010-02-17', '2010-02-18', '2010-02-19', '2010-04-05', '2010-05-03', '2010-06-14', '2010-06-15', '2010-06-16', '2010-09-22', '2010-09-23', '2010-09-24', '2010-10-01', '2010-10-04', '2010-10-05', '2010-10-06', '2010-10-07', '2011-01-03', '2011-02-02', '2011-02-03', '2011-02-04', '2011-02-07', '2011-02-08', '2011-04-04', '2011-04-05', '2011-05-02', '2011-06-06', '2011-09-12', '2011-10-03', '2011-10-04', '2011-10-05', '2011-10-06', '2011-10-07', '2012-01-02', '2012-01-03', '2012-01-23', '2012-01-24', '2012-01-25', '2012-01-26', '2012-01-27', '2012-04-02', '2012-04-03', '2012-04-04', '2012-04-30', '2012-05-01', '2012-06-22', '2012-10-01', '2012-10-02', '2012-10-03', '2012-10-04', '2012-10-05', '2013-01-01', '2013-01-02', '2013-01-03', '2013-02-11', '2013-02-12', '2013-02-13', '2013-02-14', '2013-02-15', '2013-04-04', '2013-04-05', '2013-04-29', '2013-04-30', '2013-05-01', '2013-06-10', '2013-06-11', '2013-06-12', '2013-09-19', '2013-09-20', '2013-10-01', '2013-10-02', '2013-10-03', '2013-10-04', '2013-10-07', '2014-01-01', '2014-01-31', '2014-02-03', '2014-02-04', '2014-02-05', '2014-02-06', '2014-04-07', '2014-05-01', '2014-05-02', '2014-06-02', '2014-09-08', '2014-10-01', '2014-10-02', '2014-10-03', '2014-10-06', '2014-10-07', '2015-01-01', '2015-01-02', '2015-02-18', '2015-02-19', '2015-02-20', '2015-02-23', '2015-02-24', '2015-04-06', '2015-05-01', '2015-06-22', '2015-09-03', '2015-09-04', '2015-10-01', '2015-10-02', '2015-10-05', '2015-10-06', '2015-10-07', '2016-01-01', '2016-02-08', '2016-02-09', '2016-02-10', '2016-02-11', '2016-02-12', '2016-04-04', '2016-05-02', '2016-06-09', '2016-06-10', '2016-09-15', '2016-09-16', '2016-10-03', '2016-10-04', '2016-10-05', '2016-10-06', '2016-10-07', '2017-01-02', '2017-01-27', '2017-01-30', '2017-01-31', '2017-02-01', '2017-02-02', '2017-04-03', '2017-04-04', '2017-05-01', '2017-05-29', '2017-05-30', '2017-10-02', '2017-10-03', '2017-10-04', '2017-10-05', '2017-10-06', '2018-01-01', '2018-02-15', '2018-02-16', '2018-02-19', '2018-02-20', '2018-02-21', '2018-04-05', '2018-04-06', '2018-04-30', '2018-05-01', '2018-06-18', '2018-09-24', '2018-10-01', '2018-10-02', '2018-10-03', '2018-10-04', '2018-10-05', '2018-12-31', '2019-01-01', '2019-02-04', '2019-02-05', '2019-02-06', '2019-02-07', '2019-02-08', '2019-04-05', '2019-05-01', '2019-05-02', '2019-05-03', '2019-06-07', '2019-09-13', '2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04', '2019-10-07', '2020-01-01', '2020-01-24', '2020-01-27', '2020-01-28', '2020-01-29', '2020-01-30', '2020-01-31', '2020-04-06', '2020-05-01', '2020-05-04', '2020-05-05', '2020-06-25', '2020-06-26', '2020-10-01', '2020-10-02', '2020-10-05', '2020-10-06', '2020-10-07', '2020-10-08', '2021-01-01', '2021-02-11', '2021-02-12', '2021-02-15', '2021-02-16', '2021-02-17', '2021-04-05', '2021-05-03', '2021-05-04', '2021-05-05', '2021-06-14', '2021-09-20', '2021-09-21', '2021-10-01', '2021-10-04', '2021-10-05', '2021-10-06', '2021-10-07',
19+
"2022-01-03", "2022-01-31", "2022-02-01", "2022-02-02", "2022-02-03", "2022-02-04", "2022-04-04", "2022-04-05", "2022-05-02", "2022-05-03", "2022-05-04", "2022-06-03", "2022-09-12", "2022-10-03", "2022-10-04", "2022-10-05", "2022-10-06", "2022-10-07"]
1920
rest_days_df = pd.DataFrame(data={'date': pd.Series(pd.to_datetime(CHINESE_REST_DAYS, format='%Y-%m-%d'))})
2021
rest_days_df['trading_restdays'] = False # 节假日为 False
2122

tqsdk/channel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__author__ = 'yanqiong'
44

55
import asyncio
6+
import sys
67
from logging import Logger
78
from typing import Any, TYPE_CHECKING, Union
89

@@ -42,7 +43,8 @@ def __init__(self, api: 'TqApi', last_only: bool = False, logger: Union[Logger,
4243
elif isinstance(logger, ShinnyLoggerAdapter):
4344
self._logger = logger.bind(chan_id=TqChan._chan_id, chan_name=chan_name)
4445
TqChan._chan_id += 1
45-
asyncio.Queue.__init__(self, loop=api._loop)
46+
py_ver = sys.version_info
47+
asyncio.Queue.__init__(self, loop=api._loop) if (py_ver.major == 3 and py_ver.minor < 10) else asyncio.Queue.__init__(self)
4648
self._last_only = last_only
4749
self._closed = False
4850

0 commit comments

Comments
 (0)