-
Notifications
You must be signed in to change notification settings - Fork 702
[Tqsdk-Ci] Update Version 3.8.3 #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthrough本次更新将版本号从3.8.1提升至3.8.3,完善了Sphinx文档配置以支持新的Google Analytics扩展,新增了关于在Cursor AI代码编辑器中使用TqSdk的详细指南,调整了文档标题下划线长度和目录结构,修正了部分文档链接格式,扩展了股指期权查询参数校验范围,优化了WebSocket连接处理函数,改进了Pandas版本判断逻辑,并对示例代码和异常提示进行了细节调整。 Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TqWebHelper
participant WebSocket
Client->>TqWebHelper: 发起WebSocket连接请求
TqWebHelper->>WebSocket: 建立连接
TqWebHelper->>Client: 发送初始数据
loop 消息处理
Client->>TqWebHelper: 发送消息
TqWebHelper->>Client: 响应消息
end
TqWebHelper-->>Client: 关闭连接并返回ws对象
Poem
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
✨ Finishing Touches
🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tqsdk/api.py (1)
3072-3084
: 统一错误提示中的参数名称
当前错误提示使用了exercise_date 参数
,但是该接口实际接收的参数名为nearbys
。建议将提示修改为:if underlying_symbol in ["SSE.000300", "SSE.000852", "SSE.000016"]: if any(i not in [0, 1, 2, 3, 4, 5] for i in nearbys): raise Exception(f"股指期权标的为:{underlying_symbol},nearbys 参数应在 [0, 1, 2, 3, 4, 5] 之间。") else: if any(i not in [0, 1, 2, 3] for i in nearbys): raise Exception(f"ETF 期权标的为:{underlying_symbol},nearbys 参数应在 [0, 1, 2, 3] 之间。")这样可保持文档、参数和错误提示的一致性。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
PKG-INFO
(1 hunks)doc/conf.py
(3 hunks)doc/demo/base.rst
(30 hunks)doc/index.rst
(1 hunks)doc/tq_trading_unit.rst
(4 hunks)doc/tqsdk_cursor.rst
(1 hunks)doc/usage/jupyter.rst
(1 hunks)doc/version.rst
(4 hunks)setup.py
(1 hunks)tqsdk/__version__.py
(1 hunks)tqsdk/api.py
(3 hunks)tqsdk/tqwebhelper.py
(1 hunks)
🔇 Additional comments (19)
tqsdk/tqwebhelper.py (1)
290-290
: 修复 WebSocket 处理器的返回值正确添加了
return ws
语句,这符合 aiohttp WebSocket 处理器的标准模式。之前缺少返回值可能会导致框架无法正确处理 WebSocket 响应对象。PKG-INFO (1)
3-3
: 版本号更新正确版本从 3.8.1 更新到 3.8.2,与项目的版本发布一致。
tqsdk/__version__.py (1)
1-1
:✅ Verification successful
版本字符串更新正确
版本号已正确更新为 '3.8.2',与其他文件中的版本信息保持一致。
运行以下脚本验证版本号在整个项目中的一致性:
🏁 Script executed:
#!/bin/bash # 描述:检查项目中所有版本号引用是否一致 # 预期:所有版本号都应该是 3.8.2 echo "检查版本号一致性:" echo "=== __version__.py ===" cat tqsdk/__version__.py echo "=== PKG-INFO ===" grep "^Version:" PKG-INFO echo "=== setup.py ===" rg -A 3 -B 3 "version.*=" setup.py echo "=== 其他可能的版本引用 ===" rg "3\.8\.[0-9]" --type py --type rst --type mdLength of output: 930
版本号一致性验证通过
项目中所有主要版本引用均已正确更新为 3.8.2:
tqsdk/version.py
PKG-INFO
setup.py
doc/conf.py
doc/version.rst 中保留了历史版本记录(3.8.2、3.8.1、3.8.0),无需修改。
doc/tq_trading_unit.rst 中的最低版本要求
>= 3.8.0
对于 3.8.2 依然适用,无需调整。✅ 批准合并。
doc/index.rst (1)
24-24
:✅ Verification successful
文档索引更新正确
在目录树中添加了
tqsdk_cursor.rst
,这应该是新增的 Cursor AI 代码编辑器使用指南。验证新添加的文档文件是否存在:
🏁 Script executed:
#!/bin/bash # 描述:检查新添加的文档文件是否存在 # 预期:tqsdk_cursor.rst 文件应该存在 echo "检查文档文件:" if [ -f "doc/tqsdk_cursor.rst" ]; then echo "✓ doc/tqsdk_cursor.rst 存在" echo "文件大小:$(wc -l < doc/tqsdk_cursor.rst) 行" else echo "✗ doc/tqsdk_cursor.rst 不存在" fi echo "" echo "检查是否有其他相关的 LLM 或 Cursor 文档:" fd -e rst . doc/ | grep -i -E "(llm|cursor|ai)"Length of output: 402
文档索引更新已验证
- 已确认
doc/tqsdk_cursor.rst
文件存在(178 行)- 原有的
doc/tqsdk_llm.rst
仍在,新增文档与现有 LLM 文档可并存
批准合并,无其他问题。setup.py (1)
11-11
: 版本号更新 已将版本号从3.8.1更新至3.8.2,与__version__.py
、doc/conf.py
等保持一致,符合发布流程。doc/tq_trading_unit.rst (1)
8-8
: 统一格式调整:标题下划线 已将各段落标题的下划线长度调整为与标题文本长度一致,保持文档格式统一。Also applies to: 81-81, 93-93, 106-106, 113-113
doc/usage/jupyter.rst (1)
28-29
: 修复链接格式 已移除冗余冒号和空格,修正为正确的 reST 链接语法,确保文档引用链接准确可用。doc/demo/base.rst (1)
4-4
: 统一格式调整:标题下划线 已将演示文档中所有标题的下划线长度统一为与标题文本长度一致,提升可读性和一致性。Also applies to: 12-12, 21-21, 30-30, 39-39, 48-48, 57-57, 66-66, 74-74, 82-82, 89-89, 96-96, 103-103, 110-110, 117-117, 124-124, 131-131, 138-138, 145-145, 152-152, 159-159, 165-165, 173-173, 180-180, 187-187, 194-194, 201-201, 208-208
tqsdk/api.py (2)
870-871
: 在示例中显式导入datetime
以避免运行错误
添加from datetime import datetime
导入,使示例能正确识别datetime
类型,确保示例代码可运行。
942-943
: 在示例中显式导入datetime
以避免运行错误
添加from datetime import datetime
导入,使示例能正确识别datetime
类型,确保示例代码可运行。doc/version.rst (1)
5-10
: 版本变更日志条目格式正确新增的3.8.2版本条目格式规范,内容简洁明了,符合项目的变更日志标准。修复内容和文档改进的描述都很清晰。
doc/conf.py (3)
17-17
: 正确添加Google Analytics扩展在extensions列表中正确添加了
sphinxcontrib.googleanalytics
扩展,这将为文档站点提供访问分析功能。
51-53
: 版本号更新一致版本号从3.8.1正确更新为3.8.2,与其他文件中的版本更新保持一致。
82-84
: Google Analytics配置合理Google Analytics的配置设置合理:
- 使用了GA4格式的跟踪ID (
G-9SPL7ERCMF
)- 默认启用分析功能
- 配置简洁明了
doc/tqsdk_cursor.rst (5)
1-36
: 优秀的文档概述和介绍部分文档开头部分内容全面且结构清晰:
- 明确说明了文档目的和适用对象
- 对Cursor的介绍准确且有针对性
- 详细列出了在TqSdk开发中使用Cursor的具体好处
- 内容组织逻辑性强,便于用户理解
37-77
: 实用的安装和配置指南安装和初始配置部分提供了清晰的步骤指导:
- 安装步骤简明扼要
- 包含了重要的配置建议(如推荐购买会员)
- Python环境配置说明详细实用
- 验证安装的命令很有帮助
78-108
: 极佳的源码集成建议将TqSdk源码添加到工作区的建议非常有价值:
- 强调了这种做法的重要性
- 提供了两种获取源码的方法,适应不同用户需求
- 详细说明了操作步骤
- 清楚阐释了这样做的技术优势
这是一个非常实用的最佳实践建议。
109-173
: 全面的AI交互指南文档的核心部分内容丰富且实用:
- 提供了具体的使用快捷键和操作方法
- 包含了大量实际的提问示例,覆盖不同使用场景
- 调试指导简洁实用
- 高效提问技巧部分很有价值,能帮助用户更好地利用AI功能
174-179
: 恰当的总结部分文档结尾总结恰当:
- 重申了Cursor对TqSdk开发的价值
- 鼓励用户积极使用关键功能
- 语调积极正面,有助于用户采用
b5b435f
to
373476e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (17)
PKG-INFO
(1 hunks)doc/advanced/backtest.rst
(1 hunks)doc/conf.py
(3 hunks)doc/demo/base.rst
(30 hunks)doc/index.rst
(1 hunks)doc/tq_trading_unit.rst
(4 hunks)doc/tqsdk_cursor.rst
(1 hunks)doc/usage/jupyter.rst
(1 hunks)doc/version.rst
(4 hunks)setup.py
(1 hunks)tqsdk/__version__.py
(1 hunks)tqsdk/api.py
(13 hunks)tqsdk/calendar.py
(1 hunks)tqsdk/demo/tutorial/t72.py
(1 hunks)tqsdk/lib/target_pos_task.py
(1 hunks)tqsdk/tqwebhelper.py
(1 hunks)tqsdk/tradeable/mixin.py
(4 hunks)
✅ Files skipped from review due to trivial changes (6)
- tqsdk/demo/tutorial/t72.py
- setup.py
- doc/usage/jupyter.rst
- doc/demo/base.rst
- tqsdk/lib/target_pos_task.py
- tqsdk/tradeable/mixin.py
🚧 Files skipped from review as they are similar to previous changes (8)
- PKG-INFO
- tqsdk/version.py
- doc/index.rst
- tqsdk/tqwebhelper.py
- doc/tq_trading_unit.rst
- doc/version.rst
- doc/conf.py
- tqsdk/api.py
🔇 Additional comments (1)
doc/tqsdk_cursor.rst (1)
1-179
: 请检查主索引文件是否已包含此章节
已新增doc/tqsdk_cursor.rst
文档,需在doc/index.rst
中加入对应条目,否则文档生成时不会展示此部分。#!/bin/bash grep -R "tqsdk_cursor\." doc/index.rst
# 由于主连表没有承诺主力合约在交易日更新,所以在主连表中非交易日可能也会有主力合约,比如 DCE.v1401 | ||
# 所以 merge_result 中可能会有 _cst_date 在交易日之外的日期,导致和 self.df 行数对不齐 | ||
# 所以 merge_result 只保留 self.df 中的交易日 | ||
s = merge_result.loc[merge_result['_cst_date'].isin(set(self.df['_cst_date'])), 'underlying'] | ||
self.df[cont] = pd.Series(s.values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
❓ Verification inconclusive
建议改用索引对齐避免隐含的长度一致性假设
当前实现:
s = merge_result.loc[merge_result['_cst_date'].isin(set(self.df['_cst_date'])), 'underlying']
self.df[cont] = pd.Series(s.values)
问题
s.values
与self.df
行数必须完全一致,否则会触发ValueError: Length of values does not match length of index
。一旦merge_result
中出现重复_cst_date
(主连表数据质量问题即可触发)或排序不一致,便会造成崩溃。- 依赖「长度对齐」而非「索引对齐」,可读性和健壮性都较差。
set(self.df['_cst_date'])
每次调用都会创建临时集合,成本不大但完全可以避免。
更稳健的实现方式(利用索引映射):
- s = merge_result.loc[merge_result['_cst_date'].isin(set(self.df['_cst_date'])), 'underlying']
- self.df[cont] = pd.Series(s.values)
+ # 先将 merge_result 以 _cst_date 设为索引,保证唯一索引后再映射
+ underlying_map = merge_result.set_index('_cst_date')['underlying']
+ # 基于 _cst_date 精确对齐,无需假设行数一致
+ self.df[cont] = self.df['_cst_date'].map(underlying_map)
优势
- 按日期索引精准对齐,完全消除长度不匹配风险。
- 可读性更高,意图更直观。
- 避免不必要的
set
构造,提高微观性能。
建议评估并替换现有实现。
建议改用索引对齐避免隐含的长度一致性假设
当前实现:
s = merge_result.loc[merge_result['_cst_date'].isin(set(self.df['_cst_date'])), 'underlying']
self.df[cont] = pd.Series(s.values)
问题
s.values
与self.df
行数必须完全一致,否则会触发ValueError: Length of values does not match length of index
。一旦merge_result
中出现重复_cst_date
(主连表数据质量问题即可触发)或排序不一致,便会造成崩溃。- 依赖「长度对齐」而非「索引对齐」,可读性和健壮性都较差。
set(self.df['_cst_date'])
每次调用都会创建临时集合,成本不大但完全可以避免。
更稳健的实现方式(利用索引映射):
- s = merge_result.loc[merge_result['_cst_date'].isin(set(self.df['_cst_date'])), 'underlying']
- self.df[cont] = pd.Series(s.values)
+ # 先将 merge_result 以 _cst_date 设为索引,保证唯一索引后再映射
+ underlying_map = merge_result.set_index('_cst_date')['underlying']
+ # 基于 _cst_date 精确对齐,无需假设行数一致
+ self.df[cont] = self.df['_cst_date'].map(underlying_map)
优势
- 按日期索引精准对齐,完全消除长度不匹配风险。
- 可读性更高,意图更直观。
- 避免不必要的
set
构造,提高微观性能。
建议评估并替换现有实现。
🤖 Prompt for AI Agents
In tqsdk/calendar.py around lines 101 to 105, the current code assigns values
from merge_result to self.df based on matching '_cst_date' values but relies on
length alignment which can cause ValueError if lengths mismatch or duplicates
exist. To fix this, replace the assignment with an index-based alignment
approach that uses '_cst_date' as the index to map 'underlying' values directly
to self.df, ensuring robust and clear alignment without creating temporary sets.
This will prevent length mismatch errors and improve code readability and
performance.
@@ -66,7 +66,7 @@ TqSdk 并不提供专门的参数优化机制. 您可以按照自己的需求, | |||
target_pos.set_target_volume(3) | |||
except BacktestFinished: | |||
api.close() | |||
print("SHORT=", SHORT, "最终权益=", acc.account.balance) # 每次回测结束时, 输出使用的参数和最终权益 | |||
print("SHORT=", SHORT, "最终权益=", acc.get_account().balance) # 每次回测结束时, 输出使用的参数和最终权益 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
修正示例代码的方法调用错误
并发回测示例中使用了 acc.get_account().balance
,但 acc
为 TqSim
实例,不具备 get_account()
方法。建议改为:
- print("SHORT=", SHORT, "最终权益=", acc.get_account().balance)
+ print("SHORT=", SHORT, "最终权益=", api.get_account().balance)
并与单进程示例保持一致。
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
print("SHORT=", SHORT, "最终权益=", acc.get_account().balance) # 每次回测结束时, 输出使用的参数和最终权益 | |
print("SHORT=", SHORT, "最终权益=", api.get_account().balance) # 每次回测结束时, 输出使用的参数和最终权益 |
🤖 Prompt for AI Agents
In doc/advanced/backtest.rst at line 69, the code incorrectly calls
acc.get_account().balance, but acc is a TqSim instance which does not have
get_account() method. Replace acc.get_account().balance with acc.get_balance()
to match the single-process example and correctly retrieve the account balance.
Automated changes by create-pull-request GitHub action
Summary by CodeRabbit
新功能
修复
文档
其他