Created
March 18, 2022 03:05
-
-
Save sungkim11/4e1175e8b3e1fdc7528eb1086c0f3b15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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