diff --git a/PKG-INFO b/PKG-INFO index d6bbe9bb..00437a36 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: tqsdk -Version: 3.7.2 +Version: 3.7.3 Summary: TianQin SDK Home-page: https://www.shinnytech.com/tqsdk Author: TianQin diff --git a/doc/advanced/for_vnpy_user.rst b/doc/advanced/for_vnpy_user.rst index e7ee0f05..82b99db3 100644 --- a/doc/advanced/for_vnpy_user.rst +++ b/doc/advanced/for_vnpy_user.rst @@ -31,9 +31,7 @@ TqSdk 则使用基于网络协作的组件设计. 如下图: * 交易相关接口被大幅度简化, 不再需要处理CTP接口的复杂回调, 也不需要发起任何查询请求 -也有一些不如vn.py方便的地方: - -* 由于交易指令经交易网关转发, 用户无法直接指定CTP服务器地址. 用户如果需要连接到官方交易网关不支持的期货公司, 需要自行部署交易网关. +对于需要直连期货公司交易的用户, TqSdk 也提供了 :py:meth:`~tqsdk.TqCtp` 模块支持用户直连 每个策略是一个单独运行的py文件 @@ -260,13 +258,12 @@ TqSdk配合web_gui使用时, 还支持自定义绘制行情图表, 像这样:: 关于策略回测的详细说明, 请见 :ref:`backtest` -其它区别 -------------------------------------------------- -此外, 还有一些差别值得注意 - -* TqSdk 要求 Python 3.6.4 以上版本, 不支持 Python 2.x -* TqSdk 使用了Python3的async框架, 某些 IDE 不支持, 需要使用支持 async 的IDE, 例如 pycharm - +推荐学习步骤 +------------------------------- 要学习使用 TqSdk, 推荐从 :ref:`quickstart` 开始 +使用过程中有任何问题可以 `询问天勤 AI 助手! `_ ,尝试帮助解答用户以下问题: +* 具体函数的详细介绍 +* 根据具体需求或策略提供天勤实现的示例 +* 天勤或 Python 报错的可能解决方案 diff --git a/doc/conf.py b/doc/conf.py index 810411a4..618e3046 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -48,9 +48,9 @@ # built documents. # # The short X.Y version. -version = u'3.7.2' +version = u'3.7.3' # The full version, including alpha/beta/rc tags. -release = u'3.7.2' +release = u'3.7.3' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/doc/enterprise.rst b/doc/enterprise.rst index a78754f5..e6755c87 100644 --- a/doc/enterprise.rst +++ b/doc/enterprise.rst @@ -1,74 +1,45 @@ .. _enterprise: -TqSdk2 企业版 +TqSdk 企业版 ================================================= -除了 TqSdk 专业版以外,我们还提供 TqSdk2 企业版本来供用户使用,如果想了解专业版和企业版的区别,`可以点击查看 TqSdk2 文档 `_ +除了 TqSdk 专业版以外,我们还提供 TqSdk 企业版本 -如果想使用 TqSdk2 企业版功能,可以点击 `个人中心 `_ 申请15天试用或购买 +企业版和专业版相比的主要区别是柜台支持上的区别,企业版支持直连 CTP/融航/杰宜斯等柜台,专业版只能通过中继的方式去进行连接 -企业版本提供专业版的全部功能 :ref:`profession` ,且 TqSdk 和 TqSdk2 专业版权限通用,此外还包含如下功能 +如果想使用 TqSdk 企业版功能,可以点击 `个人中心 `_ 申请15天试用或购买 -TqSdk2 直连功能 + +TqSdk 直连功能 ------------------------------------------------- -在 TqSdk2 中除了通过中继模式接入期货公司以外,还提供用户通过直连模式接入任意一家指定期货公司 +在 TqSdk 企业版支持用户通过直连模式接入任意一家指定期货公司 除了接入指定期货公司的优点以外,直连模式还带来了一下好处: * 交易指令直达期货公司,省去中继服务器路径,交易延迟平均减少10ms左右 * 减少了交易服务器依赖,程序运行稳定性提升 +TqSdk 直连CTP模式的详细介绍,请点击 :py:class:`~tqsdk.TqCtp` -.. _tqjees: - -TqSdk2 连接资管平台功能 -------------------------------------------------- -TqSdk2 提供了资管平台的对接支持,支持用户连接到指定资管平台 - -以连接杰宜斯的模拟服务器为例:: - - from tqsdk2 import TqApi, TqAuth, TqJees - - acc = TqJees(td_url="tcp://129.211.138.170:10001", broker_id="JeesDemo", app_id="shinny_tqsdk_01", auth_code= "0000000000000000", user_name="杰宜斯模拟账户", password="杰宜斯模拟账户密码") - api = TqApi(acc,auth= TqAuth("快期账户","账户密码")) - -其中杰宜斯的 **模拟账户** 和 **模拟账户密码** 需要自行和杰宜斯联系获取,其他参数在杰宜斯模拟下为 - -td_url="tcp://39.101.174.218:40205" -broker_id="JeesDemo" - -app_id="shinny_tqsdk_01" - -auth_code="0000000000000000" - -杰宜斯实盘情况下将对应信息换成实盘信息即可 - -资管平台连接模式的详细介绍,请点击 :py:class:`~tqsdk2.api.TqJees` . - - -.. _tqrohon: +.. _tqjees: -TqSdk2 连接资管平台功能 +TqSdk 连接平台功能 ------------------------------------------------- -TqSdk2 提供了资管平台的对接支持,支持用户连接到指定资管平台 - -以连接融航的模拟服务器为例:: - - from tqsdk2 import TqApi, TqAuth, TqRohon +TqSdk 提供了资管平台的对接支持,支持用户连接到指定资管平台,例如杰宜斯或者融航资管系统等 - acc = TqRohon(td_url="tcp://129.211.138.170:10001", broker_id="RohonDemo", app_id="shinny_tqsdk_01", auth_code= "qZWmA7iTXaEO2w40", user_name="融航模拟账户", password="融航模拟账户密码") - api = TqApi(acc,auth= TqAuth("快期账户","账户密码")) +以连融航的模拟服务器为例:: -其中融航模拟的 **模拟账户** 和 **模拟账户密码** 需要自行和融航联系获取,其他参数在融航模拟下为 + from tqsdk import TqApi, TqRohon, TqAuth -td_url="tcp://129.211.138.170:10001" + account = TqRohon(account_id="融航账户", password="融航密码", front_broker="融航柜台代码", front_url="融航柜台地址", app_id="融航 AppID", auth_code="融航 AuthCode") + api = TqApi(account, auth=TqAuth("快期账户", "账户密码")) -broker_id="RohonDemo" +其中融航的 **模拟账户** 、 **模拟账户密码** 、 **app_id** 和 **auth_code** 需要自行和融航联系获取,其他参数在融航模拟下为 -app_id="shinny_tqsdk_01" +front_url="tcp://129.211.138.170:10001" -auth_code="qZWmA7iTXaEO2w40" +front_broker="RohonDemo" 融航实盘情况下将对应信息换成实盘信息即可 -资管平台连接模式的详细介绍,请点击 :py:class:`~tqsdk2.api.TqRohon` . +融航资管平台连接模式的详细介绍,请点击 :py:class:`~tqsdk.TqRohon` diff --git a/doc/reference/index.rst b/doc/reference/index.rst index 7b58e835..b66f475e 100644 --- a/doc/reference/index.rst +++ b/doc/reference/index.rst @@ -13,6 +13,8 @@ TqSdk 模块参考 tqsdk.tqzq.rst tqsdk.tqctp.rst tqsdk.tqrohon.rst + tqsdk.tqjees.rst + tqsdk.tqyida.rst tqsdk.sim.rst tqsdk.multiaccount.rst tqsdk.objs.rst diff --git a/doc/reference/tqsdk.tqjees.rst b/doc/reference/tqsdk.tqjees.rst new file mode 100644 index 00000000..35a0dd5d --- /dev/null +++ b/doc/reference/tqsdk.tqjees.rst @@ -0,0 +1,7 @@ +.. _tqsdk.tqjees: + +tqsdk.TqJees - 杰宜斯资管交易类 +------------------------------------------------------------------ +.. autoclass:: tqsdk.TqJees + :members: + :inherited-members: diff --git a/doc/reference/tqsdk.tqyida.rst b/doc/reference/tqsdk.tqyida.rst new file mode 100644 index 00000000..0dda1127 --- /dev/null +++ b/doc/reference/tqsdk.tqyida.rst @@ -0,0 +1,7 @@ +.. _tqsdk.tqyida: + +tqsdk.TqYida - 易达交易类 +------------------------------------------------------------------ +.. autoclass:: tqsdk.TqYida + :members: + :inherited-members: diff --git a/doc/tqsdk_llm.rst b/doc/tqsdk_llm.rst index 015d51a6..3030a6e5 100644 --- a/doc/tqsdk_llm.rst +++ b/doc/tqsdk_llm.rst @@ -22,7 +22,7 @@ * 根据具体需求或策略提供天勤实现的示例 * 天勤或 Python 报错的可能解决方案 -点击即刻尝试 `使用智能机器人! `_ +点击即刻尝试 `使用天勤 AI 助手! `_ 下图是具体的使用示例 demo diff --git a/doc/version.rst b/doc/version.rst index 9e573f5f..ef978df8 100644 --- a/doc/version.rst +++ b/doc/version.rst @@ -2,6 +2,12 @@ 版本变更 ============================= +3.7.3 (2024/09/20) + +* 新增::py:class:`~tqsdk.TqJees` 账户类型,支持杰宜斯资管柜台 +* 新增::py:class:`~tqsdk.TqYida` 账户类型,支持易达交易柜台 + + 3.7.2 (2024/09/12) * 新增::py:class:`~tqsdk.TqRohon` 账户类型,支持融航资管柜台 diff --git a/setup.py b/setup.py index 570a32ab..eb38e041 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='tqsdk', - version="3.7.2", + version="3.7.3", description='TianQin SDK', author='TianQin', author_email='tianqincn@gmail.com', diff --git a/tqsdk/__init__.py b/tqsdk/__init__.py index 442e2af3..2dd63bae 100644 --- a/tqsdk/__init__.py +++ b/tqsdk/__init__.py @@ -4,7 +4,7 @@ name = "tqsdk" from tqsdk.api import TqApi -from tqsdk.tradeable import TqAccount, TqZq, TqKq, TqKqStock, TqSim, TqSimStock, TqCtp, TqRohon +from tqsdk.tradeable import TqAccount, TqZq, TqKq, TqKqStock, TqSim, TqSimStock, TqCtp, TqRohon, TqJees, TqYida from tqsdk.auth import TqAuth from tqsdk.channel import TqChan from tqsdk.backtest import TqBacktest, TqReplay diff --git a/tqsdk/__version__.py b/tqsdk/__version__.py index 368b1f26..87c08592 100644 --- a/tqsdk/__version__.py +++ b/tqsdk/__version__.py @@ -1 +1 @@ -__version__ = '3.7.2' +__version__ = '3.7.3' diff --git a/tqsdk/api.py b/tqsdk/api.py index 0a061ae2..5795e8d6 100644 --- a/tqsdk/api.py +++ b/tqsdk/api.py @@ -72,7 +72,7 @@ from tqsdk.risk_rule import TqRiskRule from tqsdk.ins_schema import ins_schema, basic, derivative, future, option from tqsdk.symbols import TqSymbols -from tqsdk.tradeable import TqAccount, TqZq, TqKq, TqKqStock, TqSim, TqSimStock, BaseSim, BaseOtg, TqCtp, TqRohon +from tqsdk.tradeable import TqAccount, TqZq, TqKq, TqKqStock, TqSim, TqSimStock, BaseSim, BaseOtg, TqCtp, TqRohon, TqJees, TqYida from tqsdk.trading_status import TqTradingStatus from tqsdk.tqwebhelper import TqWebHelper from tqsdk.utils import _generate_uuid, _query_for_quote, BlockManagerUnconsolidated, _quotes_add_night, _bisect_value, \ @@ -82,7 +82,7 @@ from .__version__ import __version__ -UnionTradeable = Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqCtp, TqRohon] +UnionTradeable = Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqCtp, TqRohon, TqJees, TqYida] class TqApi(TqBaseApi): @@ -121,8 +121,13 @@ def __init__(self, account: Optional[Union[TqMultiAccount, UnionTradeable]] = No * :py:class:`~tqsdk.TqRohon` : 使用融航资管账号 + * :py:class:`~tqsdk.TqJees` : 使用杰宜斯资管账号 + + * :py:class:`~tqsdk.TqYida` : 使用易达账号 + * :py:class:`~tqsdk.TqMultiAccount` : 多账户列表,列表中支持 :py:class:`~tqsdk.TqAccount`、:py:class:`~tqsdk.TqKq`、:py:class:`~tqsdk.TqKqStock`、\ - :py:class:`~tqsdk.TqSim`、:py:class:`~tqsdk.TqSimStock`、:py:class:`~tqsdk.TqZq`、:py:class:`~tqsdk.TqRohon` 和 :py:class:`~tqsdk.TqCtp` 中的 0 至 N 个或者组合 + :py:class:`~tqsdk.TqSim`、:py:class:`~tqsdk.TqSimStock`、:py:class:`~tqsdk.TqZq`、:py:class:`~tqsdk.TqRohon`、:py:class:`~tqsdk.TqJees`、\ + :py:class:`~tqsdk.TqYida` 和 :py:class:`~tqsdk.TqCtp` 中的 0 至 N 个或者组合 auth (TqAuth/str): [必填]用户快期账户: * :py:class:`~tqsdk.TqAuth` : 添加快期账户类,例如:TqAuth("tianqin@qq.com", "123456") diff --git a/tqsdk/multiaccount.py b/tqsdk/multiaccount.py index 53fe1a19..261d0b2e 100644 --- a/tqsdk/multiaccount.py +++ b/tqsdk/multiaccount.py @@ -8,7 +8,7 @@ from shinny_structlog import ShinnyLoggerAdapter from tqsdk.channel import TqChan -from tqsdk.tradeable import TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, BaseSim, TqZq, TqCtp, TqRohon +from tqsdk.tradeable import TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, BaseSim, TqZq, TqCtp, TqRohon, TqJees, TqYida from tqsdk.tradeable.mixin import StockMixin @@ -27,12 +27,12 @@ class TqMultiAccount(object): """ - def __init__(self, accounts: Optional[List[Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp, TqRohon]]] = None): + def __init__(self, accounts: Optional[List[Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp, TqRohon, TqJees, TqYida]]] = None): """ 创建 TqMultiAccount 实例 Args: - accounts (List[Union[TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp, TqRohon]]): [可选] 多账户列表, 若未指定任何账户, 则为 [TqSim()] + accounts (List[Union[TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp, TqRohon, TqJees, TqYida]]): [可选] 多账户列表, 若未指定任何账户, 则为 [TqSim()] Example1:: diff --git a/tqsdk/tradeable/__init__.py b/tqsdk/tradeable/__init__.py index 35c2b810..deae558d 100644 --- a/tqsdk/tradeable/__init__.py +++ b/tqsdk/tradeable/__init__.py @@ -5,6 +5,6 @@ from tqsdk.tradeable.otg.base_otg import BaseOtg -from tqsdk.tradeable.otg import TqAccount, TqZq, TqKq, TqKqStock, TqCtp, TqRohon +from tqsdk.tradeable.otg import TqAccount, TqZq, TqKq, TqKqStock, TqCtp, TqRohon, TqJees, TqYida from tqsdk.tradeable.sim.basesim import BaseSim from tqsdk.tradeable.sim import TqSim, TqSimStock diff --git a/tqsdk/tradeable/otg/__init__.py b/tqsdk/tradeable/otg/__init__.py index f3b9697f..7d7a543e 100644 --- a/tqsdk/tradeable/otg/__init__.py +++ b/tqsdk/tradeable/otg/__init__.py @@ -8,3 +8,5 @@ from tqsdk.tradeable.otg.tqkq import TqKq, TqKqStock from tqsdk.tradeable.otg.tqctp import TqCtp from tqsdk.tradeable.otg.tqrohon import TqRohon +from tqsdk.tradeable.otg.tqjees import TqJees +from tqsdk.tradeable.otg.tqyida import TqYida diff --git a/tqsdk/tradeable/otg/tqjees.py b/tqsdk/tradeable/otg/tqjees.py new file mode 100644 index 00000000..75719223 --- /dev/null +++ b/tqsdk/tradeable/otg/tqjees.py @@ -0,0 +1,75 @@ +#!usr/bin/env python3 +# -*- coding:utf-8 -*- +__author__ = 'chenli' + +import hashlib + +from tqsdk.tradeable.otg.base_otg import BaseOtg +from tqsdk.tradeable.mixin import FutureMixin + + +class TqJees(BaseOtg, FutureMixin): + """杰宜斯资管账户类""" + + def __init__(self, account_id: str, password: str, front_broker: str, front_url: str, app_id: str, auth_code: str) -> None: + """ + 创建杰宜斯资管账户实例 + + Args: + account_id (str): 帐号 + + password (str): 密码 + + front_broker (str): 杰宜斯柜台代码 + + front_url (str): 杰宜斯柜台地址 + + app_id (str): 杰宜斯 AppID + + auth_code (str): 杰宜斯 AuthCode + + Example1:: + + from tqsdk import TqApi, TqJees + account = TqJees(account_id="杰宜斯账户", password="杰宜斯密码", front_broker="杰宜斯柜台代码", front_url="杰宜斯柜台地址", app_id="杰宜斯 AppID", auth_code="杰宜斯 AuthCode") + api = TqApi(account, auth=TqAuth("快期账户", "账户密码")) + + 注意: + 1. 使用 TqJees 账户需要安装 tqsdk_zq_otg 包: pip install -U tqsdk_zq_otg + 2. front_broker, front_url, app_id 和 auth_code 信息需要向杰宜斯申请程序化外接后取得 + + """ + self._account_id = account_id + self._front_broker = front_broker + self._front_url = front_url + self._app_id = app_id + self._auth_code = auth_code + super(TqJees, self).__init__(broker_id="", account_id=account_id, password=password, td_url="zqotg://127.0.0.1:0/trade") + + @property + def _account_auth(self): + return { + "feature": "tq_direct", + "account_id": self._account_id, + "auto_add": True, + } + + def _get_account_key(self): + s = self._broker_id + self._account_id + s += self._front_broker if self._front_broker else "" + s += self._front_url if self._front_url else "" + return hashlib.md5(s.encode('utf-8')).hexdigest() + + async def _send_login_pack(self): + req = { + "aid": "req_login", + "bid": "tqsdk_zq_otg", + "user_name": self._account_id, + "password": self._password, + "broker_id": self._front_broker, + "front": self._front_url, + "app_id": self._app_id, + "auth_code": self._auth_code, + "backend": "jees" + } + await self._td_send_chan.send(req) diff --git a/tqsdk/tradeable/otg/tqyida.py b/tqsdk/tradeable/otg/tqyida.py new file mode 100644 index 00000000..2638b94c --- /dev/null +++ b/tqsdk/tradeable/otg/tqyida.py @@ -0,0 +1,71 @@ +#!usr/bin/env python3 +# -*- coding:utf-8 -*- +__author__ = 'chenli' + +import hashlib + +from tqsdk.tradeable.otg.base_otg import BaseOtg +from tqsdk.tradeable.mixin import FutureMixin + + +class TqYida(BaseOtg, FutureMixin): + """易达账户类""" + + def __init__(self, account_id: str, password: str, front_url: str, app_id: str, auth_code: str) -> None: + """ + 创建易达账户实例 + + Args: + account_id (str): 帐号 + + password (str): 密码 + + front_url (str): 易达柜台地址 + + app_id (str): 易达 AppID + + auth_code (str): 易达 AuthCode + + Example1:: + + from tqsdk import TqApi, TqYida + account = TqYida(account_id="易达账户", password="易达密码", front_url="易达柜台地址", app_id="易达 AppID", auth_code="易达 AuthCode") + api = TqApi(account, auth=TqAuth("快期账户", "账户密码")) + + 注意: + 1. 使用 TqYida 账户需要安装 tqsdk_zq_otg 包: pip install -U tqsdk_zq_otg + 2. front_url, app_id 和 auth_code 信息需要向易达申请程序化外接后取得 + + """ + self._account_id = account_id + self._front_url = front_url + self._app_id = app_id + self._auth_code = auth_code + super(TqYida, self).__init__(broker_id="", account_id=account_id, password=password, td_url="zqotg://127.0.0.1:0/trade") + + @property + def _account_auth(self): + return { + "feature": "tq_direct", + "account_id": self._account_id, + "auto_add": True, + } + + def _get_account_key(self): + s = self._broker_id + self._account_id + s += self._front_url if self._front_url else "" + return hashlib.md5(s.encode('utf-8')).hexdigest() + + async def _send_login_pack(self): + req = { + "aid": "req_login", + "bid": "tqsdk_zq_otg", + "user_name": self._account_id, + "password": self._password, + "broker_id": "", + "front": self._front_url, + "app_id": self._app_id, + "auth_code": self._auth_code, + "backend": "yida" + } + await self._td_send_chan.send(req)