Rust Crypto Tracker is a real-time cryptocurrency price monitoring server built with Rust. This project uses the CoinAPI to fetch prices for multiple cryptocurrencies and broadcasts these updates to connected clients via WebSockets.
- Real-time cryptocurrency price updates
- Supports multiple cryptocurrencies
- WebSocket server to push updates to clients
- Asynchronous and concurrent operations with Tokio
- Uses Warp for the WebSocket server
- Rust (latest stable version)
- CoinAPI key (get it from CoinAPI)
-
Clone the repository:
git clone https://github.com/anantdubey16/rust_crypto_tracker.git cd rust_crypto_tracker
-
Set your CoinAPI key: Replace
your_api_key
insrc/main.rs
with your actual CoinAPI key.let api_key = "your_api_key";
-
Build the project:
cargo build
-
Run the server:
cargo run
-
Connect to WebSocket server: Open a WebSocket client and connect to
ws://127.0.0.1:3030/ws
to receive real-time price updates.
This file contains the main logic of the server:
- Imports and dependencies: Includes necessary libraries and modules.
- PriceUpdate struct: Defines the structure for price updates.
- handle_connection function: Manages WebSocket connections and message broadcasting.
- main function: Initializes the server, sets up WebSocket routes, and spawns tasks for fetching prices.
This file handles communication with the CoinAPI:
- CoinApiResponse struct: Deserializes API responses.
- fetch_price function: Fetches prices from CoinAPI for given asset IDs.