Skip to content

Commit

Permalink
Update Version 3.7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
shinny-hongyan authored and shinny-chenli committed Dec 23, 2024
1 parent 573ad22 commit 1adf688
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 64 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.7.4
Version: 3.7.6
Summary: TianQin SDK
Home-page: https://www.shinnytech.com/tqsdk
Author: TianQin
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'3.7.4'
version = u'3.7.6'
# The full version, including alpha/beta/rc tags.
release = u'3.7.4'
release = u'3.7.6'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 0 additions & 2 deletions doc/profession.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ TqSdk 免费版本提供全部的期货、商品/金融期权和上证50、沪
-------------------------------------------------
TqSdk 提供了 :py:class:`~tqsdk.TqKqStock` 方法供用户来进行股票的模拟交易

专业版用户可以长久的对同一账户进行模拟股票交易测试

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

参考代码如下::
Expand Down
17 changes: 14 additions & 3 deletions doc/version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

版本变更
=============================
3.7.6 (2024/11/14)

* 修复: 增加依赖库 packaging


3.7.5 (2024/11/13)

* 修复: 兼容 websockets 14.0 版本
* docs: :py:class:`~tqsdk.TqCtp`、:py:class:`~tqsdk.TqJees`、:py:class:`~tqsdk.TqRohon`、:py:class:`~tqsdk.TqYida` 补充文档 front_url 示例


3.7.4 (2024/10/28)

* 新增:py:class:`~tqsdk.objs.Quote` 增加属性 :py:meth:`~tqsdk.objs.Quote.position_limit`
* 增加: TqApi 增加 :py:meth:`~tqsdk.TqApi.query_symbol_settlement` 接口,支持查询合约每日结算价
* 增加: TqAuth 增加 :py:meth:`~tqsdk.TqAuth.expire_datetime` 接口,支持查询快期账户授权到期时间
* 新增: :py:class:`~tqsdk.objs.Quote` 增加 :py:class:`~tqsdk.objs.Quote.position_limit` 属性,返回合约持仓限额
* 增加: :py:class:`~tqsdk.TqApi` 增加 :py:meth:`~tqsdk.TqApi.query_symbol_settlement` 接口,支持查询合约每日结算价
* 增加: :py:class:`~tqsdk.TqAuth` 增加 :py:class:`~tqsdk.TqAuth.expire_datetime` 属性,返回快期账户授权到期时间
* 自该版本起仅支持 Python >=3.7

