use std::io::Stderr;
use anyhow::{Error, Ok};
use rust_decimal::Decimal;
use self::type_::LatestPriceResult;
mod type_;
pub struct Spot {
api_key: String,
api_secret: String,
}
const BASE_URL: &str = "https://api.binance.com";
impl Spot {
pub fn new(api_key: String, api_secret: String) -> Spot {
Spot {
api_key,
api_secret,
}
}
pub async fn latest_price(&self, symbols: Vec<String>) -> Result<Vec<Decimal>, Error> {
let client = reqwest::Client::new();
let res = client
.get(format!("{}{}", BASE_URL, "/api/v3/ticker/price"))
.query(&[("symbols", format!(r#"["{}"]"#, symbols.join(r#"",""#)))])
.send().await?;
let result = res.json::<Vec<LatestPriceResult>>().await?;
Ok(result.iter().map(|x| Decimal::from_str_exact(x.price.as_str()).unwrap()).collect())
}
}