Skip to content

feat(fundamental): expose what BusinessV4 returns for business_segments - #632

Merged
hogan-yuan merged 1 commit into
mainfrom
feat/business-segments-v4
Nov 23, 2026
Merged

hogan-yuan merged 1 commit into
mainfrom
feat/business-segments-v4

Conversation

@hogan-yuan

Copy link
Copy Markdown
Member

The gateway behind business_segments moved to BusinessV4 and now returns considerably more than the SDK models. Nothing is broken — serde ignores the new fields, and the call keeps working — but a caller gets a name and a percentage per segment and nothing else.

What the gateway actually sends

Measured against production (700.HK):

{
  "total": "204785000000", "currency": "CNY", "date": "20260630",
  "report_txt": "2026.Q2", "fp_start": "2026.03.30", "fp_end": "2026.06.30",
  "yoy": "", "rpt_date": "2025.08.13",
  "business": [
    {"name": "增值服务", "percent": "48.06", "value": "98414000000",
     "id": "119683", "yoy": "7.711671"}
  ],
  "regionals": []
}

The SDK modelled date, total, currency and business[{name, percent}]. Everything else was dropped on the floor.

The two that matter

why
value without it a caller multiplies the percentage back out against total to recover an amount the server already sent
regionals an entire dimension, unreachable — and the history variant of this same API already exposed it, so the latest-snapshot type was the odd one out

Also added: report_txt, fp_start, fp_end, yoy at the top level; id and yoy per item.

rpt_date is deliberately left out

The gateway returns it. I did not expose it, because it disagrees with the business-segments/history endpoint for the same symbol and the same fiscal period:

source Tencent 2026.Q2 rpt_date
business-segments/history 2026.08.12
business-segments 2025.08.13

Six of six symbols showed the same skew (700.HK, AAPL.US, 9988.HK, MSFT.US, TSLA.US, BABA.US) — a year off, and in this case a day off too, so it is not a clean year-offset. The history endpoint's 38 records are internally consistent, including the cross-year case of an annual report filed the following March, so the fault is on this endpoint rather than a difference in meaning.

Putting a wrong value behind a field name callers would reasonably trust is worse than not having the field. It can be added once the data is right.

Robustness

Every new field is #[serde(default)]. An issuer with no coverage comes back with every field empty and an empty business array:

@@ 空响应解析成功 date="" total="" business=0 regionals=0

Verified against 600519.SH, which is such a case — A-shares return code: 0 with everything blank.

Scope

Four layers, not six. business_segments is not exposed in Node.js or Python at all, so the fan-out is Rust core → C → C++ → Java. The C header is regenerated by cbindgen.

A note for review: these are deserialize-only response types, but adding public fields to a non-#[non_exhaustive] struct is technically breaking for Rust code that constructs or exhaustively destructures one. Nobody constructs a response type, and the repo has added fields to response types in minor releases before, so I treated it as additive — say the word if you would rather it waited for a major.

Verified end to end

Against production, through the SDK:

700.HK   2026.Q2 2026.03.30~2026.06.30  total=204785000000 CNY
  business=4 regionals=0
    Value-Added Services (VAS)      pct=48.06 value=98414000000 id=119683 yoy=7.71167148235706
    Fintech and Business Services   pct=29.44 value=60286000000 id=139262 yoy=8.55301065975223

AAPL.US  2026.Q4 2026.06.30~2026.09.30  total=114477000000 USD
  business=5 regionals=0
    Americas                        pct=42.52 value=48680000000 id=117095 yoy=10.15568428674873

cargo check --all clean across all four layers. cargo test -p longbridge: 88 + 57 pass. cargo clippy --all --all-features: diffed against main, zero new warnings.

Not in this PR

  • MCP and CLI need no change. I checked both: the MCP tool already documents and returns the V4 shape, and the CLI passes the raw JSON through (--format json already carries everything new).
  • The rpt_date discrepancy itself — that is a data issue for the fundamentals team, not something the SDK can fix.

🤖 Generated with Claude Code

The gateway behind this endpoint moved to BusinessV4 and now returns
considerably more than the SDK models. Nothing broke -- serde ignores the
new fields -- but a caller gets a name and a percentage per segment and
nothing else, which means the amounts are unreachable and the regional
breakdown is invisible.

Measured against production, the response carries: report_txt, fp_start,
fp_end, yoy and regionals at the top level, and value, id and yoy on each
segment item. The history variant of this API already exposed regionals and
value, so the latest-snapshot type was the odd one out.

The two that matter most:

- `value` -- without it a caller has to multiply the percentage back out
  against `total` to recover an amount the server already sent.
- `regionals` -- an entire dimension that was simply unreachable.

Every new field is `#[serde(default)]`. An issuer with no coverage comes
back with every field empty and an empty `business` array, and that still
decodes; verified against 600519.SH, which is such a case.

`rpt_date` is deliberately left out. The gateway returns it here, but
compared with `business-segments/history` for the same symbol and the same
fiscal period the two disagree -- history gives 2026.08.12 for Tencent's
2026.Q2 where this endpoint gives 2025.08.13, a year and a day apart. Six of
six symbols showed the same skew. Exposing it as a field would put a wrong
value behind a name callers would reasonably trust.

Node.js and Python do not expose this API at all, so the fan-out is Rust
core, C, C++ and Java. The C header is regenerated by cbindgen.

Verified end to end against production: 700.HK returns report_txt=2026.Q2,
fp_start/fp_end 2026.03.30~2026.06.30, and per-segment values and ids
(Value-Added Services 48.06%, 98414000000, id 119683).
@hogan-yuan
hogan-yuan merged commit b34c78a into main Nov 23, 2026
56 checks passed
@hogan-yuan
hogan-yuan deleted the feat/business-segments-v4 branch November 23, 2026 05:33
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.

1 participant