Skip to content

Fix copy-paste field mapping bugs in TryFrom<quote::FilterWarrant> for WarrantInfo#485

Merged
sunli829 merged 2 commits into
mainfrom
copilot/fix-warrantinfo-field-mapping-bug
Mar 22, 2026
Merged

Fix copy-paste field mapping bugs in TryFrom<quote::FilterWarrant> for WarrantInfo#485
sunli829 merged 2 commits into
mainfrom
copilot/fix-warrantinfo-field-mapping-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 22, 2026

9 fields in WarrantInfo were incorrectly sourced from info.last_done instead of their respective proto fields, causing warrant_list() to return the last-done price for strike_price, itm_otm, implied_volatility, delta, effective_leverage, conversion_ratio, and balance_point.

Changes

  • rust/src/quote/types.rs — corrected field sources in both affected branches:
Field Branch Was Fix
strike_price Call/Put info.last_done info.strike_price
itm_otm Call/Put info.last_done info.itm_otm
implied_volatility Call/Put info.last_done info.implied_volatility
delta Call/Put info.last_done info.delta
effective_leverage Call/Put info.last_done info.effective_leverage
strike_price Bull/Bear info.last_done info.strike_price
itm_otm Bull/Bear info.last_done info.itm_otm
conversion_ratio Bull/Bear info.last_done info.conversion_ratio
balance_point Bull/Bear info.last_done info.balance_point

Since Python/Java/C++ SDKs are FFI bindings over this Rust layer, the fix propagates automatically. A sweep of all other TryFrom implementations across the codebase found no further instances of this pattern.

Original prompt

Bug Fix: WarrantInfo fields incorrectly mapped to last_done in TryFrom<quote::FilterWarrant>

Fixes longbridge/developers#844

Problem

In rust/src/quote/types.rs, the TryFrom<quote::FilterWarrant> for WarrantInfo implementation has a copy-paste bug where multiple fields are incorrectly assigned from info.last_done instead of their correct source fields.

This causes QuoteContext.warrant_list() to return wrong values for implied_volatility, delta, effective_leverage, strike_price, and itm_otm — all returning the same value as last_done.

Affected Code

File: rust/src/quote/types.rs

Call/Put branch (lines ~1168–1179) — 5 wrong fields:

// WRONG (current code)
strike_price: info.last_done.parse().ok(),
itm_otm: info.last_done.parse().ok(),
implied_volatility: info.last_done.parse().ok(),
delta: info.last_done.parse().ok(),
effective_leverage: info.last_done.parse().ok(),

// CORRECT (fix)
strike_price: info.strike_price.parse().ok(),
itm_otm: info.itm_otm.parse().ok(),
implied_volatility: info.implied_volatility.parse().ok(),
delta: info.warrant_delta.parse().ok(),
effective_leverage: info.effective_leverage.parse().ok(),

Bull/Bear branch (lines ~1197–1211) — 4 wrong fields:

// WRONG (current code)
strike_price: Some(info.last_done.parse().unwrap_or_default()),
itm_otm: Some(info.last_done.parse().unwrap_or_default()),
conversion_ratio: Some(info.last_done.parse().unwrap_or_default()),
balance_point: Some(info.last_done.parse().unwrap_or_default()),

// CORRECT (fix)
strike_price: Some(info.strike_price.parse().unwrap_or_default()),
itm_otm: Some(info.itm_otm.parse().unwrap_or_default()),
conversion_ratio: Some(info.conversion_ratio.parse().unwrap_or_default()),
balance_point: Some(info.balance_point.parse().unwrap_or_default()),

Fix Required

Update the TryFrom<quote::FilterWarrant> for WarrantInfo implementation in rust/src/quote/types.rs to use the correct source fields:

Field Branch Wrong Source Correct Source
strike_price Call/Put info.last_done info.strike_price
itm_otm Call/Put info.last_done info.itm_otm
implied_volatility Call/Put info.last_done info.implied_volatility
delta Call/Put info.last_done info.warrant_delta
effective_leverage Call/Put info.last_done info.effective_leverage
strike_price Bull/Bear info.last_done info.strike_price
itm_otm Bull/Bear info.last_done info.itm_otm
conversion_ratio Bull/Bear info.last_done info.conversion_ratio
balance_point Bull/Bear info.last_done info.balance_point

Only rust/src/quote/types.rs needs 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_done references in the TryFrom<quote::FilterWarrant> for WarrantInfo implementation.

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.rsTryFrom<quote::FilterWarrant> for WarrantInfo 的实现


Call / Put 分支(第 1157–1185 行)— 已确认 5 个字段错误

strike_price: info.last_done.parse().ok(),          // ❌ 应为 info.strike_...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

📱 Kick off Copilot coding agent tasks wherever you are with [GitHub Mobile](https://gh.io/cca-mobile-docs), available on iOS and Android.

…quote::FilterWarrant&gt;

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 last_done in TryFrom<quote::FilterWarrant> Mar 22, 2026
Copilot AI requested a review from huacnlee March 22, 2026 02:23
Copilot AI changed the title Fix WarrantInfo fields incorrectly sourced from last_done in TryFrom<quote::FilterWarrant> Fix copy-paste field mapping bugs in TryFrom<quote::FilterWarrant> for WarrantInfo Mar 22, 2026
@huacnlee huacnlee marked this pull request as ready for review March 22, 2026 02:40
@sunli829 sunli829 merged commit 579e395 into main Mar 22, 2026
62 checks passed
@sunli829 sunli829 deleted the copilot/fix-warrantinfo-field-mapping-bug branch March 22, 2026 02:49
sunli829 pushed a commit that referenced this pull request Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK: warrant_list() returns wrong values for implied_volatility, delta, effective_leverage, strike_price, itm_otm

3 participants