Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated Asset Prices API support #35

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,54 +55,6 @@ async fn main() {

```

### HTTP API

#### Prices

Get the supported pairs:

```rust
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:

```rust
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:

```rust
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](https://docs.spice.ai/sdks/rust-sdk) to learn more about how to use the Rust SDK.
66 changes: 2 additions & 64 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::{
config::{FIRECACHE_ADDR, FLIGHT_ADDR, HTTPS_ADDR},
flight::SqlFlightClient,
prices::PricesClient,
tls::new_tls_flight_channel,
HistoricalPriceData, LatestPricesResponse,
};
use arrow_flight::decode::FlightRecordBatchStream;
use chrono::{DateTime, Utc};
use futures::try_join;
use std::{collections::HashMap, error::Error};
use std::error::Error;
use tonic::transport::Channel;

struct SpiceClientConfig {
Expand Down Expand Up @@ -41,13 +38,11 @@ impl SpiceClientConfig {
}

/// The `SpiceClient` is the main entry point for interacting with the Spice API.
/// It provides methods for querying the Spice Flight and Firecache endpoints,
/// as well as the Spice Prices endpoint.
/// It provides methods for querying the Spice Flight and Firecache endpoints.
#[allow(clippy::module_name_repetitions)]
pub struct SpiceClient {
flight: SqlFlightClient,
firecache: SqlFlightClient,
prices: PricesClient,
}

impl SpiceClient {
Expand All @@ -66,7 +61,6 @@ impl SpiceClient {
Ok(Self {
flight: SqlFlightClient::new(config.flight_channel, api_key.to_string()),
firecache: SqlFlightClient::new(config.firecache_channel, api_key.to_string()),
prices: PricesClient::new(Some(config.https_addr), api_key.to_string()),
})
}

Expand Down Expand Up @@ -100,60 +94,4 @@ impl SpiceClient {
) -> Result<FlightRecordBatchStream, Box<dyn Error>> {
self.firecache.query(query).await
}

/// Get the supported pairs:
/// ```rust
/// # 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;
/// # }
/// ```
pub async fn get_supported_pairs(&self) -> Result<Vec<String>, Box<dyn Error>> {
self.prices.get_supported_pairs().await
}

/// Get the latest price for a token pair:
/// ```rust
/// # 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;
/// # }
/// ```
pub async fn get_prices(&self, pairs: &[&str]) -> Result<LatestPricesResponse, Box<dyn Error>> {
self.prices.get_prices(pairs).await
}

/// Get historical data:
/// ```rust
/// # 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;
/// # }
/// ```
pub async fn get_historical_prices(
&self,
pairs: &[&str],
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
granularity: Option<&str>,
) -> Result<HashMap<String, Vec<HistoricalPriceData>>, Box<dyn Error>> {
self.prices
.get_historical_prices(pairs, start, end, granularity)
.await
}
}
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
mod client;
mod config;
mod flight;
mod prices;
mod tls;

pub use client::SpiceClient as Client;
pub use prices::{HistoricalPriceData, LatestPriceDetail, LatestPricesResponse};

// Further public exports and integrations
pub use futures::StreamExt;
198 changes: 0 additions & 198 deletions src/prices.rs

This file was deleted.

Loading
Loading