Real-Time Stock Price Ticker with Latency Measurement
π Overview This project is a real-time stock price ticker that connects to the Binance WebSocket API using Rust. It fetches live price updates for a specified cryptocurrency pair (like BTC/USDT) and displays the current price along with the latency of the data received. The project demonstrates low-latency data processing and efficient handling of real-time WebSocket data.
π Features Real-time stock price updates from Binance. Measurement of latency between receiving and processing data. Efficient WebSocket handling using tokio and tokio-tungstenite. Built in Rust, emphasizing performance and low latency.
π οΈ Technologies Used Rust: For building a high-performance and low-latency application. Tokio: For asynchronous programming. tokio-tungstenite: For WebSocket communication. serde: For JSON serialization and deserialization.
π¦ Project Structure
src/ β βββ main.rs # Entry point of the application βββ websocket.rs # WebSocket connection and message handling βββ price_feed.rs # Processing and displaying price data βββ utils.rs # Utility functions (if any) βββ Cargo.toml # Project dependencies and configuration
βοΈ Setup & Installation
Prerequisites Make sure you have Rust installed. If not, you can install it from here. Step-by-Step Guide Clone the repository:
bash Copy code git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name Install dependencies:
bash Copy code cargo build Run the application:
bash Copy code cargo run -- Replace with the cryptocurrency symbol (e.g., btcusdt for Bitcoin to USDT).
π Usage Example To see real-time updates and latency measurements for Bitcoin to USDT:
bash Copy code cargo run -- btcusdt Example Output:
makefile Copy code Connected to Binance WebSocket for btcusdt BTC/USDT: $29450.23 Latency: 50 Β΅s BTC/USDT: $29451.05 Latency: 45 Β΅s
β‘ Optimizations & Future Enhancements
Better error handling: Improve how the application handles WebSocket disconnections and errors. Support for multiple symbols: Add support to monitor multiple symbols at once. Visual dashboard: Create a simple UI to visualize prices and latency in real-time. Further optimizations: Optimize deserialization and data handling for even lower latency.