Skip to content

fix!: name every integer code in every binding - #1520

Merged
userFRM merged 4 commits into
mainfrom
fix/sec-type-names
Nov 23, 2026
Merged

userFRM merged 4 commits into
mainfrom
fix/sec-type-names

Conversation

@userFRM

@userFRM userFRM commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Every value the SDK hands out as an integer code now has its name on every surface, taken from one table in the core.

Breaking: the sec_type column of streaming Arrow batches (client.stream.batches(), all languages) changes from Int32 codes to the string names STOCK, OPTION, INDEX, RATE, UNKNOWN, matching event.contract.sec_type on the callback path. Code that compared the column against 0 / 1 must compare against the names.

Additive:

  • Subscription replies: result_name (Python) / resultName (TypeScript) with the server WebSocket names (SUBSCRIBED, MAX_STREAMS_REACHED, ...); C constants and a C++ result_name().
  • C constants for sec_type, disconnect reason / cause, implied_vol_source, the stream event kind, the reconnect policy and the wait_mode / bulk_fetch / reconnect_jitter settings, with generated C++ name accessors. The hand-written C++ name functions are replaced by generated ones with the same names and signatures.
  • The C++ streaming example now uses the generated accessors; its own copy of the event-kind names had drifted.

Single source of truth: coded_fields() in thetadatadx-rs/src/surface/codes.rs lists every code and name from the core types; generate_sdk_surfaces emits the C constants, the C++ accessors and the C++ test cases from it, and --check holds them in sync.

Tests: one table-driven test per binding (Python, TypeScript, C++) reads every name through the real binding objects and compares it with the table, so a new code or field extends the test by itself. A Python test also compares the batch sec_type column with the callback contract's sec_type for the same events. Each was shown to fail when one name was changed.

Docs: streaming events, reliability, option Greeks and configuration pages; CHANGELOG under Unreleased.

…eader

The Arrow batch reader wrote `sec_type` as an Int32 code (0 stock, 1 option, 2 index, 3 rate) that nothing documented, while the per-event contract, the server WebSocket and the batch's own `event_type`, `symbol` and `right` columns carry names. The column is now Utf8 and holds the name the per-event contract carries.

The C ABI keeps `ThetaDataDxContract.sec_type` an int32_t, since its layout is pinned, but the header defined no name for any value, so C and C++ code compared it with literal integers. The generated event header now defines THETADATADX_SEC_TYPE_* from the core SecType, and the C++ sec_type_name() switches on them.

BREAKING CHANGE: the `sec_type` column of a streaming RecordBatch is Utf8 instead of Int32.
@userFRM userFRM added this to the 0.9.1 milestone Nov 23, 2026
@userFRM userFRM added bug Something isn't working rust Pull requests that update rust code ffi python typescript cpp labels Nov 23, 2026
The C ABI carries a subscription result, a disconnect's reason and cause, a binomial Greeks row's implied-volatility source, the reconnect policy and the enum config settings as int32 codes. Their mapping to the names Python, TypeScript, Arrow and the local server use lived in header comments or nowhere, the C++ name functions for the security type, disconnect reason and cause were copied by hand from the core, the reconnect policy was named by a separate hand-written match in each binding, and Python and TypeScript exposed a subscription result only as an integer.

The core now lists every such field once in coded_fields(), each code with the name read from the core type it carries. generate_sdk_surfaces renders from it a THETADATADX_<FIELD>_<NAME> constant for every code (codes.h.inc, which replaces the hand-written calendar constants and the security type block in fpss_event_structs.h.inc), the C++ thetadatadx::<field>_name() accessors (code_names.hpp.inc, which replaces the hand-written sec_type_name, reason_name, cause_name and calendar_status_name with the same signatures and adds result_name, implied_vol_source_name, reconnect_policy_name, the config setting names and kind_name for a stream event's kind), and the C++ test cases. A subscription response gains result_name in Python and resultName in TypeScript, the token the WebSocket publishes for it, and every binding reads the reconnect policy's code and name from the core.

Python, TypeScript and C++ each hold every name they give a code to the table, so a code or field the table gains reaches all three tests, and a Python test checks that a stream batch's sec_type column carries the name a callback reads from the same event's contract.
@userFRM userFRM changed the title fix(streaming)!: name the security type in stream batches and the C header fix!: name every integer code in every binding Nov 23, 2026
The reason a reconnect callback receives is a disconnect code, and every binding passed it as a bare integer with no way to name it: a disconnect event resolves the same vocabulary through its reason_name, but a callback holds only the number.

reconnect_reason_name(code) now names it as a free function beside exchange_name and calendar_status_name: thetadatadx.util.reconnect_reason_name in Python, Util.reconnectReasonName in TypeScript, thetadatadx::reconnect_reason_name in C++ and thetadatadx_reconnect_reason_name in C. All of them resolve the code through RemoveReason::name_for_code, which the coded fields table also names the field with. The field shares the disconnect reason's THETADATADX_DISCONNECT_REASON_* constants, which are still written once, so the Python, TypeScript and C++ table tests now cover the new function, and the C++ test also covers both C name functions.

The disconnect events' reason_name resolves through the same function. It cast the integer to i16 first, so a code outside the wire's 16-bit range wrapped onto a defined reason; such a code now reads as Unspecified.
@userFRM
userFRM merged commit 7b49d50 into main Nov 23, 2026
51 checks passed
@userFRM
userFRM deleted the fix/sec-type-names branch November 23, 2026 09:25
@userFRM userFRM mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cpp ffi python rust Pull requests that update rust code typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant