coinbase_bitcoin/
lib.rs

1use anyhow::{Ok, Result};
2
3mod api;
4mod currencies;
5mod request;
6
7pub type Price = f32;
8
9pub struct PriceData {
10    pub spot: Price,
11    pub buy: Price,
12    pub sell: Price,
13}
14
15pub fn get_price_data() -> Result<PriceData> {
16    let spot = get_spot_price()?;
17    let buy = get_buy_price()?;
18    let sell = get_buy_price()?;
19
20    let price_data = PriceData { spot, buy, sell };
21    Ok(price_data)
22}
23pub fn get_spot_price() -> Result<Price> {
24    let response: api::v2::SpotPriceResponse = api::v2::request_spot_price()?;
25    let price: f32 = response.data.amount.parse()?;
26    return Ok(price);
27}
28pub fn get_buy_price() -> Result<Price> {
29    let response: api::v2::BuyPriceResponse = api::v2::request_buy_price()?;
30    let price: f32 = response.data.amount.parse()?;
31    return Ok(price);
32}
33pub fn get_sell_price() -> Result<Price> {
34    let response: api::v2::SellPriceResponse = api::v2::request_sell_price()?;
35    let price: f32 = response.data.amount.parse()?;
36    return Ok(price);
37}