SDKs
Rust Integration
Rust Integration
Access Hive Intelligence using the reqwest crate.
Installation
Add to your Cargo.toml:
[dependencies]
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }
Quick Start
use reqwest::Client;
use serde_json::{json, Value};
const API_URL: &str = "https://api.hiveintelligence.xyz/api/execute";
async fn call_hive(tool_name: &str, args: Value) -> Result<Value, reqwest::Error> {
let client = Client::new();
let response = client
.post(API_URL)
.json(&json!({
"toolName": tool_name,
"arguments": args
}))
.send()
.await?
.json()
.await?;
Ok(response)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = call_hive("get_price", json!({
"ids": "bitcoin",
"vs_currencies": "usd"
})).await?;
println!("Bitcoin: ${}", result["data"]["bitcoin"]["usd"]);
Ok(())
}
Helper Client
use reqwest::Client;
use serde_json::{json, Value};
use std::time::Duration;
pub struct HiveClient {
client: Client,
base_url: String,
}
impl HiveClient {
pub fn new() -> Self {
Self {
client: Client::builder()
.timeout(Duration::from_secs(30))
.build()
.unwrap(),
base_url: "https://api.hiveintelligence.xyz".to_string(),
}
}
pub async fn execute(&self, tool_name: &str, args: Value) -> Result<Value, reqwest::Error> {
let response = self.client
.post(format!("{}/api/execute", self.base_url))
.json(&json!({
"toolName": tool_name,
"arguments": args
}))
.send()
.await?
.json()
.await?;
Ok(response)
}
pub async fn get_price(&self, coin_id: &str, currency: &str) -> Result<f64, Box<dyn std::error::Error>> {
let result = self.execute("get_price", json!({
"ids": coin_id,
"vs_currencies": currency
})).await?;
let price = result["data"][coin_id][currency]
.as_f64()
.ok_or("Failed to parse price")?;
Ok(price)
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HiveClient::new();
let btc_price = client.get_price("bitcoin", "usd").await?;
println!("Bitcoin: ${:.2}", btc_price);
Ok(())
}
Type-Safe Responses
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct HiveResponse<T> {
pub data: T,
}
#[derive(Debug, Deserialize)]
pub struct PriceData {
pub bitcoin: Option<CurrencyPrice>,
pub ethereum: Option<CurrencyPrice>,
}
#[derive(Debug, Deserialize)]
pub struct CurrencyPrice {
pub usd: f64,
}
#[derive(Debug, Deserialize)]
pub struct SecurityData {
pub is_honeypot: bool,
pub is_open_source: bool,
pub is_mintable: bool,
pub buy_tax: String,
pub sell_tax: String,
pub holder_count: u64,
}
impl HiveClient {
pub async fn execute_typed<T: for<'de> Deserialize<'de>>(
&self,
tool_name: &str,
args: Value
) -> Result<HiveResponse<T>, reqwest::Error> {
self.client
.post(format!("{}/api/execute", self.base_url))
.json(&json!({
"toolName": tool_name,
"arguments": args
}))
.send()
.await?
.json()
.await
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HiveClient::new();
// Typed price response
let price: HiveResponse<PriceData> = client.execute_typed("get_price", json!({
"ids": "bitcoin",
"vs_currencies": "usd"
})).await?;
if let Some(btc) = &price.data.bitcoin {
println!("Bitcoin: ${:.2}", btc.usd);
}
// Typed security response
let security: HiveResponse<SecurityData> = client.execute_typed("get_token_security", json!({
"contract_addresses": "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
"chain_id": "1"
})).await?;
println!("Honeypot: {}", security.data.is_honeypot);
println!("Sell Tax: {}%", security.data.sell_tax);
Ok(())
}
Working with Tools
Market Data
let client = HiveClient::new();
// Get market data
let market_data = client.execute("get_coins_market_data", json!({
"vs_currency": "usd",
"order": "market_cap_desc",
"per_page": 10
})).await?;
// Get trending
let trending = client.execute("get_trending", json!({})).await?;
DeFi Analytics
// Get protocols
let protocols = client.execute("get_protocols", json!({})).await?;
// Get yields
let yields = client.execute("get_yield_pools", json!({
"chain": "ethereum"
})).await?;
Security Analysis
// Check token security
let security = client.execute("get_token_security", json!({
"contract_addresses": "0x...",
"chain_id": "1"
})).await?;
if security["data"]["is_honeypot"].as_bool().unwrap_or(false) {
println!("WARNING: Honeypot detected!");
}
Concurrent Requests
use futures::future::join_all;
async fn get_multiple_prices(
client: &HiveClient,
coins: &[&str]
) -> Result<Vec<(String, f64)>, Box<dyn std::error::Error>> {
let futures: Vec<_> = coins
.iter()
.map(|coin| async move {
let price = client.get_price(coin, "usd").await?;
Ok::<_, Box<dyn std::error::Error>>((coin.to_string(), price))
})
.collect();
let results = join_all(futures).await;
results.into_iter().collect()
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HiveClient::new();
let prices = get_multiple_prices(&client, &["bitcoin", "ethereum", "solana"]).await?;
for (coin, price) in prices {
println!("{}: ${:.2}", coin, price);
}
Ok(())
}
Error Handling
use thiserror::Error;
#[derive(Error, Debug)]
pub enum HiveError {
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("Rate limited")]
RateLimited,
#[error("API error: {0}")]
Api(String),
#[error("Parse error: {0}")]
Parse(String),
}
impl HiveClient {
pub async fn execute_safe(&self, tool_name: &str, args: Value) -> Result<Value, HiveError> {
let response = self.client
.post(format!("{}/api/execute", self.base_url))
.json(&json!({
"toolName": tool_name,
"arguments": args
}))
.send()
.await?;
match response.status().as_u16() {
429 => Err(HiveError::RateLimited),
200 => Ok(response.json().await?),
status => Err(HiveError::Api(format!("Status: {}", status))),
}
}
}
#[tokio::main]
async fn main() {
let client = HiveClient::new();
match client.execute_safe("get_price", json!({
"ids": "bitcoin",
"vs_currencies": "usd"
})).await {
Ok(result) => println!("Price: {}", result["data"]["bitcoin"]["usd"]),
Err(HiveError::RateLimited) => println!("Rate limited. Wait and retry."),
Err(e) => println!("Error: {}", e),
}
}
Quick Reference
| Tool | Description |
|---|---|
get_price | Get current prices |
get_coins_market_data | Market data with pagination |
get_trending | Trending coins |
get_protocols | DeFi protocol list |
get_token_security | Token security analysis |
get_wallet_balance | Wallet balances |