code wiki / (root) / nx_fin_datasource.nx

nx_fin_datasource.nx source

↩ module page · 44 lines · 2704 B

1// nx_fin_datasource.nx -- the DATA-ACQUISITION doctrine as verified logic: how to get raw financial data LEGALLY 2// and POLITELY, free-first, and when we genuinely must license. Catalog SSOT = knowledge/finance/fin_datasources.conf; 3// human doc = knowledge/finance/DATA_SOURCES.md. Access tiers: 0=FREE_RAW (public-domain primary: SEC EDGAR, FRED, 4// gov), 1=FREE_TIER (keyed + rate-limited), 2=PAID (proprietary license). "Polite" = robots.txt respected + an 5// honest User-Agent where required + within the rate limit (throttle + cache). The HARD WALL: paid data without a 6// license is NEVER allowed (license it or use a free-raw alternative -- Cardinal 26 for data). Pure, i64. 7// license_tier: ORIGINAL 8import "nx_syscalls.nx" 9 10const DS_FREE_RAW: i64 = 0 // public-domain / primary, free, no license 11const DS_FREE_TIER: i64 = 1 // free but keyed + rate-limited 12const DS_PAID: i64 = 2 // proprietary license required -- do NOT circumvent 13 14// is this data legally free to us (no license needed)? (tier 0 or 1) 15func ds_is_free(tier: i64) -> i64 { if tier <= DS_FREE_TIER { return 1 } return 0 } 16 17// cheapest LEGAL tier of two candidate sources for the same need (prefer FREE_RAW > FREE_TIER > PAID). 18func ds_prefer(a: i64, b: i64) -> i64 { if a < b { return a } return b } 19 20// POLITE access: robots.txt allows AND (an honest UA is sent where the source requires one) AND within the daily 21// rate limit. rate_limit<=0 means high/unlimited (still cache + throttle). This is "get it raw politely". 22func ds_polite_ok(robots_ok: i64, requires_ua: i64, ua_sent: i64, req_count: i64, rate_limit: i64) -> i64 { 23 if robots_ok != 1 { return 0 } 24 if requires_ua == 1 { if ua_sent != 1 { return 0 } } 25 if rate_limit > 0 { if req_count > rate_limit { return 0 } } 26 return 1 27} 28 29// access ALLOWED iff you are polite AND (the data is free OR you hold a paid license). PAID without a license 30// returns 0 -- the LEGAL/ETHICAL WALL. Never circumvent: license it, or take the free-raw alternative. 31func ds_access_allowed(tier: i64, has_license: i64, robots_ok: i64, requires_ua: i64, ua_sent: i64, req_count: i64, rate_limit: i64) -> i64 { 32 if ds_polite_ok(robots_ok, requires_ua, ua_sent, req_count, rate_limit) != 1 { return 0 } 33 if ds_is_free(tier) == 1 { return 1 } 34 if has_license == 1 { return 1 } 35 return 0 36} 37 38// the honest "you must budget for this" signal: 1 iff the data is paid-only AND no free alternative exists for 39// the need. If a free alternative exists, use it (returns 0) rather than paying or circumventing. 40func ds_must_license(tier: i64, free_alt_exists: i64) -> i64 { 41 if tier != DS_PAID { return 0 } 42 if free_alt_exists == 1 { return 0 } 43 return 1 44}