Bulk Price Engine is a Rust-based WebSocket server that provides real-time price information for various tokens. It uses the Jupiter API to fetch token prices and streams this information to connected clients. The API is built with Actix Web and supports multiple concurrent connections for different tokens.
- Real-time price updates via WebSocket connections
- Support for multiple tokens (solana)
- Automatic price fetching and caching
- Connection-based resource management
- Exponential backoff for API request retries
- Health check endpoint
- Rust (latest stable version)
- Cargo (Rust's package manager)
-
Clone the repository:
git clone https://github.com/Bulk-trade/price-engine cd price-engine
-
Create a
.env
file in the project root and add the following environment variables:JUPITER_API_URL=https://public.jupiterapi.com IP_ADDRESS=0.0.0.0 PORT=8080
-
Build the project:
cargo build
To run the server in development mode:
cargo run
For production, use:
cargo run --release
Connect to the WebSocket endpoint:
ws://<server-address>/ws/price?token=<token-mint>&token_decimal=<decimal-places>
<server-address>
: The address where the server is running (e.g.,localhost:8080
)<token-mint>
: The mint address of the token you want to get prices for<decimal-places>
: The number of decimal places for the token (optional, defaults to 6)
Example:
ws://localhost:8080/ws/price?token=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&token_decimal=6
To check the health of the API:
GET http://<server-address>/health
For development with auto-reloading:
cargo watch -x 'run'
Key dependencies include:
actix-web
: Web frameworkactix-web-actors
: WebSocket supporttokio
: Asynchronous runtimeserde
: Serialization/deserializationreqwest
: HTTP clientbackoff
: Exponential backoff for retries
For a full list of dependencies, refer to the Cargo.toml
file.
graph TD
A[Client] -->|WebSocket Connection| B(WebSocket Handler)
B -->|Initialize| C{Price in Cache?}
C -->|Yes| D[Send Cached Price]
C -->|No| E[Fetch Price]
E -->|API Request| F[Jupiter API]
F -->|Response| G[Parse Price]
G -->|Store| H[Price Cache]
H -->|Send| D
B -->|Start| I[Price Update Loop]
I -->|Every 3s| J{Active Connections?}
J -->|Yes| K[Fetch New Price]
K -->|Update| H
J -->|No| L[Stop Updates]
M[Health Check API] -->|Check| H
This application can be run in a Docker container, which includes an auto-restart mechanism for improved reliability.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/Bulk-trade/price-engine.git cd price-engine
-
Build the Docker image:
docker-compose build
-
Start the container:
docker-compose up
The Bulk Price Engine will now be running and accessible at http://localhost:8080
. It will automatically restart if it crashes.
You can modify the following environment variables in the docker-compose.yml
file:
RUST_LOG
: Set the log level (e.g., debug, info, warn)JUPITER_API_URL
: The URL for the Jupiter API Hosted Jupiter Swap APIIP_ADDRESS
: The IP address to bind to (default: 0.0.0.0)PORT
: The port to run the application on (default: 8080)
To stop the application, use:
docker-compose down
This will stop and remove the containers created by docker-compose.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Bulk Labs Limited Open Source Attribution License. See the LICENSE file in the root directory of this project for the full license text.