aboutsummaryrefslogtreecommitdiff
path: root/src/utils/bitcoins.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/bitcoins.rs')
-rw-r--r--src/utils/bitcoins.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils/bitcoins.rs b/src/utils/bitcoins.rs
new file mode 100644
index 0000000..465d907
--- /dev/null
+++ b/src/utils/bitcoins.rs
@@ -0,0 +1,26 @@
+use crate::config::CONFIG;
+use crate::types::ThreadsData;
+use serde::Deserialize;
+
+#[derive(Deserialize)]
+struct Response {
+ price_24h: f64,
+}
+
+pub fn get_price() -> ThreadsData {
+ let url = format!(
+ "https://api.blockchain.com/v3/exchange/tickers/{}",
+ CONFIG.bitcoins.symbol
+ );
+ let _err = String::from("Error");
+ let res = match minreq::get(url).send() {
+ Ok(resp) => match resp.json::<Response>() {
+ Ok(data) => data.price_24h.to_string(),
+ _ => _err,
+ },
+ Err(_) => _err,
+ };
+
+ let data = format!(" {} {} {}", CONFIG.bitcoins.icon, res, CONFIG.seperator);
+ ThreadsData::BitCoins(data)
+}