Transport for SEC EDGAR: the settings resolver (per-call opts first, then context variables), a typed HttpError, JSON GETs, and query-string building that drops unset values.

opts keyContext variableDefault
user-agentsec.edgar.user-agentnone: calls fail without it

Per-call User-Agent. user-agent in opts is masked in call records and never written to context, so parallel flows and tenants in one run don't see each other's contact details. Present but blank or null, it is an error, never a fallback to context.

Context Vars

Optional
  • sec.edgar.user-agent

Values

SOURCE

SOURCE: Str "sec-edgar"

Functions

columns-to-rows

fn (columns: Map, limit: Int): Vec<Map>

Turn a columnar Map ({a: [1, 2], b: [3, 4]}, as in EDGAR's filings.recent) into a Vec of row Maps ([{a: 1, b: 3}, {a: 2, b: 4}]), at most limit rows. Columns shorter than the first are padded with null. Pure.

Example

::sec::edgar::api/columns-to-rows({a: [1, 2], b: [3, 4]}, 10)  // [{a: 1, b: 3}, {a: 2, b: 4}]
::sec::edgar::api/columns-to-rows({a: [1, 2], b: [3]}, 1)  // [{a: 1, b: 3}]

get-json

fn (url: Str, headers: Map): Any

GET a JSON resource and return the decoded body, or an Err carrying HttpError.

Example

subs ::sec::edgar::api/get-json("https://data.sec.gov/submissions/CIK0000320193.json", {User-Agent: "Acme Corp ops@acme.com"})
subs.name

given

fn (v: Any): Bool

True for a non-null value that is not a blank string.

Example

::sec::edgar::api/given("Acme Corp ops@acme.com")  // true
::sec::edgar::api/given("  ")  // false
::sec::edgar::api/given(null)  // false

http-error

fn (response: ::hot::http/HttpResponse, url: Str): HttpError

Build an HttpError from a non-2xx response. Exposed for testing; every request uses it.

Example

response ::hot::http/HttpResponse({status: 403, headers: {}, body: "Undeclared Automated Tool"})
e ::sec::edgar::api/http-error(response, "https://data.sec.gov/submissions/CIK0000320193.json")
e.status  // 403
e.message  // "sec-edgar: HTTP 403: Undeclared Automated Tool"

is-not-found

fn (e: Any): Bool

True when e is an HttpError with status 404.

Example

::sec::edgar::api/is-not-found({status: 404})  // true
::sec::edgar::api/is-not-found("connection reset")  // false

path-segment

fn (value: Any): Str

Percent-encode one path segment.

Example

::sec::edgar::api/path-segment("USD per share")  // "USD%20per%20share"

query-string

fn (params: Map): Str

Build a ?a=1&b=2 suffix from a Map, dropping null and blank values (pure); "" when nothing remains.

Example

::sec::edgar::api/query-string({q: "merger", forms: null})  // "?q=merger"
::sec::edgar::api/query-string({forms: ""})  // ""

request

fn (method: Str, url: Str, headers: Map): ::hot::http/HttpResponse

GET (or another method) a SEC URL with headers, returning the HttpResponse on 2xx or an Err carrying HttpError. A transport failure passes through as its own Err.

Example

response ::sec::edgar::api/request("GET", "https://www.sec.gov/files/company_tickers.json", {User-Agent: "Acme Corp ops@acme.com"})
response.status

require-user-agent

fn (cfg: Map): Str

The User-Agent from resolved settings, or an Err explaining that SEC requires one with contact details.

Example

::sec::edgar::api/require-user-agent({user-agent: "Acme Corp ops@acme.com"})  // "Acme Corp ops@acme.com"
is-err(::sec::edgar::api/require-user-agent({user-agent: null}))  // true

resolve

fn (opts: Map): Map

Resolve settings for one call: {user-agent}. A value in opts wins over context; it is used for that call only and comes back unchanged. An Err when user-agent is in opts but blank or null.

Example

cfg ::sec::edgar::api/resolve({user-agent: "Tenant Co ops@tenant.example"})

Types

HttpError

HttpError type {
    source: Str,
    status: Int,
    url: Str,
    headers: Map,
    body: Any,
    retry-after: Int?,
    message: Str
}

A non-2xx SEC response. source is "sec-edgar"; url the requested URL (SEC takes no credentials in URLs); retry-after the parsed Retry-After seconds on 429s; message a one-line summary that never includes credentials.