Thalex Rust SDK
This is a community-driven Rust SDK for interacting with the Thalex API, providing tools for real-time data streaming and market analysis.
Features
- WebSocket client for real-time data streaming
- Support for various market data types (OHLC, trades, quotes)
- Easy integration with Rust applications
- Callback based event handling
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!
Getting Started
To get started with the Thalex Rust SDK, install the crate via Cargo:
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.
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
THALEX_ENVIRONMENT (must be set to either Mainnet or Testnet)
Additionally you can create a client with a Custom environment by providing a WebSocket URL directly.
// examples/create_client.rs
use ;
async
Subscribing to Data Streams
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:
// examples/subscribe_ticker.rs
use ;
use Decimal;
use dec;
use init_with_level;
use ;
async
Creating Orders
The SDK also provides support for authenticated endpoints, allowing you to manage your account and place orders.
// examples/create_order.rs
use ;
async
Examples
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).
Documentation
The client is generated automatically from the Thalex OpenAPI specification using openapi-generator-cli.
The api is fully documented and available here.
Roadmap
- Initial release with WebSocket support for public data streams.
- Add support for private data streams and authenticated endpoints.
- Implement callback based event handling.
- Improve error handling and reconnection logic.
- Expand support for additional rpc endpoints.
-
- market data
-
- account management
-
- trading
-
- historical data
-
- market maker protection
-
- notifications
-
- bot management
-
- wallet operations
-
- rfq management
- Add more examples and documentation.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Development
To build and test the SDK locally, clone the repository and run:
This will run the test suite to ensure everything is working correctly.
For formatting and linting, use:
Codegen is used to regenerate the API client from the OpenAPI specification. To do this, ensure you have openapi-generator-cli installed and run:
This will update the generated code in the src/ directory.
Acknowledgements
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.