Skip to content

Commit

Permalink
Added all filing feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
joeychilson committed Jul 24, 2023
1 parent 29d20f1 commit afaddac
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
40 changes: 34 additions & 6 deletions lib/edgar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1271,26 +1271,54 @@ defmodule EDGAR do
@spec rss_feed_from_string(xml_str :: String.t()) :: success_type(map()) | error_type()
def rss_feed_from_string(xml_str), do: EDGAR.Native.parse_rss_feed(xml_str)

@doc """
Fetches the recent filings rss feed
"""
@spec filings_feed :: success_type(map()) | error_type()
def filings_feed do
url = "https://www.sec.gov/Archives/edgar/usgaap.rss.xml"

with {:ok, body} <- get(url),
result <- filing_feed_from_string(body) do
result
end
end

@doc """
Fetch the recent mutual funds filings rss feed
"""
@spec mutual_funds_feed :: success_type(map()) | error_type()
def mutual_funds_feed do
url = "https://www.sec.gov/Archives/edgar/xbrl-rr.rss.xml"

with {:ok, body} <- get(url),
result <- filing_feed_from_string(body) do
result
end
end

@doc """
Fetches the recent XBRL rss feed
"""
@spec xbrl_feed :: success_type(map()) | error_type()
def xbrl_feed do
url = "https://www.sec.gov/Archives/edgar/xbrlrss.all.xml"

with {:ok, body} <- get(url),
result <- xbrl_feed_from_string(body) do
result <- filing_feed_from_string(body) do
result
end
end

@doc """
Fetches the recent inline XBRL rss feed
"""
@spec inline_xbrl_feed :: success_type(map()) | error_type()
def inline_xbrl_feed do
url = "https://www.sec.gov/Archives/edgar/xbrl-inline.rss.xml"

with {:ok, body} <- get(url),
result <- xbrl_feed_from_string(body) do
result <- filing_feed_from_string(body) do
result
end
end
Expand All @@ -1317,21 +1345,21 @@ defmodule EDGAR do
url = "https://www.sec.gov/Archives/edgar/monthly/xbrlrss-#{year}-#{month}.xml"

with {:ok, body} <- get(url),
result <- xbrl_feed_from_string(body) do
result <- filing_feed_from_string(body) do
result
end
end
end

@doc """
Parses the XBRL feed from a string
Parses a filing feed from a string
## Required
* `xml_str` - The XBRL feed xml string to parse
"""
@spec xbrl_feed_from_string(xml_str :: String.t()) :: success_type(map()) | error_type()
def xbrl_feed_from_string(xml_str), do: EDGAR.Native.parse_xbrl_feed(xml_str)
@spec filing_feed_from_string(xml_str :: String.t()) :: success_type(map()) | error_type()
def filing_feed_from_string(xml_str), do: EDGAR.Native.parse_filing_feed(xml_str)

@doc false
defp get_json(url) do
Expand Down
2 changes: 1 addition & 1 deletion lib/edgar/native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ defmodule EDGAR.Native do

