Skip to content

Commit 55d7ae2

Browse files
shinny-packshinny-mayanqiong
authored andcommitted
Update Version 3.5.3
1 parent 73dc941 commit 55d7ae2

File tree

9 files changed

+52
-46
lines changed

9 files changed

+52
-46
lines changed

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: tqsdk
3-
Version: 3.5.2
3+
Version: 3.5.3
44
Summary: TianQin SDK
55
Home-page: https://www.shinnytech.com/tqsdk
66
Author: TianQin

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
# built documents.
4949
#
5050
# The short X.Y version.
51-
version = u'3.5.2'
51+
version = u'3.5.3'
5252
# The full version, including alpha/beta/rc tags.
53-
release = u'3.5.2'
53+
release = u'3.5.3'
5454

5555
# The language for content autogenerated by Sphinx. Refer to documentation
5656
# for a list of supported languages.

doc/version.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
版本变更
44
=============================
5+
3.5.3 (2024/02/23)
6+
7+
* 修复:使用 :py:class:`~tqsdk.TargetPosScheduler`,并且最后一项调仓目标为 0 时,可能出现任务无法结束的问题
8+
* 修复:回测时如果订阅多个不同周期 K 线时,成交可能不符合预期的问题
9+
10+
511
3.5.2 (2024/02/07)
612

