Fix copy-paste field mapping bugs in TryFrom<quote::FilterWarrant> for WarrantInfo#485
Merged
Merged
Conversation
…quote::FilterWarrant> Co-authored-by: huacnlee <5518+huacnlee@users.noreply.github.com> Agent-Logs-Url: https://github.com/longbridge/openapi/sessions/5db8f207-8635-401c-ab01-6e8cb47d3436
Copilot
AI
changed the title
[WIP] Fix WarrantInfo fields incorrectly mapped in TryFrom implementation
Fix WarrantInfo fields incorrectly sourced from Mar 22, 2026
last_done in TryFrom<quote::FilterWarrant>
Copilot
AI
changed the title
Fix WarrantInfo fields incorrectly sourced from
Fix copy-paste field mapping bugs in Mar 22, 2026
last_done in TryFrom<quote::FilterWarrant>TryFrom<quote::FilterWarrant> for WarrantInfo
huacnlee
approved these changes
Mar 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
9 fields in
WarrantInfowere incorrectly sourced frominfo.last_doneinstead of their respective proto fields, causingwarrant_list()to return the last-done price forstrike_price,itm_otm,implied_volatility,delta,effective_leverage,conversion_ratio, andbalance_point.Changes
rust/src/quote/types.rs— corrected field sources in both affected branches:strike_priceinfo.last_doneinfo.strike_priceitm_otminfo.last_doneinfo.itm_otmimplied_volatilityinfo.last_doneinfo.implied_volatilitydeltainfo.last_doneinfo.deltaeffective_leverageinfo.last_doneinfo.effective_leveragestrike_priceinfo.last_doneinfo.strike_priceitm_otminfo.last_doneinfo.itm_otmconversion_ratioinfo.last_doneinfo.conversion_ratiobalance_pointinfo.last_doneinfo.balance_pointSince Python/Java/C++ SDKs are FFI bindings over this Rust layer, the fix propagates automatically. A sweep of all other
TryFromimplementations across the codebase found no further instances of this pattern.Original prompt
Bug Fix:
WarrantInfofields incorrectly mapped tolast_doneinTryFrom<quote::FilterWarrant>Fixes longbridge/developers#844
Problem
In
rust/src/quote/types.rs, theTryFrom<quote::FilterWarrant> for WarrantInfoimplementation has a copy-paste bug where multiple fields are incorrectly assigned frominfo.last_doneinstead of their correct source fields.This causes
QuoteContext.warrant_list()to return wrong values forimplied_volatility,delta,effective_leverage,strike_price, anditm_otm— all returning the same value aslast_done.Affected Code
File:
rust/src/quote/types.rsCall/Put branch (lines ~1168–1179) — 5 wrong fields:
Bull/Bear branch (lines ~1197–1211) — 4 wrong fields:
Fix Required
Update the
TryFrom<quote::FilterWarrant> for WarrantInfoimplementation inrust/src/quote/types.rsto use the correct source fields:strike_priceinfo.last_doneinfo.strike_priceitm_otminfo.last_doneinfo.itm_otmimplied_volatilityinfo.last_doneinfo.implied_volatilitydeltainfo.last_doneinfo.warrant_deltaeffective_leverageinfo.last_doneinfo.effective_leveragestrike_priceinfo.last_doneinfo.strike_priceitm_otminfo.last_doneinfo.itm_otmconversion_ratioinfo.last_doneinfo.conversion_ratiobalance_pointinfo.last_doneinfo.balance_pointOnly
rust/src/quote/types.rsneeds to be modified. Since Python/Java/C++ SDKs are all FFI bindings on top of the Rust layer, this fix will automatically propagate to all language SDKs.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: 以下是其他 AI 工具分析源代码定位到的问题:
我已经在 Rust SDK 源码中定位到了 bug。问题出在 rust/src/quote/types.rs 文件的 WarrantInfo 结构体的 TryFromquote::FilterWarrant 实现中。
问题根源
当轮证类型为 Call 或 Put 时,以下 5 个字段被错误地赋值为 last_done:
rust
// 错误的实现(第 1571-1576 行)
strike_price: info.last_done.parse().ok(), // ❌ 应该用 info.strike_price
itm_otm: info.last_done.parse().ok(), // ❌ 应该用 info.itm_otm
implied_volatility: info.last_done.parse().ok(), // ❌ 应该用 info.implied_volatility
delta: info.last_done.parse().ok(), // ❌ 应该用 info.delta ( 或 warrant_delta)
effective_leverage: info.last_done.parse().ok(), // ❌ 应该用 info.effective_leverage
正确的实现应该是
rust
strike_price: info.strike_price
itm_otm: info.itm_otm.parse().ok(),
implied_volatility: info.implied_volatility.parse().ok(),
delta: info.// 或 info.warrant_delta
effective_leverage: info.effective_leverage.parse().ok(),
影响范围
受影响的轮证类型:认购证(Call)和认沽证(Put)
不受影响:Bull/Bear/Inline 类型的轮证在相同代码中也有类似的错误,但赋值逻辑不同
源码位置:
文件:rust/src/quote/types.rs
起始行:约 1568-1602(Call/Put 分支)
也存在于:1604-1633(Bull/Bear 分支)和 1635-1661(Inline 分支)
修复建议
这是一个明显的复制粘贴错误,需要修改 Rust SDK 的源码。由于 Python SDK 是基于 Rust 的 FFI 绑定,修复了 Rust 层后,Python SDK 会自动继承修复。
我会在 GitHub Issue 中详细说明。
Assistant: I can now see the full bug clearly. Let me create a PR to fix all the erroneous
info.last_donereferences in theTryFrom<quote::FilterWarrant> for WarrantInfoimplementation.Assistant: We're waiting for your response to the tool call dialog to continue — please accept or reject it to proceed.
User: 先分析,Issue 里面的问题是否为我描述那样
Assistant: 我来仔细分析源码,确认 Issue 中描述的 bug。
分析结果
已确认,Issue 的问题描述完全正确,而且比 Issue 本身描述的还要严重。
Bug 位置:
rust/src/quote/types.rs中TryFrom<quote::FilterWarrant> for WarrantInfo的实现Call / Put 分支(第 1157–1185 行)— 已确认 5 个字段错误