Repository navigation
fix!: name every integer code in every binding - #1520
Merged
Merged
Conversation
…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.
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.
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.
Merged
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.
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_typecolumn of streaming Arrow batches (client.stream.batches(), all languages) changes fromInt32codes to the string namesSTOCK,OPTION,INDEX,RATE,UNKNOWN, matchingevent.contract.sec_typeon the callback path. Code that compared the column against0/1must compare against the names.Additive:
result_name(Python) /resultName(TypeScript) with the server WebSocket names (SUBSCRIBED,MAX_STREAMS_REACHED, ...); C constants and a C++result_name().sec_type, disconnectreason/cause,implied_vol_source, the stream event kind, the reconnect policy and thewait_mode/bulk_fetch/reconnect_jittersettings, with generated C++ name accessors. The hand-written C++ name functions are replaced by generated ones with the same names and signatures.Single source of truth:
coded_fields()inthetadatadx-rs/src/surface/codes.rslists every code and name from the core types;generate_sdk_surfacesemits the C constants, the C++ accessors and the C++ test cases from it, and--checkholds 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_typecolumn with the callback contract'ssec_typefor 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.