Skip to content

Commit f2c73bb

Browse files
userFRMclaude
andauthored
fix(ffi): add unified exports + SnapshotTradeTick plumbing to Go/C++ headers (#216, #227) (#239)
Add all 19 tdx_unified_* C declarations (connect, start/stop streaming, subscribe/unsubscribe quotes/trades/open_interest/full_trades/full_open_interest, is_streaming, contract_lookup, active_subscriptions, next_event, historical, free) plus the TdxUnified opaque type to both sdks/go/ffi_bridge.h and sdks/cpp/include/thetadx.h. Add missing cOptionContract size assertion to Go init() checks. Note: TdxSnapshotTradeTickArray and tdx_free_snapshot_trade_tick_array are NOT added because the Rust FFI does not export them -- SnapshotTradeTick was intentionally removed from the FFI layer in v5.4.0 (snapshot trade endpoints return TdxTradeTickArray). The C struct definition remains for documentation but has no array/free plumbing. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a59c0ba commit f2c73bb

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

sdks/cpp/include/thetadx.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct TdxCredentials TdxCredentials;
3737
typedef struct TdxClient TdxClient;
3838
typedef struct TdxConfig TdxConfig;
3939
typedef struct TdxFpssHandle TdxFpssHandle;
40+
typedef struct TdxUnified TdxUnified;
4041

4142
/* ═══════════════════════════════════════════════════════════════════════ */
4243
/* #[repr(C)] tick types — layout-compatible with Rust tdbe structs */
@@ -890,6 +891,69 @@ void tdx_fpss_shutdown(const TdxFpssHandle* h);
890891
/** Free the FPSS handle. Must be called after tdx_fpss_shutdown. */
891892
void tdx_fpss_free(TdxFpssHandle* h);
892893

894+
/* ======================================================================= */
895+
/* Unified client -- historical + streaming through one handle */
896+
/* ======================================================================= */
897+
898+
/** Connect to ThetaData (historical only -- FPSS streaming is NOT started).
899+
* Returns NULL on connection/auth failure (check tdx_last_error()). */
900+
TdxUnified* tdx_unified_connect(const TdxCredentials* creds, const TdxConfig* config);
901+
902+
/** Start FPSS streaming on the unified client. Returns 0 on success, -1 on error. */
903+
int tdx_unified_start_streaming(const TdxUnified* handle);
904+
905+
/** Subscribe to quote data for a stock symbol. Returns 0 on success, -1 on error. */
906+
int tdx_unified_subscribe_quotes(const TdxUnified* handle, const char* symbol);
907+
908+
/** Subscribe to trade data for a stock symbol. Returns 0 on success, -1 on error. */
909+
int tdx_unified_subscribe_trades(const TdxUnified* handle, const char* symbol);
910+
911+
/** Unsubscribe from quote data. Returns 0 on success, -1 on error. */
912+
int tdx_unified_unsubscribe_quotes(const TdxUnified* handle, const char* symbol);
913+
914+
/** Unsubscribe from trade data. Returns 0 on success, -1 on error. */
915+
int tdx_unified_unsubscribe_trades(const TdxUnified* handle, const char* symbol);
916+
917+
/** Subscribe to open interest data. Returns 0 on success, -1 on error. */
918+
int tdx_unified_subscribe_open_interest(const TdxUnified* handle, const char* symbol);
919+
920+
/** Unsubscribe from open interest data. Returns 0 on success, -1 on error. */
921+
int tdx_unified_unsubscribe_open_interest(const TdxUnified* handle, const char* symbol);
922+
923+
/** Subscribe to all trades for a security type ("STOCK", "OPTION", "INDEX"). Returns 0 or -1. */
924+
int tdx_unified_subscribe_full_trades(const TdxUnified* handle, const char* sec_type);
925+
926+
/** Subscribe to all open interest for a security type. Returns 0 or -1. */
927+
int tdx_unified_subscribe_full_open_interest(const TdxUnified* handle, const char* sec_type);
928+
929+
/** Unsubscribe from all trades for a security type. Returns 0 or -1. */
930+
int tdx_unified_unsubscribe_full_trades(const TdxUnified* handle, const char* sec_type);
931+
932+
/** Unsubscribe from all open interest for a security type. Returns 0 or -1. */
933+
int tdx_unified_unsubscribe_full_open_interest(const TdxUnified* handle, const char* sec_type);
934+
935+
/** Check if streaming is active. Returns 1 if streaming, 0 otherwise. */
936+
int tdx_unified_is_streaming(const TdxUnified* handle);
937+
938+
/** Look up a contract by ID. Returns string or NULL. Caller must free with tdx_string_free. */
939+
char* tdx_unified_contract_lookup(const TdxUnified* handle, int id);
940+
941+
/** Get active subscriptions as typed array. Caller must free with tdx_subscription_array_free. */
942+
TdxSubscriptionArray* tdx_unified_active_subscriptions(const TdxUnified* handle);
943+
944+
/** Poll for next streaming event. Returns TdxFpssEvent* or NULL on timeout.
945+
* Caller MUST free with tdx_fpss_event_free. */
946+
TdxFpssEvent* tdx_unified_next_event(const TdxUnified* handle, uint64_t timeout_ms);
947+
948+
/** Borrow the historical client from a unified handle. Do NOT free the returned pointer. */
949+
const TdxClient* tdx_unified_historical(const TdxUnified* handle);
950+
951+
/** Stop streaming on the unified client. Historical remains available. */
952+
void tdx_unified_stop_streaming(const TdxUnified* handle);
953+
954+
/** Free a unified client handle. */
955+
void tdx_unified_free(TdxUnified* handle);
956+
893957
#ifdef __cplusplus
894958
}
895959
#endif

