finance-query 3.0.0

A Rust library for querying financial data
Documentation
//! SEC EDGAR API endpoint URLs.
//!
//! All EDGAR API endpoints are free, public, and require no authentication
//! (only a proper User-Agent header with contact email).

/// All ticker-to-CIK mappings (JSON, ~2MB).
pub const COMPANY_TICKERS: &str = "https://www.sec.gov/files/company_tickers.json";

/// Ticker-to-listing-exchange mappings (JSON, ~1MB). Covers active listings
/// only — SEC keeps no delisted-securities file.
pub const COMPANY_TICKERS_EXCHANGE: &str =
    "https://www.sec.gov/files/company_tickers_exchange.json";

/// Build the submissions URL for a CIK (filing history + company metadata).
///
/// CIK is zero-padded to 10 digits as required by the EDGAR API.
pub fn submissions(cik: u64) -> String {
    format!("https://data.sec.gov/submissions/CIK{:010}.json", cik)
}

/// Build the company facts URL for a CIK (structured XBRL financial data).
///
/// CIK is zero-padded to 10 digits as required by the EDGAR API.
pub fn company_facts(cik: u64) -> String {
    format!(
        "https://data.sec.gov/api/xbrl/companyfacts/CIK{:010}.json",
        cik
    )
}

/// Full-text search endpoint (EFTS).
pub const FULL_TEXT_SEARCH: &str = "https://efts.sec.gov/LATEST/search-index";

/// Build the filing index URL for a CIK and accession (no dashes).
///
/// Filing documents live under `www.sec.gov/Archives`, not `data.sec.gov`
/// (which serves only the submissions/XBRL JSON APIs above) — `data.sec.gov`
/// 404s on this path.
pub fn filing_index(cik: &str, accession_no_dashes: &str) -> String {
    format!(
        "https://www.sec.gov/Archives/edgar/data/{}/{}/index.json",
        cik, accession_no_dashes
    )
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_submissions_url_padding() {
        assert_eq!(
            submissions(320193),
            "https://data.sec.gov/submissions/CIK0000320193.json"
        );
    }

    #[test]
    fn test_company_facts_url_padding() {
        assert_eq!(
            company_facts(320193),
            "https://data.sec.gov/api/xbrl/companyfacts/CIK0000320193.json"
        );
    }

    #[test]
    fn test_small_cik_padding() {
        assert_eq!(
            submissions(1),
            "https://data.sec.gov/submissions/CIK0000000001.json"
        );
    }

    #[test]
    fn test_filing_index_uses_www_not_data_host() {
        assert_eq!(
            filing_index("320193", "000032019324000123"),
            "https://www.sec.gov/Archives/edgar/data/320193/000032019324000123/index.json"
        );
    }
}