Company fundamentals and corporate events, fetched from the providers themselves, normalized and cached on the user's machine. Built for DegenView, usable without it.
Today, for US-listed securities:
- dividends and splits from Alpaca's corporate actions API,
- the SEC company behind a security, its filings, and when its results came out,
- its reported figures, normalized from XBRL into fiscal quarters, halves, years and trailing twelve months, with what was first reported and when,
- ratios per period, and valuation at a price you pass in.
- statement tables with year-on-year change, and a dividend summary (totals by year, how often, growth, the next one).
use degenview_fundamentals::{
AlpacaCredentials, AlpacaKeys, Config, Fundamentals, Part, Priority, SecContact, Symbol,
SystemClock, UreqTransport,
};
use std::sync::Arc;
struct Keys;
impl AlpacaCredentials for Keys {
fn keys(&self) -> Option<AlpacaKeys> {
Some(AlpacaKeys {
key_id: std::env::var("APCA_API_KEY_ID").ok()?,
secret: std::env::var("APCA_API_SECRET_KEY").ok()?,
})
}
}
/// The SEC requires automated clients to say who to write to.
struct Contact;
impl SecContact for Contact {
fn contact(&self) -> Option<String> {
std::env::var("SEC_CONTACT_EMAIL").ok()
}
}
let service = Fundamentals::new(Config {
cache_dir: "cache/fundamentals".into(),
transport: Arc::new(UreqTransport::default()),
alpaca: Arc::new(Keys),
sec: Arc::new(Contact),
product: "MyApp/1.0".into(),
clock: Arc::new(SystemClock),
on_change: Arc::new(|| println!("changed")),
});
let apple = Symbol::new("AAPL").expect("a ticker");
// Ask each time the data is about to be shown: it downloads only what is stale.
service.request(&apple, Part::Actions, Priority::Interactive);
let snapshot = service.snapshot(&apple);- No method blocks on the network or disk except
Fundamentals::clear. - Cached data is shown at once and refreshed when stale; a failed download keeps it.
- Nothing is scheduled: a security nobody asks for is never downloaded.
- A value a provider does not give is absent, never zero. Nothing is estimated or inferred.
- It owns no HTTP stack (
Transport), credential store or user interface.
Providers, endpoints and their limits: docs/providers.md.
ureq(default):UreqTransport.testing: a scripted transport, a manual clock and a temporary directory.
GPL-3.0-only.