use crate::error::Result;
use crate::providers::{Capability, ProviderSet};
use std::sync::Arc;
pub struct ForexPair {
from: Arc<str>,
to: Arc<str>,
providers: Arc<ProviderSet>,
}
impl ForexPair {
pub(crate) fn with_providers(
from: Arc<str>,
to: Arc<str>,
providers: Arc<ProviderSet>,
) -> Self {
Self {
from,
to,
providers,
}
}
pub fn from(&self) -> &str {
&self.from
}
pub fn to(&self) -> &str {
&self.to
}
pub async fn quote(&self) -> Result<crate::models::forex::ForexQuote> {
let from = self.from.clone();
let to = self.to.clone();
self.providers
.fetch(Capability::FOREX, move |p| {
let f = from.clone();
let t = to.clone();
let p = p.clone();
async move { p.fetch_forex_quote(&f, &t).await }
})
.await
}
}