| Crates.io | thalex_rust_sdk |
| lib.rs | thalex_rust_sdk |
| version | 0.1.24 |
| created_at | 2025-12-30 14:03:59.771953+00 |
| updated_at | 2026-01-20 13:55:03.664703+00 |
| description | Trading client for Thalex exchange |
| homepage | |
| repository | https://github.com/8ball030/thalex_rust_sdk |
| max_upload_size | |
| id | 2012689 |
| size | 2,033,592 |
This is a community-driven Rust SDK for interacting with the Thalex API, providing tools for real-time data streaming and market analysis.
Note, this SDK is not officially maintained by Thalex but is developed and supported by the community. It is a work in progress, and contributions are welcome!
To get started with the Thalex Rust SDK, install the crate via Cargo:
cargo add thalex_rust_sdk
A client can be either public or private, depending on whether you need to access authenticated endpoints. For public access, you can create a WsClient without any authentication parameters.
use thalex_rust_sdk::ws_client::WsClient;
#[tokio::main]
async fn main() {
let ws_client = WsClient::new_public().await.unwrap();
// Use the client...
}
For private access, you will need to get an API key and secret from your Thalex account and create a WsClient with those credentials.
A helpful instantiation method is provided to create a private client using the following environment variables:
THALEX_PRIVATE_KEY_PATH
THALEX_KEY_ID
THALEX_ACCOUNT_ID
use thalex_rust_sdk::ws_client::WsClient;
#[tokio::main]
async fn main
{
let ws_client = WsClient::from_env().await.unwrap();
// Use the client...
}
Once you have a WsClient instance, you can subscribe to various data streams.
A callback based approach is used to handle incoming messages.
For example, to subscribe to ticker OHLC data:
let _ = client
.subscriptions()
.market_data()
.ticker("BTC-PERPETUAL", Delay::Variant1000ms, |msg| {
// Parses into a json value initally
async move {
let best_bid_price: f64 = msg.best_bid_price.unwrap();
let best_ask_price: f64 = msg.best_ask_price.unwrap();
let index_price = msg.index.unwrap();
// Check if all non-optional fields are present
let spread = best_ask_price - best_bid_price;
let index_delta = msg.mark_price.unwrap() - index_price;
let index_delta_bps = if index_price != 0.0 {
(index_delta / index_price) * 10000.0
} else {
0.0
};
info!(
"Ticker update - Bid: {best_bid_price}, Ask: {best_ask_price} spread: {spread} index: {index_price} index_delta_bps: {index_delta_bps}"
);
}
})
.await;
client.wait_for_connection().await;
info!("Starting receive loop!");
loop {
match client.run_till_event().await {
ExternalEvent::Connected => {
client.resubscribe_all().await.ok();
}
ExternalEvent::Disconnected => continue,
ExternalEvent::Exited => break,
}
}
The SDK includes several example applications demonstrating its capabilities. You can find them in the examples
directory. To run an example, use the following command:
bashcargo run --example <example_name>
Replace <example_name> with the name of the example file (without the .rs extension).
The client is generated automatically from the Thalex OpenAPI specification using openapi-generator-cli.
The api is fully documented and available here.
Contributions are welcome! Please feel free to submit issues and pull requests on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.
To build and test the SDK locally, clone the repository and run:
make test
This will run the test suite to ensure everything is working correctly.
For formatting and linting, use:
make fmt
make lint
Codegen is used to regenerate the API client from the OpenAPI specification. To do this, ensure you have openapi-generator-cli installed and run:
make all
This will update the generated code in the src/ directory.
This SDK is inspired by and builds upon the work of various open-source projects in the Rust ecosystem and the Thalex community. Special thanks to the team at Thalex for their support and for providing a robust API.