SDKs
Java Integration
Java Integration
Access Hive Intelligence using Java's HttpClient.
Requirements: Java 11+
Quick Start
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class HiveExample {
private static final String API_URL = "https://api.hiveintelligence.xyz/api/execute";
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"toolName": "get_price",
"arguments": {
"ids": "bitcoin",
"vs_currencies": "usd"
}
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(API_URL))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
Helper Client Class
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
public class HiveClient {
private final String baseUrl;
private final HttpClient httpClient;
private final ObjectMapper objectMapper;
public HiveClient() {
this("https://api.hiveintelligence.xyz");
}
public HiveClient(String baseUrl) {
this.baseUrl = baseUrl;
this.httpClient = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(30))
.build();
this.objectMapper = new ObjectMapper();
}
public Map<String, Object> execute(String toolName, Map<String, Object> arguments) throws Exception {
Map<String, Object> payload = Map.of(
"toolName", toolName,
"arguments", arguments
);
String json = objectMapper.writeValueAsString(payload);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(baseUrl + "/api/execute"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
throw new RuntimeException("API error: " + response.statusCode());
}
return objectMapper.readValue(response.body(), Map.class);
}
public double getPrice(String coinId, String currency) throws Exception {
Map<String, Object> result = execute("get_price", Map.of(
"ids", coinId,
"vs_currencies", currency
));
Map<String, Object> data = (Map<String, Object>) result.get("data");
Map<String, Object> coin = (Map<String, Object>) data.get(coinId);
return ((Number) coin.get(currency)).doubleValue();
}
public static void main(String[] args) throws Exception {
HiveClient client = new HiveClient();
double btcPrice = client.getPrice("bitcoin", "usd");
System.out.printf("Bitcoin: $%.2f%n", btcPrice);
}
}
With Jackson for JSON
Add to your pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.0</version>
</dependency>
Type-Safe Responses
import com.fasterxml.jackson.annotation.JsonProperty;
// Response DTOs
public class HiveResponse<T> {
private T data;
private String error;
public T getData() { return data; }
public String getError() { return error; }
}
public class SecurityData {
@JsonProperty("is_honeypot")
private boolean isHoneypot;
@JsonProperty("is_open_source")
private boolean isOpenSource;
@JsonProperty("buy_tax")
private String buyTax;
@JsonProperty("sell_tax")
private String sellTax;
@JsonProperty("holder_count")
private int holderCount;
// Getters
public boolean isHoneypot() { return isHoneypot; }
public boolean isOpenSource() { return isOpenSource; }
public String getBuyTax() { return buyTax; }
public String getSellTax() { return sellTax; }
public int getHolderCount() { return holderCount; }
}
// Usage
public <T> T executeTyped(String toolName, Map<String, Object> arguments, Class<T> responseType) throws Exception {
Map<String, Object> result = execute(toolName, arguments);
return objectMapper.convertValue(result.get("data"), responseType);
}
// Example
SecurityData security = client.executeTyped(
"get_token_security",
Map.of("contract_addresses", "0x...", "chain_id", "1"),
SecurityData.class
);
if (security.isHoneypot()) {
System.out.println("WARNING: Honeypot detected!");
}
Working with Tools
Market Data
HiveClient client = new HiveClient();
// Get market data
Map<String, Object> marketData = client.execute("get_coins_market_data", Map.of(
"vs_currency", "usd",
"order", "market_cap_desc",
"per_page", 10
));
// Get trending
Map<String, Object> trending = client.execute("get_trending", Map.of());
DeFi Analytics
// Get all protocols
Map<String, Object> protocols = client.execute("get_protocols", Map.of());
// Get yield pools
Map<String, Object> yields = client.execute("get_yield_pools", Map.of(
"chain", "ethereum"
));
Security Analysis
// Check token security
Map<String, Object> result = client.execute("get_token_security", Map.of(
"contract_addresses", "0x...",
"chain_id", "1"
));
Map<String, Object> security = (Map<String, Object>) result.get("data");
if (Boolean.TRUE.equals(security.get("is_honeypot"))) {
System.out.println("WARNING: Honeypot detected!");
}
String sellTax = (String) security.get("sell_tax");
if (Double.parseDouble(sellTax) > 10) {
System.out.println("WARNING: High sell tax: " + sellTax + "%");
}
Async Support
import java.util.concurrent.CompletableFuture;
public class AsyncHiveClient extends HiveClient {
public CompletableFuture<Map<String, Object>> executeAsync(String toolName, Map<String, Object> arguments) {
return CompletableFuture.supplyAsync(() -> {
try {
return execute(toolName, arguments);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
}
// Usage
AsyncHiveClient client = new AsyncHiveClient();
CompletableFuture<Double> btcFuture = client.executeAsync("get_price", Map.of(
"ids", "bitcoin", "vs_currencies", "usd"
)).thenApply(result -> {
Map<String, Object> data = (Map<String, Object>) result.get("data");
Map<String, Object> btc = (Map<String, Object>) data.get("bitcoin");
return ((Number) btc.get("usd")).doubleValue();
});
CompletableFuture<Double> ethFuture = client.executeAsync("get_price", Map.of(
"ids", "ethereum", "vs_currencies", "usd"
)).thenApply(result -> {
Map<String, Object> data = (Map<String, Object>) result.get("data");
Map<String, Object> eth = (Map<String, Object>) data.get("ethereum");
return ((Number) eth.get("usd")).doubleValue();
});
CompletableFuture.allOf(btcFuture, ethFuture).join();
System.out.printf("BTC: $%.2f, ETH: $%.2f%n", btcFuture.get(), ethFuture.get());
Error Handling
public Map<String, Object> executeSafe(String toolName, Map<String, Object> arguments) {
try {
Map<String, Object> payload = Map.of(
"toolName", toolName,
"arguments", arguments
);
String json = objectMapper.writeValueAsString(payload);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(baseUrl + "/api/execute"))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(30))
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 429) {
throw new RuntimeException("Rate limited. Wait and retry.");
}
if (response.statusCode() != 200) {
throw new RuntimeException("API error: status " + response.statusCode());
}
return objectMapper.readValue(response.body(), Map.class);
} catch (java.net.http.HttpTimeoutException e) {
throw new RuntimeException("Request timed out", e);
} catch (Exception e) {
throw new RuntimeException("Request failed: " + e.getMessage(), 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 |