Skip to content

Commit

Permalink
Update Version 3.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
shinny-hongyan authored and shinny-chenli committed Sep 20, 2024
1 parent 3ab4cf1 commit a24d884
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 20 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.1
Version: 3.7.2
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.1'
version = u'3.7.2'
# The full version, including alpha/beta/rc tags.
release = u'3.7.1'
release = u'3.7.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1 change: 1 addition & 0 deletions doc/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ TqSdk 模块参考
tqsdk.tqkq.rst
tqsdk.tqzq.rst
tqsdk.tqctp.rst
tqsdk.tqrohon.rst
tqsdk.sim.rst
tqsdk.multiaccount.rst
tqsdk.objs.rst
Expand Down
7 changes: 7 additions & 0 deletions doc/reference/tqsdk.tqrohon.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _tqsdk.tqrohon:

tqsdk.TqRohon - 融航资管交易类
------------------------------------------------------------------
.. autoclass:: tqsdk.TqRohon
:members:
:inherited-members:
6 changes: 6 additions & 0 deletions doc/version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

版本变更
=============================
3.7.2 (2024/09/12)

* 新增::py:class:`~tqsdk.TqRohon` 账户类型,支持融航资管柜台
* BREAKING:从安装依赖中移除 tqsdk_zq_otg 模块,用户使用多柜台需要手动安装依赖包:``pip install -U tqsdk_zq_otg``


3.7.1 (2024/08/29)

* 修复:在 Windows 系统上使用 :py:class:`~tqsdk.TqCtp` 账户导致多 TqApi 实例无法运行的问题
Expand Down
4 changes: 2 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.1",
version="3.7.2",
description='TianQin SDK',
author='TianQin',
author_email='[email protected]',
Expand All @@ -18,7 +18,7 @@
packages=setuptools.find_packages(exclude=["tqsdk.test", "tqsdk.test.*"]),
python_requires='>=3.6.4',
install_requires=["websockets>=8.1", "requests", "numpy", "pandas>=1.1.0", "scipy", "simplejson", "aiohttp",
"certifi", "pyjwt", "psutil", "shinny_structlog", "sgqlc", "filelock", "tqsdk_ctpse", "tqsdk_sm", "tqsdk_zq_otg==1.1.1"],
"certifi", "pyjwt", "psutil", "shinny_structlog", "sgqlc", "filelock", "tqsdk_ctpse", "tqsdk_sm"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name = "tqsdk"

from tqsdk.api import TqApi
from tqsdk.tradeable import TqAccount, TqZq, TqKq, TqKqStock, TqSim, TqSimStock, TqCtp
from tqsdk.tradeable import TqAccount, TqZq, TqKq, TqKqStock, TqSim, TqSimStock, TqCtp, TqRohon
from tqsdk.auth import TqAuth
from tqsdk.channel import TqChan
from tqsdk.backtest import TqBacktest, TqReplay
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.1'
__version__ = '3.7.2'
8 changes: 5 additions & 3 deletions tqsdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from tqsdk.tradeable import TqAccount, TqZq, TqKq, TqKqStock, TqSim, TqSimStock, BaseSim, BaseOtg, TqCtp, TqRohon
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, \
Expand All @@ -82,7 +82,7 @@
from .__version__ import __version__


UnionTradeable = Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqCtp]
UnionTradeable = Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqCtp, TqRohon]


