#server-connection #subscription #client-server #real-time #events #lightstreamer

bin+lib lightstreamer-client

A Rust client for Lightstreamer, designed to facilitate real-time communication with Lightstreamer servers

10 releases

0.1.9 Apr 13, 2024
0.1.8 Apr 13, 2024
0.1.0 Mar 23, 2024

#94 in WebSocket


Used in ig_trading_api

GPL-3.0-only

250KB
2K SLoC

Lightstreamer Rust Client SDK

This project is a partial implementation of the Lightstreamer TLCP (Text-based Live Connections Protocol) in Rust. It provides a client SDK to interact with Lightstreamer servers, focused on supporting the specific needs of the ig_trading_api project.

Features

  • Full-duplex WebSocket-based connection mode.
  • Subscriptions to items and item groups.
  • MERGE subscription mode.
  • Listening to connection events and messages.
  • Configuration of connection options and connection details.
  • Subscription lifecycle management.
  • Retrieval of real-time item updates.

Please note that this SDK currently does not support all the features and capabilities of the full Lightstreamer protocol. It has been developed to cover the requirements of the ig_trading_api project mentioned above. Features like other connection modes, subscription modes (DISTINCT, RAW, COMMAND), and some other advanced options are not implemented at this time.

Installation

To use this SDK in your Rust project, add the following dependency to your Cargo.toml:

[dependencies]
lightstreamer-client = "0.1.9"

Usage

Here's a minimal example of how to use the Lightstreamer Rust Client SDK:

use lightstreamer_client::ls_client::LightstreamerClient;
use lightstreamer_client::subscription::{Subscription, SubscriptionMode};

#[tokio::main]
async fn main() {
    // Create a Lightstreamer client
    let client = LightstreamerClient::new(
        Some("http://push.lightstreamer.com/lightstreamer"), // Lightstreamer server
        Some("DEMO"), // adapter set
        None, // username
        None, // password
    ).unwrap();

    // Create a subscription
    let mut subscription = Subscription::new(
        SubscriptionMode::Merge,
        Some(vec!["item1".to_string(), "item2".to_string()]),
        Some(vec!["field1".to_string(), "field2".to_string()]),
    ).unwrap();

    // Subscribe and connect
    client.subscribe(subscription);
    client.connect(None).await.unwrap();
}

For a more advanced example of how to use the SDK to subscribe to item updates, refer to the main.rs file in the project source code. It demonstrates creating a Lightstreamer client, setting up subscriptions, handling item updates, and managing the connection lifecycle with a configurable number of connection attempts.

For more details on using the SDK, please refer to the reference documentation.

Documentation

The full SDK documentation is available at docs.rs.

Project Structure

Although this SDK does not provide a complete implementation of the Lightstreamer protocol, it has been built with a solid structure and scaffolding, similar to the official Lightstreamer libraries. The code is documented, and the project is designed to facilitate contributions from the community to add support for missing features.

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Contributing

Contributions are welcome. Please open an issue or submit a pull request to propose changes and help complete the SDK with additional Lightstreamer features.

Dependencies

~8–20MB
~312K SLoC