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
rustup
andcargo
)
-
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
rustup
andcargo
installed. Follow the installation instructions here. -
Configure the
.env
filetThe project uses a
.env
file for configuration. Create a.env
file in the root directory with the following:SERVER_HOST=127.0.0.1:8080 RUST_LOG=info
SERVER_HOST
specifies the address where the WebSocket server will listen. If not set, it defaults to127.0.0.1:8080
RUST_LOG
controls the log level (e.g., info, warn). Set it to info to see detailed logs.
-
Configure the
tokens.json
fileCreate or modify the
tokens.json
file 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.json
are 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
.