From 7a2f704aea661ee0b8bf7a4f032a4a98330c2df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=81=E7=AB=A0=E6=B4=AA?= Date: Tue, 1 Sep 2026 16:59:42 +0800 Subject: [PATCH] feat!: remove GridContext.submit_strategy_questionnaire (POST /v1/record/questionnaire) The strategy risk-disclosure questionnaire endpoint has been retired and is no longer submitted through the OpenAPI SDK. Remove the submit_strategy_questionnaire method and its SubmitStrategyQuestionnaireOptions type across all six SDK layers: - Rust core: grid/context.rs, blocking/grid.rs, grid/requests/mod.rs; deleted grid/requests/submit_strategy_questionnaire.rs - C: grid_context/context.rs (longbridge.h auto-regenerated by cbindgen) - C++: grid_context.hpp / grid_context.cpp - Java: JNI grid_context.rs + SdkNative.java + GridContext.java - Node.js: grid/context.rs (index.d.ts / index.js regenerated) - Python: grid/context.rs + openapi.pyi - Removed the call from the grid_trading example All other grid APIs (submit / replace / cancel / suspend / restart / list / detail / trigger_history / symbol_info) are unchanged. cargo build for all crates, clippy --all --all-features (0 errors), and cargo fmt --check pass. --- CHANGELOG.md | 4 + c/csrc/include/longbridge.h | 8 - c/src/grid_context/context.rs | 20 +- cpp/include/grid_context.hpp | 5 - cpp/src/grid_context.cpp | 17 -- examples/rust/grid_trading/src/main.rs | 6 +- .../main/java/com/longbridge/SdkNative.java | 2 - .../java/com/longbridge/grid/GridContext.java | 13 - java/src/grid_context.rs | 21 +- nodejs/index.d.ts | 25 +- nodejs/index.js | 253 +++++++++++++++--- nodejs/src/grid/context.rs | 13 - python/pysrc/longbridge/openapi.pyi | 6 - python/src/grid/context.rs | 11 - rust/src/blocking/grid.rs | 11 +- rust/src/grid/context.rs | 20 +- rust/src/grid/requests/mod.rs | 2 - .../requests/submit_strategy_questionnaire.rs | 34 --- 18 files changed, 237 insertions(+), 234 deletions(-) delete mode 100644 rust/src/grid/requests/submit_strategy_questionnaire.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9455ea078..048f440bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Breaking changes + +- **All SDKs:** removed `GridContext.submit_strategy_questionnaire` (`POST /v1/record/questionnaire`) and its `SubmitStrategyQuestionnaireOptions` type. The endpoint has been retired; the strategy risk-disclosure record is no longer submitted through the OpenAPI SDK. Removed across Rust (incl. blocking), C, C++, Java, Node.js, and Python bindings + ### Fixed - **C/C++ SDKs:** every list argument that crosses the FFI boundary now tolerates a null pointer with a zero length. `std::vector::data()` is allowed to return `nullptr` for an empty vector, which is exactly what the C++ binding passes for an omitted list argument, but the C layer fed it straight to `std::slice::from_raw_parts` — undefined behaviour that **aborts the process** under the debug UB checks. Hit live by `QuoteContext::warrant_list` with no filters (`c/src/quote_context/context.rs:784`); all 17 call sites across `quote_context`, `trade_context`, `agent_context`, `alert_context`, and `types` now go through a null-tolerant `slice_from_raw_parts` helper diff --git a/c/csrc/include/longbridge.h b/c/csrc/include/longbridge.h index cc361ccd2..a458d19b9 100644 --- a/c/csrc/include/longbridge.h +++ b/c/csrc/include/longbridge.h @@ -12779,14 +12779,6 @@ void lb_grid_context_restart(const struct lb_grid_context_t *ctx, lb_async_callback_t callback, void *userdata); -/** - * Submit the strategy risk-disclosure questionnaire record (grid trading - * compliance authorization). - */ -void lb_grid_context_submit_strategy_questionnaire(const struct lb_grid_context_t *ctx, - lb_async_callback_t callback, - void *userdata); - /** * Get the security (symbol) info used to build a grid order (lot size, * authorization flag, settlement currency, etc.). diff --git a/c/src/grid_context/context.rs b/c/src/grid_context/context.rs index c29006192..10f9e9b2e 100644 --- a/c/src/grid_context/context.rs +++ b/c/src/grid_context/context.rs @@ -5,8 +5,7 @@ use longbridge::{ grid::{ GetGridOrderDetailOptions, GetGridOrdersByIdsOptions, GetGridOrdersOptions, GetGridTriggerHistoryOptions, GridLimitEvent, GridTimeInForce, GridTradeRule, - ReplaceGridOrderOptions, SubmitGridOrderOptions, SubmitStrategyQuestionnaireOptions, - TriggerPriceType, + ReplaceGridOrderOptions, SubmitGridOrderOptions, TriggerPriceType, }, }; @@ -322,23 +321,6 @@ pub unsafe extern "C" fn lb_grid_context_restart( }); } -/// Submit the strategy risk-disclosure questionnaire record (grid trading -/// compliance authorization). -#[unsafe(no_mangle)] -pub unsafe extern "C" fn lb_grid_context_submit_strategy_questionnaire( - ctx: *const CGridContext, - callback: CAsyncCallback, - userdata: *mut c_void, -) { - let ctx_inner = (*ctx).ctx.clone(); - execute_async(callback, ctx, userdata, async move { - ctx_inner - .submit_strategy_questionnaire(SubmitStrategyQuestionnaireOptions::new()) - .await?; - Ok(()) - }); -} - /// Get the security (symbol) info used to build a grid order (lot size, /// authorization flag, settlement currency, etc.). #[unsafe(no_mangle)] diff --git a/cpp/include/grid_context.hpp b/cpp/include/grid_context.hpp index 47256dcba..d5b7c8a0a 100644 --- a/cpp/include/grid_context.hpp +++ b/cpp/include/grid_context.hpp @@ -69,11 +69,6 @@ class GridContext void restart(const std::string& order_id, AsyncCallback callback) const; - /// Submit the strategy risk-disclosure questionnaire record (grid trading - /// compliance authorization). - void submit_strategy_questionnaire( - AsyncCallback callback) const; - /// Get the security (symbol) info used to build a grid order (lot size, /// authorization flag, settlement currency, etc.). void symbol_info( diff --git a/cpp/src/grid_context.cpp b/cpp/src/grid_context.cpp index 939ade412..c15b3e6ba 100644 --- a/cpp/src/grid_context.cpp +++ b/cpp/src/grid_context.cpp @@ -336,23 +336,6 @@ GridContext::restart( new AsyncCallback(callback)); } -void -GridContext::submit_strategy_questionnaire( - AsyncCallback callback) const -{ - lb_grid_context_submit_strategy_questionnaire( - ctx_, - [](auto res) { - auto callback_ptr = - callback::get_async_callback(res->userdata); - (*callback_ptr)(AsyncResult( - GridContext((const lb_grid_context_t*)res->ctx), - Status(res->error), - nullptr)); - }, - new AsyncCallback(callback)); -} - void GridContext::symbol_info( const std::string& symbol, diff --git a/examples/rust/grid_trading/src/main.rs b/examples/rust/grid_trading/src/main.rs index 3722c0e55..dd10e64c3 100644 --- a/examples/rust/grid_trading/src/main.rs +++ b/examples/rust/grid_trading/src/main.rs @@ -4,7 +4,7 @@ use longbridge::{ Config, grid::{ GetGridOrderDetailOptions, GetGridOrdersOptions, GetGridTriggerHistoryOptions, GridContext, - GridTradeRule, SubmitGridOrderOptions, SubmitStrategyQuestionnaireOptions, + GridTradeRule, SubmitGridOrderOptions, }, oauth::OAuthBuilder, trade::TradeContext, @@ -27,10 +27,6 @@ async fn main() -> Result<(), Box> { // Grid master-order pushes still arrive on the TradeContext private topic. let (_trade, mut receiver) = TradeContext::new(config); - // Accept the strategy risk disclosure (compliance authorization) once. - ctx.submit_strategy_questionnaire(SubmitStrategyQuestionnaireOptions::new()) - .await?; - // Security (symbol) info used to build a grid order (lot size, auth flag). let info = ctx.symbol_info("700.HK").await?; println!("grid symbol info: {info:?}"); diff --git a/java/javasrc/src/main/java/com/longbridge/SdkNative.java b/java/javasrc/src/main/java/com/longbridge/SdkNative.java index 357278b31..211e29544 100644 --- a/java/javasrc/src/main/java/com/longbridge/SdkNative.java +++ b/java/javasrc/src/main/java/com/longbridge/SdkNative.java @@ -298,8 +298,6 @@ public static native void gridContextTriggerHistory(long context, GetGridTrigger public static native void gridContextRestart(long context, String orderId, AsyncCallback callback); - public static native void gridContextSubmitStrategyQuestionnaire(long context, AsyncCallback callback); - public static native void gridContextSymbolInfo(long context, String symbol, AsyncCallback callback); // ── DCAContext ──────────────────────────────────────────────── diff --git a/java/javasrc/src/main/java/com/longbridge/grid/GridContext.java b/java/javasrc/src/main/java/com/longbridge/grid/GridContext.java index af2b75104..42f29f37d 100644 --- a/java/javasrc/src/main/java/com/longbridge/grid/GridContext.java +++ b/java/javasrc/src/main/java/com/longbridge/grid/GridContext.java @@ -159,19 +159,6 @@ public CompletableFuture restart(String orderId) throws OpenApiException { }); } - /** - * Submit the strategy risk-disclosure questionnaire record (grid trading - * compliance authorization). - * - * @return A Future representing the result of the operation - * @throws OpenApiException If an error occurs - */ - public CompletableFuture submitStrategyQuestionnaire() throws OpenApiException { - return AsyncCallback.executeTask((callback) -> { - SdkNative.gridContextSubmitStrategyQuestionnaire(raw(), callback); - }); - } - /** * Get the security (symbol) info used to build a grid order (lot size, * authorization flag, settlement currency, etc.). diff --git a/java/src/grid_context.rs b/java/src/grid_context.rs index d215ee455..d16b92fad 100644 --- a/java/src/grid_context.rs +++ b/java/src/grid_context.rs @@ -10,7 +10,7 @@ use longbridge::{ grid::{ GetGridOrderDetailOptions, GetGridOrdersByIdsOptions, GetGridOrdersOptions, GetGridTriggerHistoryOptions, GridContext, GridTradeRule, ReplaceGridOrderOptions, - SubmitGridOrderOptions, SubmitStrategyQuestionnaireOptions, + SubmitGridOrderOptions, }, }; @@ -342,25 +342,6 @@ pub unsafe extern "system" fn Java_com_longbridge_SdkNative_gridContextRestart( }) } -#[unsafe(no_mangle)] -pub unsafe extern "system" fn Java_com_longbridge_SdkNative_gridContextSubmitStrategyQuestionnaire( - mut env: JNIEnv, - _class: JClass, - context: i64, - callback: JObject, -) { - jni_result(&mut env, (), |env| { - let context = &*(context as *const ContextObj); - let __owned_ctx = context.ctx.clone(); - async_util::execute(env, callback, async move { - Ok(__owned_ctx - .submit_strategy_questionnaire(SubmitStrategyQuestionnaireOptions::new()) - .await?) - })?; - Ok(()) - }) -} - #[unsafe(no_mangle)] pub unsafe extern "system" fn Java_com_longbridge_SdkNative_gridContextSymbolInfo( mut env: JNIEnv, diff --git a/nodejs/index.d.ts b/nodejs/index.d.ts index e4cfe7225..e40e0e025 100644 --- a/nodejs/index.d.ts +++ b/nodejs/index.d.ts @@ -898,11 +898,6 @@ export declare class GridContext { suspend(orderId: string): Promise /** Restart a grid trading order */ restart(orderId: string): Promise - /** - * Submit the strategy risk-disclosure questionnaire record (grid trading - * compliance authorization). - */ - submitStrategyQuestionnaire(): Promise /** * Get the security (symbol) info used to build a grid order (lot size, * authorization flag, settlement currency, etc.). @@ -7309,6 +7304,16 @@ export interface SubmitAttachedParams { activateRth?: OutsideRTH } +/** Options for submit grid trading order request */ +export interface SubmitGridOrderOptions { + /** Security code */ + symbol: string + /** Settlement currency */ + settlementCurrency: string + /** Grid trading rule */ + gridTradingRule: GridTradeRule +} + /** A leg of a multi-leg combination order to submit */ export interface SubmitMultiLegOrderLeg { /** Option symbol, in `ticker.region` format (e.g. `QQQ260731C764000.US`) */ @@ -7346,16 +7351,6 @@ export interface SubmitMultiLegOrderOptions { clientRequestId?: string } -/** Options for submit grid trading order request */ -export interface SubmitGridOrderOptions { - /** Security code */ - symbol: string - /** Settlement currency */ - settlementCurrency: string - /** Grid trading rule */ - gridTradingRule: GridTradeRule -} - /** Options for submit order request */ export interface SubmitOrderOptions { /** Security code */ diff --git a/nodejs/index.js b/nodejs/index.js index f3d26499b..88789ebfb 100644 --- a/nodejs/index.js +++ b/nodejs/index.js @@ -3,9 +3,6 @@ // @ts-nocheck /* auto-generated by NAPI-RS */ -const { createRequire } = require('node:module') -require = createRequire(__filename) - const { readFileSync } = require('node:fs') let nativeBinding = null const loadErrors = [] @@ -66,7 +63,7 @@ const isMuslFromChildProcess = () => { function requireNative() { if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) { try { - nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); + return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); } catch (err) { loadErrors.push(err) } @@ -78,7 +75,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-android-arm64') + const binding = require('longbridge-android-arm64') + const bindingPackageVersion = require('longbridge-android-arm64/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -89,7 +91,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-android-arm-eabi') + const binding = require('longbridge-android-arm-eabi') + const bindingPackageVersion = require('longbridge-android-arm-eabi/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -98,16 +105,39 @@ function requireNative() { } } else if (process.platform === 'win32') { if (process.arch === 'x64') { + if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') { + try { + return require('./longbridge.win32-x64-gnu.node') + } catch (e) { + loadErrors.push(e) + } try { + const binding = require('longbridge-win32-x64-gnu') + const bindingPackageVersion = require('longbridge-win32-x64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding + } catch (e) { + loadErrors.push(e) + } + } else { + try { return require('./longbridge.win32-x64-msvc.node') } catch (e) { loadErrors.push(e) } try { - return require('longbridge-win32-x64-msvc') + const binding = require('longbridge-win32-x64-msvc') + const bindingPackageVersion = require('longbridge-win32-x64-msvc/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } + } } else if (process.arch === 'ia32') { try { return require('./longbridge.win32-ia32-msvc.node') @@ -115,7 +145,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-win32-ia32-msvc') + const binding = require('longbridge-win32-ia32-msvc') + const bindingPackageVersion = require('longbridge-win32-ia32-msvc/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -126,7 +161,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-win32-arm64-msvc') + const binding = require('longbridge-win32-arm64-msvc') + const bindingPackageVersion = require('longbridge-win32-arm64-msvc/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -140,7 +180,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-darwin-universal') + const binding = require('longbridge-darwin-universal') + const bindingPackageVersion = require('longbridge-darwin-universal/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -151,7 +196,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-darwin-x64') + const binding = require('longbridge-darwin-x64') + const bindingPackageVersion = require('longbridge-darwin-x64/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -162,7 +212,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-darwin-arm64') + const binding = require('longbridge-darwin-arm64') + const bindingPackageVersion = require('longbridge-darwin-arm64/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -177,7 +232,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-freebsd-x64') + const binding = require('longbridge-freebsd-x64') + const bindingPackageVersion = require('longbridge-freebsd-x64/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -188,7 +248,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-freebsd-arm64') + const binding = require('longbridge-freebsd-arm64') + const bindingPackageVersion = require('longbridge-freebsd-arm64/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -204,7 +269,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-x64-musl') + const binding = require('longbridge-linux-x64-musl') + const bindingPackageVersion = require('longbridge-linux-x64-musl/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -215,7 +285,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-x64-gnu') + const binding = require('longbridge-linux-x64-gnu') + const bindingPackageVersion = require('longbridge-linux-x64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -228,7 +303,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-arm64-musl') + const binding = require('longbridge-linux-arm64-musl') + const bindingPackageVersion = require('longbridge-linux-arm64-musl/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -239,7 +319,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-arm64-gnu') + const binding = require('longbridge-linux-arm64-gnu') + const bindingPackageVersion = require('longbridge-linux-arm64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -252,7 +337,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-arm-musleabihf') + const binding = require('longbridge-linux-arm-musleabihf') + const bindingPackageVersion = require('longbridge-linux-arm-musleabihf/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -263,7 +353,46 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-arm-gnueabihf') + const binding = require('longbridge-linux-arm-gnueabihf') + const bindingPackageVersion = require('longbridge-linux-arm-gnueabihf/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding + } catch (e) { + loadErrors.push(e) + } + } + } else if (process.arch === 'loong64') { + if (isMusl()) { + try { + return require('./longbridge.linux-loong64-musl.node') + } catch (e) { + loadErrors.push(e) + } + try { + const binding = require('longbridge-linux-loong64-musl') + const bindingPackageVersion = require('longbridge-linux-loong64-musl/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding + } catch (e) { + loadErrors.push(e) + } + } else { + try { + return require('./longbridge.linux-loong64-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + const binding = require('longbridge-linux-loong64-gnu') + const bindingPackageVersion = require('longbridge-linux-loong64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -276,7 +405,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-riscv64-musl') + const binding = require('longbridge-linux-riscv64-musl') + const bindingPackageVersion = require('longbridge-linux-riscv64-musl/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -287,7 +421,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-riscv64-gnu') + const binding = require('longbridge-linux-riscv64-gnu') + const bindingPackageVersion = require('longbridge-linux-riscv64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -299,7 +438,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-ppc64-gnu') + const binding = require('longbridge-linux-ppc64-gnu') + const bindingPackageVersion = require('longbridge-linux-ppc64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -310,7 +454,12 @@ function requireNative() { loadErrors.push(e) } try { - return require('longbridge-linux-s390x-gnu') + const binding = require('longbridge-linux-s390x-gnu') + const bindingPackageVersion = require('longbridge-linux-s390x-gnu/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -320,34 +469,49 @@ function requireNative() { } else if (process.platform === 'openharmony') { if (process.arch === 'arm64') { try { - return require('./longbridge.linux-arm64-ohos.node') + return require('./longbridge.openharmony-arm64.node') } catch (e) { loadErrors.push(e) } try { - return require('longbridge-linux-arm64-ohos') + const binding = require('longbridge-openharmony-arm64') + const bindingPackageVersion = require('longbridge-openharmony-arm64/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } } else if (process.arch === 'x64') { try { - return require('./longbridge.linux-x64-ohos.node') + return require('./longbridge.openharmony-x64.node') } catch (e) { loadErrors.push(e) } try { - return require('longbridge-linux-x64-ohos') + const binding = require('longbridge-openharmony-x64') + const bindingPackageVersion = require('longbridge-openharmony-x64/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } } else if (process.arch === 'arm') { try { - return require('./longbridge.linux-arm-ohos.node') + return require('./longbridge.openharmony-arm.node') } catch (e) { loadErrors.push(e) } try { - return require('longbridge-linux-arm-ohos') + const binding = require('longbridge-openharmony-arm') + const bindingPackageVersion = require('longbridge-openharmony-arm/package.json').version + if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { loadErrors.push(e) } @@ -362,22 +526,36 @@ function requireNative() { nativeBinding = requireNative() if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { + let wasiBinding = null + let wasiBindingError = null try { - nativeBinding = require('./longbridge.wasi.cjs') + wasiBinding = require('./longbridge.wasi.cjs') + nativeBinding = wasiBinding } catch (err) { if (process.env.NAPI_RS_FORCE_WASI) { - loadErrors.push(err) + wasiBindingError = err } } - if (!nativeBinding) { + if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { try { - nativeBinding = require('longbridge-wasm32-wasi') + wasiBinding = require('longbridge-wasm32-wasi') + nativeBinding = wasiBinding } catch (err) { if (process.env.NAPI_RS_FORCE_WASI) { + if (!wasiBindingError) { + wasiBindingError = err + } else { + wasiBindingError.cause = err + } loadErrors.push(err) } } } + if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) { + const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error') + error.cause = wasiBindingError + throw error + } } if (!nativeBinding) { @@ -386,7 +564,12 @@ if (!nativeBinding) { `Cannot find native binding. ` + `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` + 'Please try `npm i` again after removing both package-lock.json and node_modules directory.', - { cause: loadErrors } + { + cause: loadErrors.reduce((err, cur) => { + cur.cause = err + return cur + }), + }, ) } throw new Error(`Failed to load native binding`) diff --git a/nodejs/src/grid/context.rs b/nodejs/src/grid/context.rs index 63127618d..8ed3b10e3 100644 --- a/nodejs/src/grid/context.rs +++ b/nodejs/src/grid/context.rs @@ -145,19 +145,6 @@ impl GridContext { Ok(()) } - /// Submit the strategy risk-disclosure questionnaire record (grid trading - /// compliance authorization). - #[napi] - pub async fn submit_strategy_questionnaire(&self) -> Result<()> { - self.ctx - .submit_strategy_questionnaire( - longbridge::grid::SubmitStrategyQuestionnaireOptions::new(), - ) - .await - .map_err(ErrorNewType)?; - Ok(()) - } - /// Get the security (symbol) info used to build a grid order (lot size, /// authorization flag, settlement currency, etc.). #[napi] diff --git a/python/pysrc/longbridge/openapi.pyi b/python/pysrc/longbridge/openapi.pyi index 34d30ad88..b0e6e23d0 100644 --- a/python/pysrc/longbridge/openapi.pyi +++ b/python/pysrc/longbridge/openapi.pyi @@ -8816,12 +8816,6 @@ class GridContext: order_id: Grid master order ID """ - def submit_strategy_questionnaire(self) -> None: - """ - Submit the strategy risk-disclosure questionnaire record (grid trading - compliance authorization). - """ - def symbol_info(self, symbol: str) -> GridSymbolInfo: """ Get the security (symbol) info used to build a grid order (lot size, diff --git a/python/src/grid/context.rs b/python/src/grid/context.rs index aee4be55b..e082a2c78 100644 --- a/python/src/grid/context.rs +++ b/python/src/grid/context.rs @@ -5,7 +5,6 @@ use longbridge::{ grid::{ GetGridOrderDetailOptions, GetGridOrdersByIdsOptions, GetGridOrdersOptions, GetGridTriggerHistoryOptions, ReplaceGridOrderOptions, SubmitGridOrderOptions, - SubmitStrategyQuestionnaireOptions, }, }; use pyo3::{PyResult, pyclass, pymethods}; @@ -174,16 +173,6 @@ impl GridContext { Ok(()) } - /// Submit the strategy risk-disclosure questionnaire record (grid trading - /// compliance authorization). - fn submit_strategy_questionnaire(&self) -> PyResult<()> { - let opts = SubmitStrategyQuestionnaireOptions::new(); - self.ctx - .submit_strategy_questionnaire(opts) - .map_err(ErrorNewType)?; - Ok(()) - } - /// Get the security (symbol) info used to build a grid order (lot size, /// authorization flag, settlement currency, etc.). fn symbol_info(&self, symbol: String) -> PyResult { diff --git a/rust/src/blocking/grid.rs b/rust/src/blocking/grid.rs index 99b6a62fc..e208c68ca 100644 --- a/rust/src/blocking/grid.rs +++ b/rust/src/blocking/grid.rs @@ -9,7 +9,7 @@ use crate::{ GetGridOrderDetailOptions, GetGridOrdersByIdsOptions, GetGridOrdersOptions, GetGridTriggerHistoryOptions, GridContext, GridOrder, GridOrderDetail, GridOrdersResponse, GridSymbolInfo, GridTriggerHistoryResponse, ReplaceGridOrderOptions, - SubmitGridOrderOptions, SubmitGridOrderResponse, SubmitStrategyQuestionnaireOptions, + SubmitGridOrderOptions, SubmitGridOrderResponse, }, }; @@ -93,15 +93,6 @@ impl GridContextSync { .call(move |ctx| async move { ctx.restart(order_id).await }) } - /// Submit the strategy risk-disclosure questionnaire record (blocking) - pub fn submit_strategy_questionnaire( - &self, - options: SubmitStrategyQuestionnaireOptions, - ) -> Result<()> { - self.rt - .call(move |ctx| async move { ctx.submit_strategy_questionnaire(options).await }) - } - /// Get the security (symbol) info used to build a grid order (blocking) pub fn symbol_info( &self, diff --git a/rust/src/grid/context.rs b/rust/src/grid/context.rs index c6fe94b27..417605a37 100644 --- a/rust/src/grid/context.rs +++ b/rust/src/grid/context.rs @@ -9,8 +9,7 @@ use crate::{ grid::{ GetGridOrderDetailOptions, GetGridOrdersByIdsOptions, GetGridOrdersOptions, GetGridTriggerHistoryOptions, GridOrder, GridOrderDetail, GridSymbolInfo, - ReplaceGridOrderOptions, SubmitGridOrderOptions, SubmitStrategyQuestionnaireOptions, - TriggerOrder, + ReplaceGridOrderOptions, SubmitGridOrderOptions, TriggerOrder, }, }; @@ -217,23 +216,6 @@ impl GridContext { Ok(()) } - /// Submit the strategy risk-disclosure questionnaire record (grid trading - /// compliance authorization). - pub async fn submit_strategy_questionnaire( - &self, - options: SubmitStrategyQuestionnaireOptions, - ) -> Result<()> { - self.0 - .http_cli - .request(Method::POST, "/v1/record/questionnaire") - .body(Json(options)) - .response::>() - .send() - .with_subscriber(self.0.log_subscriber.clone()) - .await?; - Ok(()) - } - /// Get the security (symbol) info used to build a grid order (lot size, /// authorization flag, settlement currency, etc.). pub async fn symbol_info(&self, symbol: impl Into) -> Result { diff --git a/rust/src/grid/requests/mod.rs b/rust/src/grid/requests/mod.rs index 51aee3a40..59e8cee45 100644 --- a/rust/src/grid/requests/mod.rs +++ b/rust/src/grid/requests/mod.rs @@ -4,7 +4,6 @@ mod get_grid_orders_by_ids; mod get_grid_trigger_history; mod replace_grid_order; mod submit_grid_order; -mod submit_strategy_questionnaire; pub use get_grid_order_detail::GetGridOrderDetailOptions; pub use get_grid_orders::GetGridOrdersOptions; @@ -12,4 +11,3 @@ pub use get_grid_orders_by_ids::GetGridOrdersByIdsOptions; pub use get_grid_trigger_history::GetGridTriggerHistoryOptions; pub use replace_grid_order::ReplaceGridOrderOptions; pub use submit_grid_order::SubmitGridOrderOptions; -pub use submit_strategy_questionnaire::SubmitStrategyQuestionnaireOptions; diff --git a/rust/src/grid/requests/submit_strategy_questionnaire.rs b/rust/src/grid/requests/submit_strategy_questionnaire.rs deleted file mode 100644 index 738a78090..000000000 --- a/rust/src/grid/requests/submit_strategy_questionnaire.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::collections::HashMap; - -use serde::Serialize; - -/// Options for submitting the strategy risk-disclosure questionnaire record. -/// -/// This records the user's consent to the strategy risk disclosure required -/// before using grid trading. The default body is -/// `{ "type": "strategy", "items": { "agree": "true" } }`. -#[derive(Debug, Serialize, Clone)] -pub struct SubmitStrategyQuestionnaireOptions { - r#type: String, - items: HashMap, -} - -impl Default for SubmitStrategyQuestionnaireOptions { - fn default() -> Self { - Self::new() - } -} - -impl SubmitStrategyQuestionnaireOptions { - /// Create a new `SubmitStrategyQuestionnaireOptions` with the strategy - /// consent body. - #[inline] - pub fn new() -> Self { - let mut items = HashMap::new(); - items.insert("agree".to_string(), "true".to_string()); - Self { - r#type: "strategy".to_string(), - items, - } - } -}