3.7.3 (2024/09/20)
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='tqsdk',
version="3.7.4",
version="3.7.6",
description='TianQin SDK',
author='TianQin',
author_email='[email protected]',
Expand All @@ -18,7 +18,8 @@
packages=setuptools.find_packages(exclude=["tqsdk.test", "tqsdk.test.*"]),
python_requires='>=3.7',
install_requires=["websockets>=8.1", "requests", "numpy", "pandas>=1.1.0", "scipy", "simplejson", "aiohttp",
"certifi", "pyjwt", "psutil>=5.9.6", "shinny_structlog", "sgqlc", "filelock", "tqsdk_ctpse", "tqsdk_sm"],
"certifi", "pyjwt", "psutil>=5.9.6", "shinny_structlog", "sgqlc", "filelock", "tqsdk_ctpse", "tqsdk_sm",
"packaging"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
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.7.4'
__version__ = '3.7.6'
4 changes: 0 additions & 4 deletions tqsdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2312,8 +2312,6 @@ def query_symbol_settlement(self, symbol: Union[str, List[str]], days: int = 1,
"""
查询交易所合约每日结算价
本接口仅限专业版用户使用,如需购买专业版或者申请试用,请访问 https://www.shinnytech.com/tqsdk_professional/。
该函数返回的对象不会更新,不建议在循环内调用该方法。
Args:
Expand Down Expand Up @@ -2385,8 +2383,6 @@ def query_symbol_ranking(self, symbol: str, ranking_type: str, days: int = 1, st
"""
查询合约成交排名/持仓排名
本接口仅限专业版用户使用,如需购买专业版或者申请试用,请访问 https://www.shinnytech.com/tqsdk-buy/。
该函数返回的对象不会更新,不建议在循环内调用该方法。
Args:
Expand Down
70 changes: 25 additions & 45 deletions tqsdk/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import certifi
import websockets
import websockets.exceptions
from packaging import version
from shinny_structlog import ShinnyLoggerAdapter

from tqsdk.datetime import _cst_now
Expand All @@ -42,6 +44,9 @@
"""


websocket_version_ge_14 = version.parse(websockets.__version__) >= version.parse("14.0")


class ReconnectTimer(object):

def __init__(self):
Expand All @@ -54,42 +59,17 @@ def set_count(self, count):
self.timer = time.time() + random.uniform(seconds, seconds * 2)


class TqStreamReader(asyncio.StreamReader):

def __init__(self, *args, **kwargs):
super(TqStreamReader, self).__init__(*args, **kwargs)
self._start_read_message = None
self._read_size = 0

async def readexactly(self, n):
data = await super(TqStreamReader, self).readexactly(n)
if not self._start_read_message:
self._start_read_message = time.time()
self._read_size += n
return data


class TqWebSocketClientProtocol(websockets.WebSocketClientProtocol):

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://www.shinnytech.com/tqsdk-buy/") from None
raise

async def read_message(self):
message = await super().read_message()
self.reader._start_read_message = None
self.reader._read_size = 0
return message
if websocket_version_ge_14:
# https://websockets.readthedocs.io/en/stable/reference/exceptions.html#module-websockets.exceptions
websocket_expect_exc = (
websockets.exceptions.ConnectionClosedError, websockets.exceptions.InvalidHandshake, websockets.exceptions.InvalidURI,
websockets.exceptions.InvalidState, websockets.exceptions.ProtocolError
)
else:
websocket_expect_exc = (
websockets.exceptions.ConnectionClosed, websockets.exceptions.InvalidStatusCode, websockets.exceptions.InvalidURI,
websockets.exceptions.InvalidState, websockets.exceptions.ProtocolError
)


class TqConnect(object):
Expand Down Expand Up @@ -117,8 +97,14 @@ async def _run(self, api, url, send_chan, recv_chan):
self._subscribed_per_seconds = 100 # 每秒 subscribe_quote 请求次数限制
self._subscribed_queue = Queue(self._subscribed_per_seconds)

self._keywords["extra_headers"] = self._api._base_headers
self._keywords["create_protocol"] = TqWebSocketClientProtocol
# websockets 14.0版本升级后用法有变化
if websocket_version_ge_14:
# https://websockets.readthedocs.io/en/stable/howto/upgrade.html#arguments-of-connect
self._keywords["additional_headers"] = self._api._base_headers
self._keywords["user_agent_header"] = None # self._api._base_headers 里面已经包含了 "User-Agent"
self._keywords["process_exception"] = lambda exc: exc
else:
self._keywords["extra_headers"] = self._api._base_headers
url_info = urlparse(url)
cm = NullContext()
if url_info.scheme == "wss":
Expand Down Expand Up @@ -198,16 +184,10 @@ async def _run(self, api, url, send_chan, recv_chan):
self._logger.debug("websocket received data", pack=msg)
await recv_chan.send(pack)
finally:
self._logger.debug("websocket connection info", current_time=time.time(),
start_read_message=client.reader._start_read_message,
read_size=client.reader._read_size)
await self._api._cancel_task(send_task)
# 希望做到的效果是遇到网络问题可以断线重连, 但是可能抛出的例外太多了(TimeoutError,socket.gaierror等), 又没有文档或工具可以理出 try 代码中所有可能遇到的例外
# 而这里的 except 又需要处理所有子函数及子函数的子函数等等可能抛出的例外, 因此这里只能遇到问题之后再补, 并且无法避免 false positive 和 false negative
except (websockets.exceptions.ConnectionClosed, websockets.exceptions.InvalidStatusCode, websockets.exceptions.InvalidURI,
websockets.exceptions.InvalidState, websockets.exceptions.ProtocolError, asyncio.TimeoutError,
OSError, EOFError,
TqBacktestPermissionError) as e:
except websocket_expect_exc + (asyncio.TimeoutError, OSError, EOFError, TqBacktestPermissionError) as e:
in_ops_time = _cst_now().hour == 19 and 0 <= _cst_now().minute <= 30
# 发送网络连接断开的通知,code = 2019112911
notify_id = _generate_uuid()
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/tradeable/otg/tqctp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, account_id: str, password: str, front_broker: str, front_url:
front_broker (str): CTP 柜台代码
front_url (str): CTP 柜台地址
front_url (str): CTP 柜台地址,格式为 tcp://ip:port,如 tcp://129.211.138.170:10001
app_id (str): CTP AppID
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/tradeable/otg/tqjees.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, account_id: str, password: str, front_broker: str, front_url:
front_broker (str): 杰宜斯柜台代码
front_url (str): 杰宜斯柜台地址
front_url (str): 杰宜斯柜台地址,格式为 tcp://ip:port,如 tcp://129.211.138.170:10001
app_id (str): 杰宜斯 AppID
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/tradeable/otg/tqrohon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, account_id: str, password: str, front_broker: str, front_url:
front_broker (str): 融航柜台代码
front_url (str): 融航柜台地址
front_url (str): 融航柜台地址,格式为 tcp://ip:port,如 tcp://129.211.138.170:10001
app_id (str): 融航 AppID
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/tradeable/otg/tqyida.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, account_id: str, password: str, front_url: str, app_id: str,
password (str): 密码
front_url (str): 易达柜台地址
front_url (str): 易达柜台地址,格式为 tcp://ip:port,如 tcp://129.211.138.170:10001
app_id (str): 易达 AppID
Expand Down

0 comments on commit 1adf688

Please sign in to comment.