#ai #sdk #spice #price #client #run-time #platform

spiceai

SDK for Spice.ai, an open-source runtime and platform for building AI-driven software

1 stable release

1.0.3 Mar 21, 2024

#1804 in Web programming

Download history 109/week @ 2024-03-16 13/week @ 2024-03-23 15/week @ 2024-03-30 1/week @ 2024-04-06

138 downloads per month

Apache-2.0

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