Skip to content

Commit eadca7a

Browse files
committed
refactor: lazy WebSocket, sync context creation, unified tokio runtime (4.0.5)
- Lazy WebSocket connection: WS connects on first use instead of at creation. QuoteContext and TradeContext no longer perform any I/O at construction time. - Sync context creation: QuoteContext::new / TradeContext::new are now infallible synchronous functions returning Self directly. All language bindings updated accordingly: - C: lb_quote/trade_context_new returns the context pointer directly - C++: QuoteContext/TradeContext::create returns the object directly - Java: QuoteContext/TradeContext.create() returns the object directly - Node.js: QuoteContext/TradeContext.new is now a sync static method - Python: AsyncQuoteContext/TradeContext.create is now a sync classmethod - Rust blocking: QuoteContextSync/TradeContextSync::new returns Self directly - Unified tokio runtime: a single global LazyLock<Runtime> in the longbridge crate is shared across all bindings; no more per-binding runtimes. - member_id / quote_level / quote_package_details promoted to async API methods (were previously sync fields); updated across all bindings. - Java: fix Javadoc formatting in QuoteContext/TradeContext examples, add missing content package classes to compile task, use platform-aware classpath separator in Makefile.toml, add --enable-native-access=ALL-UNNAMED. - Node.js: update all doc-comment examples to sync QuoteContext/TradeContext.new. - Bump version to 4.0.5.
1 parent f5361b9 commit eadca7a

77 files changed

Lines changed: 1509 additions & 1428 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [4.0.5]
8+
9+
## Changed
10+
11+
- **All bindings:** `QuoteContext::new` / `TradeContext::new` are now synchronous and infallible — no more `await` or `.get()` at construction time. The WebSocket connection is established lazily on first use.
12+
- **All bindings:** `member_id`, `quote_level`, and `quote_package_details` are now async methods (were previously sync fields/properties).
13+
- **Rust:** A single global Tokio runtime is shared across all SDK components; per-binding runtimes removed.
14+
15+
## Fixed
16+
17+
- **Java:** Restored broken Javadoc comment formatting in `QuoteContext` and `TradeContext` example blocks.
18+
- **Java:** `Makefile.toml` now uses a platform-aware classpath separator (`:` on Unix, `;` on Windows) and adds `--enable-native-access=ALL-UNNAMED` to suppress JVM native-access warnings on JDK 17+.
19+
- **Java:** Added missing `content` package classes (`ContentContext`, `NewsItem`, `TopicItem`) to the compile task.
20+
- **Node.js:** Updated all doc-comment examples to use sync `QuoteContext.new(config)` / `TradeContext.new(config)`.
21+
722
# [4.0.4]
823

924
## Fixed

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ resolver = "3"
33
members = ["rust", "python", "nodejs", "java", "c", "mcp"]
44

55
[workspace.package]
6-
version = "4.0.4"
6+
version = "4.0.5"
77
edition = "2024"
88

99
[profile.release]
1010
lto = true
1111

1212
[workspace.dependencies]
13-
longbridge-wscli = { path = "rust/crates/wsclient", version = "4.0.4" }
14-
longbridge-httpcli = { path = "rust/crates/httpclient", version = "4.0.4" }
15-
longbridge-proto = { path = "rust/crates/proto", version = "4.0.4" }
16-
longbridge-candlesticks = { path = "rust/crates/candlesticks", version = "4.0.4" }
17-
longbridge-oauth = { path = "rust/crates/oauth", version = "4.0.4" }
18-
longbridge = { path = "rust", version = "4.0.4" }
13+
longbridge-wscli = { path = "rust/crates/wsclient", version = "4.0.5" }
14+
longbridge-httpcli = { path = "rust/crates/httpclient", version = "4.0.5" }
15+
longbridge-proto = { path = "rust/crates/proto", version = "4.0.5" }
16+
longbridge-candlesticks = { path = "rust/crates/candlesticks", version = "4.0.5" }
17+
longbridge-oauth = { path = "rust/crates/oauth", version = "4.0.5" }
18+
longbridge = { path = "rust", version = "4.0.5" }
1919

2020
tokio = "1.47.1"
2121
tokio-tungstenite = "0.27.0"

c/csrc/include/longbridge.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,9 +4261,7 @@ struct lb_oauth_t *lb_oauth_clone(const struct lb_oauth_t *oauth);
42614261
*/
42624262
void lb_oauth_free(struct lb_oauth_t *oauth);
42634263

4264-
void lb_quote_context_new(const struct lb_config_t *config,
4265-
lb_async_callback_t callback,
4266-
void *userdata);
4264+
const struct lb_quote_context_t *lb_quote_context_new(const struct lb_config_t *config);
42674265

42684266
void lb_quote_context_retain(const struct lb_quote_context_t *ctx);
42694267

@@ -4278,9 +4276,13 @@ void *lb_quote_context_userdata(const struct lb_quote_context_t *ctx);
42784276
void lb_quote_context_set_free_userdata_func(const struct lb_quote_context_t *ctx,
42794277
lb_free_userdata_func_t f);
42804278

4281-
int64_t lb_quote_context_member_id(const struct lb_quote_context_t *ctx);
4279+
void lb_quote_context_member_id(const struct lb_quote_context_t *ctx,
4280+
lb_async_callback_t callback,
4281+
void *userdata);
42824282

4283-
const char *lb_quote_context_quote_level(const struct lb_quote_context_t *ctx);
4283+
void lb_quote_context_quote_level(const struct lb_quote_context_t *ctx,
4284+
lb_async_callback_t callback,
4285+
void *userdata);
42844286

42854287
void lb_quote_context_quote_package_details(const struct lb_quote_context_t *ctx,
42864288
lb_async_callback_t callback,
@@ -4704,9 +4706,7 @@ void lb_quote_context_history_market_temperature(const struct lb_quote_context_t
47044706
lb_async_callback_t callback,
47054707
void *userdata);
47064708

4707-
void lb_trade_context_new(const struct lb_config_t *config,
4708-
lb_async_callback_t callback,
4709-
void *userdata);
4709+
const struct lb_trade_context_t *lb_trade_context_new(const struct lb_config_t *config);
47104710

47114711
void lb_trade_context_retain(const struct lb_trade_context_t *ctx);
47124712

c/src/async_call.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
use std::{
2-
ffi::c_void,
3-
future::Future,
4-
sync::{Arc, LazyLock},
5-
};
1+
use std::{ffi::c_void, future::Future, sync::Arc};
62

73
use longbridge::Result;
8-
use tokio::runtime::Runtime;
94

105
use crate::error::CError;
116

12-
static RUNTIME: LazyLock<Runtime> = LazyLock::new(|| {
13-
tokio::runtime::Builder::new_multi_thread()
14-
.enable_all()
15-
.build()
16-
.expect("create tokio runtime")
17-
});
18-
197
pub type CAsyncCallback = extern "C" fn(*const CAsyncResult);
208

219
#[derive(Debug, Copy, Clone)]
@@ -128,14 +116,13 @@ pub(crate) fn execute_async<P, F, T>(
128116
P: Send,
129117
{
130118
unsafe {
131-
let _guard = RUNTIME.enter();
132119
let ctx_pointer = ctx as usize;
133120
let userdata_pointer = userdata as usize;
134121

135122
if !ctx.is_null() {
136123
Arc::increment_strong_count(ctx);
137124
}
138-
tokio::spawn(async move {
125+
longbridge::runtime_handle().spawn(async move {
139126
match fut.await {
140127
Ok(res) => {
141128
let mut res = res.to_async_result(ctx_pointer as *const c_void);

0 commit comments

Comments
 (0)