def parse_current_feed(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_company_feed(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_filing_feed(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_form13f_document(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_form13f_table(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_ownership_form(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_rss_feed(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_xbrl(_xml), do: :erlang.nif_error(:nif_not_loaded)
def parse_xbrl_feed(_xml), do: :erlang.nif_error(:nif_not_loaded)
end
29 changes: 14 additions & 15 deletions native/edgar_parser/src/feeds.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::xml::{get_int32, get_int64, get_string};
use crate::xml::{get_int32, get_string};
use roxmltree::Document as XMLDoc;
use rustler::NifMap;

Expand Down Expand Up @@ -452,18 +452,18 @@ fn parse_summary(node: &roxmltree::Node) -> Result<Option<Summary>, String> {
}

#[derive(NifMap)]
pub struct XBRLFeed {
pub struct FilingFeed {
title: Option<String>,
link: Option<String>,
description: Option<String>,
language: Option<String>,
items: Vec<XBRLItem>,
items: Vec<FilingItem>,
pub_date: Option<String>,
last_build_date: Option<String>,
}

#[derive(NifMap)]
pub struct XBRLItem {
pub struct FilingItem {
title: Option<String>,
link: Option<String>,
guid: Option<String>,
Expand All @@ -485,14 +485,14 @@ pub struct Filing {
cik: Option<String>,
company_name: Option<String>,
filing_date: Option<String>,
acceptance_datetime: Option<i64>,
period: Option<i32>,
acceptance_datetime: Option<String>,
period: Option<String>,
accession_number: Option<String>,
file_number: Option<String>,
form_type: Option<String>,
assistant_director: Option<String>,
assigned_sic: Option<i32>,
fiscal_year_end: Option<i32>,
fiscal_year_end: Option<String>,
files: Vec<File>,
}

Expand All @@ -507,13 +507,12 @@ pub struct File {
}

#[rustler::nif]
pub fn parse_xbrl_feed(xml: &str) -> Result<XBRLFeed, String> {
pub fn parse_filing_feed(xml: &str) -> Result<FilingFeed, String> {
let doc = XMLDoc::parse(xml).map_err(|e| e.to_string())?;
let root_node = doc
.root_element()
.first_element_child()
.ok_or_else(|| "Could not find the root element's first child".to_string())?;

let title = get_string(&root_node, "title");
let link = get_string(&root_node, "link");
let description = get_string(&root_node, "description");
Expand All @@ -533,7 +532,7 @@ pub fn parse_xbrl_feed(xml: &str) -> Result<XBRLFeed, String> {
let pub_date = get_string(&item_node, "pubDate");
let filing = parse_filing(&item_node)?;

Ok::<XBRLItem, String>(XBRLItem {
Ok::<FilingItem, String>(FilingItem {
title,
link,
guid,
Expand All @@ -543,9 +542,9 @@ pub fn parse_xbrl_feed(xml: &str) -> Result<XBRLFeed, String> {
filing,
})
})
.collect::<Result<Vec<XBRLItem>, String>>()?;
.collect::<Result<Vec<FilingItem>, String>>()?;

Ok(XBRLFeed {
Ok(FilingFeed {
title,
link,
description,
Expand Down Expand Up @@ -582,14 +581,14 @@ fn parse_filing(node: &roxmltree::Node) -> Result<Option<Filing>, String> {
let cik = get_string(&filing_node, "cikNumber");
let company_name = get_string(&filing_node, "companyName");
let filing_date = get_string(&filing_node, "filingDate");
let acceptance_datetime = get_int64(&filing_node, "acceptanceDatetime");
let period = get_int32(&filing_node, "period");
let acceptance_datetime = get_string(&filing_node, "acceptanceDatetime");
let period = get_string(&filing_node, "period");
let accession_number = get_string(&filing_node, "accessionNumber");
let file_number = get_string(&filing_node, "fileNumber");
let form_type = get_string(&filing_node, "formType");
let assistant_director = get_string(&filing_node, "assistantDirector");
let assigned_sic = get_int32(&filing_node, "assignedSic");
let fiscal_year_end = get_int32(&filing_node, "fiscalYearEnd");
let fiscal_year_end = get_string(&filing_node, "fiscalYearEnd");
let files = parse_files(&filing_node)?;

Ok::<Filing, String>(Filing {
Expand Down
4 changes: 2 additions & 2 deletions native/edgar_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod thirteenf;
mod xbrl;
mod xml;

use feeds::{parse_company_feed, parse_current_feed, parse_rss_feed, parse_xbrl_feed};
use feeds::{parse_company_feed, parse_current_feed, parse_filing_feed, parse_rss_feed};
use ownership::parse_ownership_form;
use thirteenf::{parse_form13f_document, parse_form13f_table};
use xbrl::parse_xbrl;
Expand All @@ -14,11 +14,11 @@ rustler::init!(
[
parse_company_feed,
parse_current_feed,
parse_filing_feed,
parse_form13f_document,
parse_form13f_table,
parse_ownership_form,
parse_rss_feed,
parse_xbrl,
parse_xbrl_feed,
]
);

0 comments on commit afaddac

Please sign in to comment.