1 stable release
1.0.3 | Mar 21, 2024 |
---|
#1804 in Web programming
138 downloads per month
23KB
432 lines
Rust Spice SDK
Rust SDK for Spice.ai
Installation
Add the following to your Cargo.toml
:
[dependencies]
spice-rs = { git = "https://github.com/spiceai/spice-rs", tag = "v1.0.2" }
Usage
New client
use spiceai::Client;
#[tokio::main]
async fn main() {
let mut client = Client::new("API_KEY").await.unwrap();
}
Arrow Query
SQL Query
use spiceai::Client;
#[tokio::main]
async fn main() {
let mut client = Client::new("API_KEY").await.unwrap();
let data = client.query("SELECT * FROM eth.recent_blocks LIMIT 10;").await;
}
Firecache Query
Firecache SQL Query
use spiceai::Client;
#[tokio::main]
async fn main() {
let mut client = Client::new("API_KEY").await.unwrap();
let data = client.fire_query("SELECT * FROM eth.recent_blocks LIMIT 10;").await;
}
HTTP API
Prices
Get the supported pairs:
use spiceai::Client;
#[tokio::main]
async fn main() {
let mut client = Client::new("API_KEY").await.unwrap();
let supported_pairs = client.get_supported_pairs().await;
}
Get the latest price for a token pair:
use spiceai::Client;
#[tokio::main]
async fn main() {
let mut client = Client::new("API_KEY").await.unwrap();
let price_data = client.get_prices(&["BTC-USDC"]).await;
}
Get historical data:
use spiceai::Client;
use chrono::Utc;
use chrono::Duration;
use std::ops::Sub;
#[tokio::main]
async fn main() {
let mut client = Client::new("API_KEY").await.unwrap();
let now = Utc::now();
let start = now.sub(Duration::seconds(3600));
let historical_price_data = client
.get_historical_prices(&["BTC-USDC"], Some(start), Some(now), Option::None).await;
}
Documentation
Check out our Documentation to learn more about how to use the Rust SDK.
Dependencies
~30–47MB
~860K SLoC