mod client;
pub(crate) mod models;
pub(crate) mod commodities;
pub(crate) mod corporate;
pub(crate) mod crypto;
pub(crate) mod economic;
pub(crate) mod forex;
pub(crate) mod fundamentals;
pub(crate) mod options;
pub(crate) mod quote;
pub(crate) mod technicals;
use crate::adapters::singleton::{provider_build_client, provider_singleton_state};
use crate::error::Result;
use std::time::Duration;
pub use commodities::*;
pub use corporate::*;
pub use crypto::*;
pub use economic::*;
pub use forex::*;
pub use fundamentals::*;
pub use options::*;
pub use quote::*;
const AV_RATE_PER_SEC: f64 = 1.0;
provider_singleton_state!(
name = AlphaVantageSingleton,
static_name = AV_SINGLETON,
rate_const = AV_RATE_PER_SEC,
provider_key = "alphavantage",
already_init_reason = "Alpha Vantage client already initialized",
);
provider_build_client!(
name = AlphaVantageSingleton,
static_name = AV_SINGLETON,
rate_const = AV_RATE_PER_SEC,
provider_key = "alphavantage",
env_var = "ALPHAVANTAGE_API_KEY",
env_missing_reason = "ALPHAVANTAGE_API_KEY not set. Call alphavantage::init(key) or set ALPHAVANTAGE_API_KEY env var.",
builder = client::AlphaVantageClientBuilder,
client_ty = client::AlphaVantageClient,
);
#[allow(dead_code)]
pub fn init(api_key: impl Into<String>) -> Result<()> {
init_with_timeout(api_key, Duration::from_secs(30))
}
#[allow(dead_code)]
pub fn init_with_timeout(api_key: impl Into<String>, timeout: Duration) -> Result<()> {
set_singleton(api_key, timeout)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::error::FinanceError;
#[test]
fn test_init_errors_on_double_init() {
let _ = init("test-key-1");
let result = init("test-key-2");
assert!(matches!(result, Err(FinanceError::InvalidParameter { .. })));
}
}