class TqApi(TqBaseApi):
Expand Down Expand Up @@ -119,8 +119,10 @@ def __init__(self, account: Optional[Union[TqMultiAccount, UnionTradeable]] = No
* :py:class:`~tqsdk.TqCtp` : 使用直连 CTP 账号
* :py:class:`~tqsdk.TqRohon` : 使用融航资管账号
* :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.TqCtp` 中的 0 至 N 个或者组合
:py:class:`~tqsdk.TqSim`、:py:class:`~tqsdk.TqSimStock`、:py:class:`~tqsdk.TqZq`、:py:class:`~tqsdk.TqRohon` 和 :py:class:`~tqsdk.TqCtp` 中的 0 至 N 个或者组合
auth (TqAuth/str): [必填]用户快期账户:
* :py:class:`~tqsdk.TqAuth` : 添加快期账户类,例如:TqAuth("[email protected]", "123456")
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def _run(self, api, url, send_chan, recv_chan):
url_info = url_info._replace(scheme="ws", path="/".join(sm_info[:1]+sm_info[4:]))
elif url_info.scheme.startswith("zqotg"):
url_info = url_info._replace(scheme="ws")
cm = ZqOtgContext()
cm = ZqOtgContext(self._api)

count = 0
async with cm:
Expand Down
6 changes: 3 additions & 3 deletions tqsdk/multiaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from tqsdk.tradeable import TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, BaseSim, TqZq, TqCtp, TqRohon
from tqsdk.tradeable.mixin import StockMixin


Expand All @@ -27,12 +27,12 @@ class TqMultiAccount(object):
"""

def __init__(self, accounts: Optional[List[Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp]]] = None):
def __init__(self, accounts: Optional[List[Union[TqAccount, TqKq, TqZq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp, TqRohon]]] = None):
"""
创建 TqMultiAccount 实例
Args:
accounts (List[Union[TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp]]): [可选] 多账户列表, 若未指定任何账户, 则为 [TqSim()]
accounts (List[Union[TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, TqZq, TqCtp, TqRohon]]): [可选] 多账户列表, 若未指定任何账户, 则为 [TqSim()]
Example1::
Expand Down
2 changes: 1 addition & 1 deletion tqsdk/tradeable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@


from tqsdk.tradeable.otg.base_otg import BaseOtg
from tqsdk.tradeable.otg import TqAccount, TqZq, TqKq, TqKqStock, TqCtp
from tqsdk.tradeable.otg import TqAccount, TqZq, TqKq, TqKqStock, TqCtp, TqRohon
from tqsdk.tradeable.sim.basesim import BaseSim
from tqsdk.tradeable.sim import TqSim, TqSimStock
1 change: 1 addition & 0 deletions tqsdk/tradeable/otg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from tqsdk.tradeable.otg.tqzq import TqZq
from tqsdk.tradeable.otg.tqkq import TqKq, TqKqStock
from tqsdk.tradeable.otg.tqctp import TqCtp
from tqsdk.tradeable.otg.tqrohon import TqRohon
4 changes: 4 additions & 0 deletions tqsdk/tradeable/otg/tqctp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def __init__(self, account_id: str, password: str, front_broker: str, front_url:
account = TqCtp(account_id="CTP 账户", password="CTP 密码", front_broker="CTP 柜台代码", front_url="CTP 柜台地址", app_id="CTP AppID", auth_code="CTP AuthCode")
api = TqApi(account, auth=TqAuth("快期账户", "账户密码"))
注意:
1. 使用 TqCtp 账户需要安装 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
Expand Down
75 changes: 75 additions & 0 deletions tqsdk/tradeable/otg/tqrohon.py
Original file line number Diff line number Diff line change
@@ -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 TqRohon(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, TqRohon
account = TqRohon(account_id="融航账户", password="融航密码", front_broker="融航柜台代码", front_url="融航柜台地址", app_id="融航 AppID", auth_code="融航 AuthCode")
api = TqApi(account, auth=TqAuth("快期账户", "账户密码"))
注意:
1. 使用 TqRohon 账户需要安装 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(TqRohon, 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": "rohon"
}
await self._td_send_chan.send(req)
15 changes: 10 additions & 5 deletions tqsdk/zq_otg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import json
import os
import tempfile
import signal
import sys
import subprocess
import contextlib
from pathlib import Path
from asyncio.subprocess import DEVNULL, PIPE

from tqsdk_zq_otg import get_zq_otg_path


class ZqOtgContext(object):
def __init__(self):
def __init__(self, api):
acc_types = ", ".join([type(acc).__name__ for acc in api._account._account_list if acc._account_auth.get("feature") == "tq_direct"])
try:
from tqsdk_zq_otg import __version__ as otg_version
from tqsdk import __version__ as tqsdk_version
from tqsdk_zq_otg import get_zq_otg_path
except ImportError:
raise Exception(f"使用 {acc_types} 账户需要安装 tqsdk_zq_otg 包: pip install -U tqsdk_zq_otg") from None
if otg_version != tqsdk_version:
raise Exception(f"使用 {acc_types} 账户需要更新 tqsdk_zq_otg 包到最新版本: pip install -U tqsdk_zq_otg")
self._zq_otg_path = get_zq_otg_path()
self._zq_otg_exe = str(Path(self._zq_otg_path) / "otg_adapter")
self._zq_otg_env = os.environ.copy()
Expand Down

0 comments on commit a24d884

Please sign in to comment.