A WebSocket server that manages clients based on tokens listed in config.json. Every 10 seconds, it requests token price, symbol, and datetime from each client. The server fetches this data using the CoinGecko API for tokens on the Sui blockchain via their contract_address.
Before running the project, you will need to have the following installed:
- Rust (via
rustupandcargo)
-
Clone the repository
Clone the repository to your local machine:
git clone https://github.com/juliog922/suicrypto_oracle.git cd suicrypto_oracle -
Install Rust
Make sure you have
rustupandcargoinstalled. Follow the installation instructions here. -
Configure the
.envfiletThe project uses a
.envfile for configuration. Create a.envfile in the root directory with the following:SERVER_HOST=127.0.0.1:8080 RUST_LOG=info
SERVER_HOSTspecifies the address where the WebSocket server will listen. If not set, it defaults to127.0.0.1:8080RUST_LOGcontrols the log level (e.g., info, warn). Set it to info to see detailed logs.
-
Configure the
tokens.jsonfileCreate or modify the
tokens.jsonfile to include a list of tokens:{ "tokens": ["DEEP", "SUI", "SUDENG"] }
- The tokens key should contain a list of token names.
- If the file doesn't contain this structure, the program will throw an error.
- If the tokens are misspelled or not found on the Sui network, a warning will appear.
-
Runing the Server
To start the WebSocket server, use the following command:
cargo run --bin server
-
Once the server starts, you will see the following message in the terminal:
Server listening on 127.0.0.1:8080
-
If there are no clients connected, the server will print the following warning:
Broadcast Channel Error: No clients listening
-
Running the Clients
In a separate terminal, start the client for each token by running:
cargo run --bin client
-
Once the client connects, you will see:
Client created: <token_name> Client connected with Token: <token_name>
-
Once the server requests token data, the client will send the price, symbol, and datetime in this format:
Message received from client: {"price":<token_price>,"symbol":<token_symbol>,"timestamp":<token_price_datetime>}
The logs are printed using the log crate, with info and warn levels.
If RUST_LOG=info is set, you will see detailed log messages. Otherwise, only warnings will appear.
-
When the server shuts down or a client disconnects, you will see:
Client disconnected
-
To run the project's tests, execute the following command:
cargo test
This will run all unit and integration tests in the project.
-
Ensure the token names in
tokens.jsonare correctly spelled and belong to the Sui network. -
The server and client can be run on separate machines as long as they can connect to each other via the configured
SERVER_HOST.