713
* 新增::py:class:`~tqsdk.objs.Quote` 增加以下属性

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setuptools.setup(
1010
name='tqsdk',
11-
version="3.5.2",
11+
version="3.5.3",
1212
description='TianQin SDK',
1313
author='TianQin',
1414
author_email='tianqincn@gmail.com',

tqsdk/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.5.2'
1+
__version__ = '3.5.3'

tqsdk/algorithm/twap.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,6 @@ def __init__(self, api: TqApi, symbol: str, direction: str, offset: str, volume:
117117
print(target_twap.average_trade_price)
118118
api.close()
119119
"""
120-
if symbol.startswith("CZCE.ZC"):
121-
raise Exception("动力煤期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 4 手,这些函数还未支持该规则!")
122-
if symbol.startswith("CZCE.WH"):
123-
raise Exception("强麦期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
124-
if symbol.startswith("CZCE.PM"):
125-
raise Exception("普麦期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
126-
if symbol.startswith("CZCE.RI"):
127-
raise Exception("早籼稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
128-
if symbol.startswith("CZCE.JR"):
129-
raise Exception("粳稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
130-
if symbol.startswith("CZCE.LR"):
131-
raise Exception("晚籼稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
132-
if symbol == "CZCE.SA309" or symbol == "CZCE.SA310":
133-
raise Exception("纯碱期货 2309 合约及 2310 合约不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 4 手,这些函数还未支持该规则!")
134120
self._api = api
135121
self._account = api._account._check_valid(account)
136122
if self._account is None:
@@ -167,6 +153,12 @@ def average_trade_price(self):
167153

168154
async def _run(self, volume_list, interval_list):
169155
self._quote = await self._api.get_quote(self._symbol)
156+
# 判断最小下单手数是否大于1
157+
if self._quote.open_min_market_order_volume > 1 or self._quote.open_min_limit_order_volume > 1:
158+
raise Exception(
159+
f"交易所规定 {self._symbol} 的最小市价开仓手数 ({self._quote.open_min_market_order_volume})"
160+
f" 或最小限价开仓手数 ({self._quote.open_min_limit_order_volume}) 大于 1,targetpostask、twap、vwap 这些函数还未支持该规则!"
161+
)
170162
# 计算得到时间序列,每个时间段快要结束的时间点,此时应该从被动价格切换为主动价格
171163
deadline_timestamp_list, strict_deadline_timestamp_list = self._get_deadline_timestamp(interval_list)
172164
for i in range(len(volume_list)):

tqsdk/backtest/backtest.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,11 @@ async def _gen_serial(self, ins, dur):
607607
}
608608
}
609609
}
610+
is_min_dur = dur == self._quotes[symbol]["min_duration"]
610611
yield timestamp, diff, self._get_quotes_from_kline(self._data["quotes"][symbol_list[0]],
611612
timestamp,
612-
item) # K线结束时生成quote数据
613+
item,
614+
is_min_dur) # K线结束时生成quote数据
613615
current_id += 1
614616
finally:
615617
# 释放chart资源
@@ -696,15 +698,16 @@ def _get_quotes_from_kline_open(info, timestamp, kline):
696698
]
697699

698700
@staticmethod
699-
def _get_quotes_from_kline(info, timestamp, kline):
701+
def _get_quotes_from_kline(info, timestamp, kline, is_min_dur):
700702
"""
701703
分为三个包发给下游:
702704
1. 根据 diff 协议,对于用户收到的最终结果没有影响
703705
2. TqSim 撮合交易会按顺序处理收到的包,分别比较 high、low、close 三个价格对应的买卖价
704706
3. TqSim 撮合交易只用到了买卖价,所以最新价只产生一次 close,而不会发送三次
707+
4. 最高最低仅用于 TqSim 撮合交易,由最小周期生成
705708
"""
706-
return [
707-
{
709+
if is_min_dur:
710+
return [{
708711
"datetime": _timestamp_nano_to_str(timestamp),
709712
"ask_price1": kline["high"] + info["price_tick"],
710713
"ask_volume1": 1,
@@ -717,13 +720,25 @@ def _get_quotes_from_kline(info, timestamp, kline):
717720
"volume": 0,
718721
"amount": float("nan"),
719722
"open_interest": kline["close_oi"],
720-
},
721-
{
723+
}, {
722724
"ask_price1": kline["low"] + info["price_tick"],
723725
"bid_price1": kline["low"] - info["price_tick"],
724-
},
725-
{
726+
}, {
726727
"ask_price1": kline["close"] + info["price_tick"],
727728
"bid_price1": kline["close"] - info["price_tick"],
728-
}
729-
]
729+
}]
730+
else:
731+
return [{
732+
"datetime": _timestamp_nano_to_str(timestamp),
733+
"ask_price1": kline["close"] + info["price_tick"],
734+
"ask_volume1": 1,
735+
"bid_price1": kline["close"] - info["price_tick"],
736+
"bid_volume1": 1,
737+
"last_price": kline["close"],
738+
"highest": float("nan"),
739+
"lowest": float("nan"),
740+
"average": float("nan"),
741+
"volume": 0,
742+
"amount": float("nan"),
743+
"open_interest": kline["close_oi"],
744+
}]

tqsdk/lib/target_pos_scheduler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ async def _run(self):
137137
break
138138
elif target_pos_task: # 最后一项,如果有 target_pos_task 等待持仓调整完成,否则直接退出
139139
position = self._account.get_position(self._symbol)
140-
async for _ in self._api.register_update_notify(position):
141-
if position.pos == row['target_pos']:
142-
break
140+
if position.pos != row['target_pos']:
141+
async for _ in self._api.register_update_notify(position):
142+
if position.pos == row['target_pos']:
143+
break
143144
_index = _index + 1
144145
finally:
145146
if target_pos_task:

tqsdk/lib/target_pos_task.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,6 @@ def get_price(direction):
198198
# 2021-03-15 11:29:48 - INFO - 时间: 2021-03-15 11:29:47.533515, 合约: SHFE.rb2106, 开平: OPEN, 方向: BUY, 手数: 3, 价格: 4687.000,手续费: 14.12
199199
200200
"""
201-
if symbol.startswith("CZCE.ZC"):
202-
raise Exception("动力煤期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 4 手,这些函数还未支持该规则!")
203-
if symbol.startswith("CZCE.WH"):
204-
raise Exception("强麦期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
205-
if symbol.startswith("CZCE.PM"):
206-
raise Exception("普麦期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
207-
if symbol.startswith("CZCE.RI"):
208-
raise Exception("早籼稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
209-
if symbol.startswith("CZCE.JR"):
210-
raise Exception("粳稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
211-
if symbol.startswith("CZCE.LR"):
212-
raise Exception("晚籼稻期货不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 10 手,这些函数还未支持该规则!")
213-
if symbol == "CZCE.SA309" or symbol == "CZCE.SA310":
214-
raise Exception("纯碱期货 2309 合约及 2310 合约不支持创建 targetpostask、twap、vwap 任务,交易所规定该品种最小开仓手数为大于等于 4 手,这些函数还未支持该规则!")
215201
super(TargetPosTask, self).__init__()
216202
self._api = api
217203
self._account = api._account._check_valid(account)
@@ -345,6 +331,12 @@ async def _target_pos_task(self):
345331
all_tasks = []
346332
try:
347333
self._quote = await self._api.get_quote(self._symbol)
334+
# 判断最小下单手数是否大于1
335+
if self._quote.open_min_market_order_volume > 1 or self._quote.open_min_limit_order_volume > 1:
336+
raise Exception(
337+
f"交易所规定 {self._symbol} 最小市价开仓手数 ({self._quote.open_min_market_order_volume})"
338+
f" 或最小限价开仓手数 ({self._quote.open_min_limit_order_volume}) 大于 1,targetpostask、twap、vwap 这些函数还未支持该规则!"
339+
)
348340
async for target_pos in self._pos_chan:
349341
# lib 中对于时间判断的方案:
350342
# 如果当前时间(模拟交易所时间)不在交易时间段内,则:等待直到行情更新

0 commit comments

Comments
 (0)