Skip to content

Commit

Permalink
Update Version 3.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
shinny-pack authored and shinny-mayanqiong committed Jul 8, 2022
1 parent 6d48354 commit 6b51b4e
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 177 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.2.8
Version: 3.2.9
Summary: TianQin SDK
Home-page: https://www.shinnytech.com/tqsdk
Author: TianQin
Expand Down
56 changes: 1 addition & 55 deletions doc/advanced/multi_strategy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

我们可能需要将这个策略运行多份, 每份的 SYMBOL, LONG, SHORT 都不同.

TqSdk 为这类需求提供三种解决方案, 您可任意选择一种.
TqSdk 为这类需求提供两种解决方案, 您可任意选择一种.


每个进程执行一个策略实例
Expand Down Expand Up @@ -111,60 +111,6 @@ TqSdk 为这类需求提供三种解决方案, 您可任意选择一种.
* 每个策略进程要建立一个单独的服务器连接, 数量过大时可能无法连接成功


单进程中多线程, 每个线程执行一个策略实例
-------------------------------------------------
一般情况下, 我们推荐用户使用上一方案. 仅当用户策略实例很多, 导致网络连接数无法容纳时, 可以考虑使用本方案.

* 首先需要正常创建一个 TqApi 实例 api_master, 并用 TqApi.copy 函数获得多个slave副本
* 启动多个线程, 每个线程中使用一个 TqApi 实例副本.
* 主线程中的 api_master 仍然需要持续调用 wait_update
* 每个线程中的策略代码可以如常工作

示例代码如下::

import threading

class WorkerThread(threading.Thread):
def __init__(self, api, symbol):
threading.Thread.__init__(self)
self.api = api
self.symbol = symbol

def run(self):
SHORT = 30 # 短周期
LONG = 60 # 长周期
data_length = LONG + 2 # k线数据长度
klines = self.api.get_kline_serial(self.symbol, duration_seconds=60, data_length=data_length)
target_pos = TargetPosTask(self.api, self.symbol)

while True:
self.api.wait_update()
if self.api.is_changing(klines.iloc[-1], "datetime"): # 产生新k线:重新计算SMA
short_avg = ma(klines["close"], SHORT) # 短周期
long_avg = ma(klines["close"], LONG) # 长周期
if long_avg.iloc[-2] < short_avg.iloc[-2] and long_avg.iloc[-1] > short_avg.iloc[-1]:
target_pos.set_target_volume(-3)
print("均线下穿,做空")
if short_avg.iloc[-2] < long_avg.iloc[-2] and short_avg.iloc[-1] > long_avg.iloc[-1]:
target_pos.set_target_volume(3)
print("均线上穿,做多")


if __name__ == "__main__":
api_master = TqApi(TqSim())

# Create new threads
thread1 = WorkerThread(api_master.copy(), "SHFE.cu1901")
thread2 = WorkerThread(api_master.copy(), "SHFE.rb1901")

# Start new Threads
thread1.start()
thread2.start()

while True:
api_master.wait_update()


.. _multi_async_task:

单线程创建多个异步任务
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.2.8'
version = u'3.2.9'
# The full version, including alpha/beta/rc tags.
release = u'3.2.8'
release = u'3.2.9'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
10 changes: 10 additions & 0 deletions doc/version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

版本变更
=============================
3.2.9 (2022/07/07)

* 增加:下载 tick 数据时增加 average 列
* 增加::py:meth:`~tqsdk.TqApi.get_tick_data_series` 接口返回值中增加 average 列
* 优化:下载数据时优化 cpu 占用
* 优化:tqsdk 内部各个模块使用统一的时间处理函数
* 修复::py:class:`~tqsdk.TargetPosTask` 及 :py:class:`~tqsdk.algorithm.twap` 增加添加普麦、早籼稻、粳稻及晚籼稻期货暂不支持的提示
* 修复::py:meth:`~tqsdk.TqApi.query_symbol_ranking` 接口某些情况可能报错的问题


3.2.8 (2022/04/29)

* 修复:下载多合约 klines 时数据可能未完全收全的问题
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_tag(self):

setuptools.setup(
name='tqsdk',
version="3.2.8",
version="3.2.9",
description='TianQin SDK',
author='TianQin',
author_email='[email protected]',
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.2.8'
__version__ = '3.2.9'
5 changes: 3 additions & 2 deletions tqsdk/algorithm/time_table_generater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from tqsdk.api import TqApi
from tqsdk import utils
from tqsdk.datetime import _get_trading_timestamp, _get_trade_timestamp, _get_trading_day_from_timestamp
from tqsdk.datetime import _get_trading_timestamp, _get_trade_timestamp, _get_trading_day_from_timestamp, \
_datetime_to_timestamp_nano
from tqsdk.rangeset import _rangeset_slice, _rangeset_head
from tqsdk.tradeable import TqAccount, TqKq, TqSim

Expand Down Expand Up @@ -228,7 +229,7 @@ def vwap_table(api: TqApi, symbol: str, target_pos: int, duration: float,
current_datetime = datetime.fromtimestamp(current_timestamp_nano//1000000000)
# 下一分钟的开始时间
next_datetime = current_datetime.replace(second=0) + timedelta(minutes=1)
start_datetime_nano = int(next_datetime.timestamp()) * 1000000000
start_datetime_nano = _datetime_to_timestamp_nano(next_datetime)
r = _rangeset_head(_rangeset_slice(trading_timestamp_nano_range, start_datetime_nano), int(duration * 1e9))
if not (r and trading_timestamp_nano_range[0][0] <= r[-1][-1] < trading_timestamp_nano_range[-1][1]):
raise Exception("指定时间段超出当前交易日")
Expand Down
8 changes: 8 additions & 0 deletions tqsdk/algorithm/twap.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ def __init__(self, api: TqApi, symbol: str, direction: str, offset: str, volume:
raise Exception("动力煤期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 4 手,这些函数还未支持该规则!")
if symbol.startswith("CZCE.WH"):
raise Exception("强麦期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
if symbol.startswith("CZCE.PM"):
raise Exception("普麦期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
if symbol.startswith("CZCE.RI"):
raise Exception("早籼稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
if symbol.startswith("CZCE.JR"):
raise Exception("粳稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
if symbol.startswith("CZCE.LR"):
raise Exception("晚籼稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
self._api = api
self._account = api._account._check_valid(account)
if self._account is None:
Expand Down
Loading

0 comments on commit 6b51b4e

Please sign in to comment.