Skip to content

Instantly share code, notes, and snippets.

@sungkim11
Created March 18, 2022 03:05
Show Gist options
  • Save sungkim11/4e1175e8b3e1fdc7528eb1086c0f3b15 to your computer and use it in GitHub Desktop.
Save sungkim11/4e1175e8b3e1fdc7528eb1086c0f3b15 to your computer and use it in GitHub Desktop.
extern crate serde;
use serde::{Serialize, Deserialize};
extern crate reqwest;
use reqwest::Client;
#[derive(Serialize, Deserialize, Debug)]
pub struct CoinbasePrice {
pub data: CoinPrice
}
#[derive(Serialize, Deserialize, Debug)]
pub struct CoinPrice {
pub base: String,
pub currency: String,
pub amount: String,
}
#[tokio::main]
pub async fn crypto_publisher_1() -> Result<(), Box<dyn std::error::Error>> {
let spot_url = format!("https://api.coinbase.com/v2/prices/{currency}-{rates}/spot",
currency = "BTC",
rates = "USD");
let resp_spot_price = Client::new().get(&spot_url).send().await?.json::<CoinbasePrice>().await?;
println!("SPOT: {base}-{currency}: {amount}",
base=resp_spot_price.data.base,
currency=resp_spot_price.data.currency,
amount=resp_spot_price.data.amount);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment