Crates.io | vyper-client-rs |
lib.rs | vyper-client-rs |
version | 0.2.1 |
source | src |
created_at | 2024-09-24 03:56:28.638489 |
updated_at | 2024-09-24 04:55:23.317521 |
description | A Rust SDK for Vyper client |
homepage | https://github.com/Vyper-Terminal/vyper-client-rs |
repository | https://github.com/Vyper-Terminal/vyper-client-rs |
max_upload_size | |
id | 1384752 |
size | 76,775 |
A Rust SDK for interacting with the Vyper API. This library allows developers to integrate Vyper's HTTP and WebSocket API into their Rust applications with ease.
To install the Vyper API Rust SDK, add the following to your Cargo.toml:
[dependencies]
vyper-client_rs = "0.1.0" # Replace with the actual version
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Here's a simple example to get you started:
use vyper_client_rs::client::VyperClient;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the client with your API key
let client = VyperClient::new("your_api_key_here");
// Get the list of chain IDs supported by Vyper
let chain_ids = client.get_chain_ids().await?;
println!("Supported chain IDs: {:?}", chain_ids);
Ok(())
}
Retrieve the market data for a specific token:
use vyper_client_rs::client::VyperClient;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = VyperClient::new("your_api_key_here");
// Fetch the All-Time High (ATH) data for a token
let token_ath = client
.get_token_ath(1, "AVs9TA4nWDzfPJE9gGVNJMVhcQy3V9PGazuz33BfG2RA")
.await?;
println!("Market Cap USD: {}", token_ath.market_cap_usd);
println!("Timestamp: {}", token_ath.timestamp);
Ok(())
}
use vyper_client_rs::websocket::{VyperWebsocketClient, FeedType, SubscriptionType, TokenSubscriptionMessage, SubscriptionMessageType};
use serde_json::Value;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ws_client = VyperWebsocketClient::new("your_api_key_here".to_string());
// Define a message handler
let handler = move |message: Value| {
println!("Received message: {:?}", message);
};
ws_client.set_message_handler(handler);
// Connect to the WebSocket and subscribe to token events
ws_client.connect(FeedType::TokenEvents).await?;
ws_client
.subscribe(
FeedType::TokenEvents,
TokenSubscriptionMessage {
action: SubscriptionMessageType::Subscribe,
types: vec![SubscriptionType::PumpfunTokens],
},
)
.await?;
println!("Subscribed to token events");
// Start listening for messages
ws_client.listen().await?;
Ok(())
}
For detailed information on the Vyper API, refer to the official documentation: