Skip to content

Commit

Permalink
Update Version 3.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
shinny-pack authored and shinny-mayanqiong committed Aug 11, 2023
1 parent a62dd2e commit a9726de
Show file tree
Hide file tree
Showing 106 changed files with 566 additions and 479 deletions.
4 changes: 2 additions & 2 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: tqsdk
Version: 3.4.5
Version: 3.4.6
Summary: TianQin SDK
Home-page: https://www.shinnytech.com/tqsdk
Author: TianQin
Expand Down Expand Up @@ -34,7 +34,7 @@ TqSdk 是一个由[信易科技](https://www.shinnytech.com)发起并贡献主
``` {.sourceCode .python}
from tqsdk import TqApi, TqAuth, TqAccount, TargetPosTask

api = TqApi(TqAccount("H海通期货", "4003242", "123456"), auth=TqAuth("信易账户", "账户密码")) # 创建 TqApi 实例, 指定交易账户
api = TqApi(TqAccount("H海通期货", "4003242", "123456"), auth=TqAuth("快期账户", "账户密码")) # 创建 TqApi 实例, 指定交易账户
q_1910 = api.get_quote("SHFE.rb1910") # 订阅近月合约行情
t_1910 = TargetPosTask(api, "SHFE.rb1910") # 创建近月合约调仓工具
q_2001 = api.get_quote("SHFE.rb2001") # 订阅远月合约行情
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TqSdk 是一个由[信易科技](https://www.shinnytech.com)发起并贡献主
``` {.sourceCode .python}
from tqsdk import TqApi, TqAuth, TqAccount, TargetPosTask
api = TqApi(TqAccount("H海通期货", "4003242", "123456"), auth=TqAuth("信易账户", "账户密码")) # 创建 TqApi 实例, 指定交易账户
api = TqApi(TqAccount("H海通期货", "4003242", "123456"), auth=TqAuth("快期账户", "账户密码")) # 创建 TqApi 实例, 指定交易账户
q_1910 = api.get_quote("SHFE.rb1910") # 订阅近月合约行情
t_1910 = TargetPosTask(api, "SHFE.rb1910") # 创建近月合约调仓工具
q_2001 = api.get_quote("SHFE.rb2001") # 订阅远月合约行情
Expand Down
4 changes: 2 additions & 2 deletions doc/advanced/backtest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TqSdk 并不提供专门的参数优化机制. 您可以按照自己的需求,
for SHORT in range(20, 40): # 短周期参数从20-40分别做回测
acc = TqSim() # 每次回测都创建一个新的模拟账户
try:
api = TqApi(acc, backtest=TqBacktest(start_dt=date(2019, 5, 6), end_dt=date(2019, 5, 10)), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(acc, backtest=TqBacktest(start_dt=date(2019, 5, 6), end_dt=date(2019, 5, 10)), auth=TqAuth("快期账户", "账户密码"))
account = api.get_account()
klines = api.get_kline_serial(SYMBOL, duration_seconds=60, data_length=LONG + 2)
target_pos = TargetPosTask(api, SYMBOL)
Expand Down Expand Up @@ -51,7 +51,7 @@ TqSdk 并不提供专门的参数优化机制. 您可以按照自己的需求,
SYMBOL = "SHFE.cu1907"
acc = TqSim()
try:
api = TqApi(acc, backtest=TqBacktest(start_dt=date(2019, 5, 6), end_dt=date(2019, 5, 10)), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(acc, backtest=TqBacktest(start_dt=date(2019, 5, 6), end_dt=date(2019, 5, 10)), auth=TqAuth("快期账户", "账户密码"))
data_length = LONG + 2
klines = api.get_kline_serial(SYMBOL, duration_seconds=60, data_length=data_length)
target_pos = TargetPosTask(api, SYMBOL)
Expand Down
2 changes: 1 addition & 1 deletion doc/advanced/dingding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TqSdk 并不提供专门的服务器来推送消息,但是你可以通过其
print(content)


api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
quote = api.get_quote("SHFE.rb2109")
target_pos = TargetPosTask(api, "SHFE.rb2110")
send_msg("策略开始运行")
Expand Down
12 changes: 6 additions & 6 deletions doc/advanced/entry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@ TqApi 独立运行模拟交易
创建 TqApi 实例时传入 TqSim ::

from tqsdk import TqApi, TqAuth, TqSim
api = TqApi(TqSim(), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqSim(), auth=TqAuth("快期账户", "账户密码"))

或者不填其他参数, 默认为使用TqSim::

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))


TqApi 独立运行实盘交易
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
创建 TqApi 实例时传入 TqAccount ::

from tqsdk import TqApi, TqAuth, TqAccount
api = TqApi(TqAccount("H海通期货", "022631", "123456"), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqAccount("H海通期货", "022631", "123456"), auth=TqAuth("快期账户", "账户密码"))

特别的, 如果需要连接到期货公司的特定服务器, 可以在 TqAccount 中指定::

api = TqApi(TqAccount("H海通期货", "022631", "123456", front_broker="8888", front_url="tcp://134.232.123.33:41205"), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqAccount("H海通期货", "022631", "123456", front_broker="8888", front_url="tcp://134.232.123.33:41205"), auth=TqAuth("快期账户", "账户密码"))

如果要连接到自己架设的交易网关, 可以使用::

api = TqApi(TqAccount("H海通期货", "022631", "123456"), url="ws://202.33.21.34:7878/", auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqAccount("H海通期货", "022631", "123456"), url="ws://202.33.21.34:7878/", auth=TqAuth("快期账户", "账户密码"))


TqApi 独立运行回测
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
创建 TqApi 实例时传入 TqBacktest ::

from tqsdk import TqApi, TqAuth, TqSim, TqBacktest
api = TqApi(TqSim(), backtest=TqBacktest(start_dt=date(2018, 5, 1), end_dt=date(2018, 10, 1)), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqSim(), backtest=TqBacktest(start_dt=date(2018, 5, 1), end_dt=date(2018, 10, 1)), auth=TqAuth("快期账户", "账户密码"))


由天勤拉起策略进程
Expand Down
4 changes: 2 additions & 2 deletions doc/advanced/for_ctp_user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Ctp接口按照事件回调模型设计, 使用 CThostFtdcTraderSpi 的 OnXXX
TqSdk则不使用事件回调机制. :py:meth:`~tqsdk.TqApi.wait_update` 函数设计用来获取任意数据更新, 像这样::

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
x = api.insert_order("SHFE.cu1901", direction="BUY", offset="OPEN", volume=1, limit_price=50000)
while True:
Expand All @@ -93,7 +93,7 @@ TqSdk则不使用事件回调机制. :py:meth:`~tqsdk.TqApi.wait_update` 函数

一次 wait_update 可能更新多个实体, 在这种情况下, :py:meth:`~tqsdk.TqApi.is_changing` 被用来判断某个实体是否有变更::

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
q = api.get_quote("SHFE.cu1901")
ks = api.get_kline_serial("SHFE.cu1901", 60)
x = api.insert_order("SHFE.cu1901", direction="BUY", offset="OPEN", volume=1, limit_price=50000)
Expand Down
10 changes: 5 additions & 5 deletions doc/advanced/for_vnpy_user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TqSdk 则使用基于网络协作的组件设计. 如下图:
LONG = 60
SYMBOL = "SHFE.bu1912"

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))