sdks/go/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ func init() {
299299
{"cMarketValueTick", unsafe.Sizeof(cMarketValueTick{}), 128},
300300
{"cGreeksTick", unsafe.Sizeof(cGreeksTick{}), 256},
301301
{"cTradeQuoteTick", unsafe.Sizeof(cTradeQuoteTick{}), 192},
302+
{"cOptionContract", unsafe.Sizeof(cOptionContract{}), 32},
302303
}
303304
for _, c := range checks {
304305
if c.got != c.want {

sdks/go/ffi_bridge.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typedef struct TdxCredentials TdxCredentials;
1010
typedef struct TdxClient TdxClient;
1111
typedef struct TdxConfig TdxConfig;
1212
typedef struct TdxFpssHandle TdxFpssHandle;
13+
typedef struct TdxUnified TdxUnified;
1314

1415
/* Generic array layouts used by the Go bindings. */
1516
typedef struct { const void* data; size_t len; } TdxTickArray;
@@ -268,4 +269,25 @@ extern void tdx_fpss_event_free(TdxFpssEvent* event);
268269
extern void tdx_fpss_shutdown(const TdxFpssHandle* h);
269270
extern void tdx_fpss_free(TdxFpssHandle* h);
270271

272+
/* Unified client -- historical + streaming through one handle */
273+
extern TdxUnified* tdx_unified_connect(const TdxCredentials* creds, const TdxConfig* config);
274+
extern int tdx_unified_start_streaming(const TdxUnified* handle);
275+
extern int tdx_unified_subscribe_quotes(const TdxUnified* handle, const char* symbol);
276+
extern int tdx_unified_subscribe_trades(const TdxUnified* handle, const char* symbol);
277+
extern int tdx_unified_unsubscribe_quotes(const TdxUnified* handle, const char* symbol);
278+
extern int tdx_unified_unsubscribe_trades(const TdxUnified* handle, const char* symbol);
279+
extern int tdx_unified_subscribe_open_interest(const TdxUnified* handle, const char* symbol);
280+
extern int tdx_unified_unsubscribe_open_interest(const TdxUnified* handle, const char* symbol);
281+
extern int tdx_unified_subscribe_full_trades(const TdxUnified* handle, const char* sec_type);
282+
extern int tdx_unified_subscribe_full_open_interest(const TdxUnified* handle, const char* sec_type);
283+
extern int tdx_unified_unsubscribe_full_trades(const TdxUnified* handle, const char* sec_type);
284+
extern int tdx_unified_unsubscribe_full_open_interest(const TdxUnified* handle, const char* sec_type);
285+
extern int tdx_unified_is_streaming(const TdxUnified* handle);
286+
extern char* tdx_unified_contract_lookup(const TdxUnified* handle, int id);
287+
extern TdxSubscriptionArray* tdx_unified_active_subscriptions(const TdxUnified* handle);
288+
extern TdxFpssEvent* tdx_unified_next_event(const TdxUnified* handle, uint64_t timeout_ms);
289+
extern const TdxClient* tdx_unified_historical(const TdxUnified* handle);
290+
extern void tdx_unified_stop_streaming(const TdxUnified* handle);
291+
extern void tdx_unified_free(TdxUnified* handle);
292+
271293
#endif

0 commit comments

Comments
 (0)