data_length = LONG + 2
klines = api.get_kline_serial(SYMBOL, duration_seconds=60, data_length=data_length)
Expand Down Expand Up @@ -122,7 +122,7 @@ TqSdk将每个策略作为一个独立进程运行, 这样就可以:
当近月-远月的价差大于200时做空近月,做多远月
当价差小于150时平仓
'''
api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
quote_near = api.get_quote("SHFE.rb1910")
quote_deferred = api.get_quote("SHFE.rb2001")
# 创建 rb1910 的目标持仓 task,该 task 负责调整 rb1910 的仓位到指定的目标仓位
Expand Down Expand Up @@ -192,7 +192,7 @@ vn.py按照事件回调模型设计, 使用 CtaTemplate 的 on_xxx 回调函数

TqSdk则不使用事件回调机制. :py:meth:`~tqsdk.TqApi.wait_update` 函数设计用来获取任意数据更新, 像这样::

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
ks = api.get_kline_serial("SHFE.cu1901", 60)
while True:
Expand All @@ -202,7 +202,7 @@ TqSdk则不使用事件回调机制. :py:meth:`~tqsdk.TqApi.wait_update` 函数

一次 wait_update 可能更新多个实体, 在这种情况下, :py:meth:`~tqsdk.TqApi.is_changing` 被用来判断某个实体是否有变更::

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
q = api.get_quote("SHFE.cu1901")
ks = api.get_kline_serial("SHFE.cu1901", 60)
x = api.insert_order("SHFE.cu1901", direction="BUY", offset="OPEN", volume=1, limit_price=50000)
Expand Down Expand Up @@ -235,7 +235,7 @@ TqSdk 提供 :ref:`web_gui` 来供有图形化需求的用户使用:

TqSdk配合web_gui使用时, 还支持自定义绘制行情图表, 像这样::

api = TqApi(auth=TqAuth("信易账户","账户密码"), web_gui=True)
api = TqApi(auth=TqAuth("快期账户","账户密码"), web_gui=True)
# 获取 cu1905 和 cu1906 的日线数据
klines = api.get_kline_serial("SHFE.cu1905", 86400)
klines2 = api.get_kline_serial("SHFE.cu1906", 86400)
Expand Down
6 changes: 3 additions & 3 deletions doc/advanced/multi_strategy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SHORT = 30 # 短周期
LONG = 60 # 长周期

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))

klines = api.get_kline_serial(SYMBOL, duration_seconds=60, data_length=LONG + 2)
target_pos = TargetPosTask(api, SYMBOL)
Expand Down Expand Up @@ -148,7 +148,7 @@ TqSdk(2.6.1 版本)对几个常用接口 :py:meth:`~tqsdk.TqApi.get_quote`,
print(SYMBOL, quote.datetime, quote.last_price)
# ... 策略代码 ...

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
# 为每个合约创建异步任务
api.create_task(demo("SHFE.rb2107"))
api.create_task(demo("DCE.m2109"))
Expand All @@ -162,7 +162,7 @@ TqSdk(2.6.1 版本)对几个常用接口 :py:meth:`~tqsdk.TqApi.get_quote`,
# 协程示例,为每个合约创建 task
from tqsdk import TqApi

api = TqApi(auth=TqAuth("信易账户", "账户密码")) # 构造 api 实例
api = TqApi(auth=TqAuth("快期账户", "账户密码")) # 构造 api 实例

async def demo(SYMBOL, SHORT, LONG):
"""
Expand Down
2 changes: 1 addition & 1 deletion doc/advanced/order.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FIVELEVEL FAK 最优五档即时成交剩余撤销指令

from tqsdk import TqApi, TqAuth

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
# 当日有效限价单
api.insert_order("SHFE.cu2009", "BUY", "OPEN", 3, limit_price=14200)
# FAK 限价单
Expand Down
2 changes: 1 addition & 1 deletion doc/advanced/scheduler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ TargetPosScheduler 执行目标持仓任务列表
from tqsdk import TqApi, TargetPosScheduler
from tqsdk.algorithm import twap_table

api = TqApi(auth="信易账户,用户密码")
api = TqApi(auth="快期账户,用户密码")
quote = api.get_quote("CZCE.MA109")

# 设置 twap 任务参数,
Expand Down
2 changes: 1 addition & 1 deletion doc/advanced/targetpostask2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TargetPosTask 高级功能
from datetime import datetime, time
from tqsdk import TqApi, TargetPosTask

api = TqApi(auth=TqAuth("信易账户", "账户密码"))
api = TqApi(auth=TqAuth("快期账户", "账户密码"))
quote = api.get_quote("SHFE.rb2110")
target_pos_passive = TargetPosTask(api, "SHFE.rb2110", price="PASSIVE")

Expand Down
4 changes: 2 additions & 2 deletions doc/advanced/tqsdk2ctptest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ TqSdk 没有直接提供查询保证金的接口,但是你可以通过使用 T
import tqsdk2

account = tqsdk2.TqCtp(front_url, front_broker, app_id, auth_code, account_id, password)
api_margin = tqsdk2.TqApi(account = account, auth=tqsdk2.TqAuth("信易账户", "账户密码"))
api_margin = tqsdk2.TqApi(account = account, auth=tqsdk2.TqAuth("快期账户", "账户密码"))
rate = api_margin.get_margin_rates("SHFE.cu2201")
print(rate)
api = TqApi(TqAccount("期货公司","账号","密码"),auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqAccount("期货公司","账号","密码"),auth=TqAuth("快期账户", "账户密码"))
quote = api.get_quote("SHFE.cu2201")
while True:
api.wait_update()
Expand Down
6 changes: 3 additions & 3 deletions doc/advanced/unanttended.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TqSdk可以在windows/linux或macosx环境下运行. 无论您选择使用window
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
将每个策略程序配置为独立直连实盘账号. 在创建 TqApi 时, 传入TqAccount实例. 注意期货公司名称需要与天勤中的名称一致::

api = TqApi(TqAccount("H海通期货", "022631", "123456"), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqAccount("H海通期货", "022631", "123456"), auth=TqAuth("快期账户", "账户密码"))


检查策略程序
Expand Down Expand Up @@ -67,7 +67,7 @@ TqSdk可以在windows/linux或macosx环境下运行. 无论您选择使用window

from tqsdk import TqApi, TqAccount

api = TqApi(TqAccount("H海通期货", "0330203", "123456"), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqAccount("H海通期货", "0330203", "123456"), auth=TqAuth("快期账户", "账户密码"))
# 开仓两手并等待完成
order = api.insert_order(symbol="SHFE.rb1901", direction="BUY", offset="OPEN", limit_price=4310,volume=2)
while order.status != "FINISHED":
Expand All @@ -91,7 +91,7 @@ TqSdk可以在windows/linux或macosx环境下运行. 无论您选择使用window
args = parser.parse_args()
print("策略参数为: ", args.user_name, args.symbol)

api = TqApi(TqAccount(args.broker, args.user_name, args.password), auth=TqAuth("信易账户", "账户密码"))
api = TqApi(TqAccount(args.broker, args.user_name, args.password), auth=TqAuth("快期账户", "账户密码"))
# 开仓两手并等待完成
order = api.insert_order(symbol=args.symbol, direction="BUY", offset="OPEN", limit_price=4310,volume=2)
while order.status != "FINISHED":
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.4.5'
version = u'3.4.6'
# The full version, including alpha/beta/rc tags.
release = u'3.4.5'
release = u'3.4.6'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion doc/devtools/drawindex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ATR的计算比较简单,首先我们要算出当前真实的波幅.这里不
from tqsdk import TqApi, TqAuth
from tqsdk.ta import ATR

api = TqApi(TqAuth("信易账户", "账户密码"))
api = TqApi(TqAuth("快期账户", "账户密码"))
klines = api.get_kline_serial("SHFE.au1912", 24 * 60 * 60)
atr = ATR(klines, 14)
print(atr.tr) # 真实波幅
Expand Down
4 changes: 2 additions & 2 deletions doc/devtools/vscode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
然后配置如下信息

* 实盘交易账号(选填)
* 信易账号(必填,没有的话可以前往 :ref:`shinny_account` 注册)
* 快期账号(必填,没有的话可以前往 :ref:`shinny_account` 注册)

.. figure:: ../images/vscode_setting_account.png

Expand Down Expand Up @@ -58,7 +58,7 @@ Vs Code插件策略运行

Vs Code插件回测策略
----------------------------------------------------
回测功能为 TqSdk 专业版功能,如果需要使用 `可以购买专业版或申请试用 <https://www.shinnytech.com/tqsdk_professional/>`_ ,在获得专业版权限后,设置正确的信易账户,我们即可回测自己的策略
回测功能为 TqSdk 专业版功能,如果需要使用 `可以购买专业版或申请试用 <https://www.shinnytech.com/tqsdk_professional/>`_ ,在获得专业版权限后,设置正确的快期账户,我们即可回测自己的策略

右键菜单中提供默认【回测7天】和【回测30天】

Expand Down
4 changes: 2 additions & 2 deletions doc/enterprise.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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("信易账户","账户密码"))
api = TqApi(acc,auth= TqAuth("快期账户","账户密码"))

其中杰宜斯的 **模拟账户** 和 **模拟账户密码** 需要自行和杰宜斯联系获取,其他参数在杰宜斯模拟下为

Expand Down Expand Up @@ -57,7 +57,7 @@ TqSdk2 提供了资管平台的对接支持,支持用户连接到指定资管
from tqsdk2 import TqApi, TqAuth, TqRohon

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("信易账户","账户密码"))
api = TqApi(acc,auth= TqAuth("快期账户","账户密码"))

其中融航模拟的 **模拟账户** 和 **模拟账户密码** 需要自行和融航联系获取,其他参数在融航模拟下为

Expand Down
Binary file added doc/images/how-grafana04.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TqSdk 是一个由 `信易科技 <https://www.shinnytech.com>`_ 发起并贡献

from tqsdk import TqApi, TqAuth, TqAccount, TargetPosTask

api = TqApi(TqAccount("H海通期货", "4003242", "123456"), auth=TqAuth("信易账户", "账户密码")) # 创建 TqApi 实例, 指定交易账户
api = TqApi(TqAccount("H海通期货", "4003242", "123456"), auth=TqAuth("快期账户", "账户密码")) # 创建 TqApi 实例, 指定交易账户
q_1910 = api.get_quote("SHFE.rb1910") # 订阅近月合约行情
t_1910 = TargetPosTask(api, "SHFE.rb1910") # 创建近月合约调仓工具
q_2001 = api.get_quote("SHFE.rb2001") # 订阅远月合约行情
Expand Down
Loading

0 comments on commit a9726de

Please sign in to comment.