code wiki / (root) / nx_fin_datasource_gate.nx

nx_fin_datasource_gate.nx source

↩ module page · 50 lines · 2946 B

1// nx_fin_datasource_gate.nx -- GATE for the data-acquisition doctrine: free classification, cheapest-legal 2// preference, polite-access compliance, the paid-without-license WALL, and the honest must-license signal -- 3// checked against the real catalog (EDGAR=FREE_RAW+UA, Alpha Vantage=FREE_TIER 25/day, SIP=PAID). Exits 0 iff 4// all pass. license_tier: ORIGINAL 5import "nx_gate.nx" 6import "nx_fin_datasource.nx" 7 8func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 { 9 if got == want { st[0] = st[0] + 1; gw(" PASS " as *u8); gw(name); gw("\n" as *u8) } 10 else { st[1] = st[1] + 1; gw(" FAIL " as *u8); gw(name); gw(" got=" as *u8); gn(got); gw(" want=" as *u8); gn(want); gw("\n" as *u8) } 11 return 0 12} 13 14func main() -> i64 { 15 let st: *i64 = sys_mmap(16) as *i64 16 st[0] = 0; st[1] = 0 17 18 // free classification 19 chk("FREE_RAW is free" as *u8, ds_is_free(DS_FREE_RAW), 1, st) 20 chk("FREE_TIER is free" as *u8, ds_is_free(DS_FREE_TIER), 1, st) 21 chk("PAID is NOT free" as *u8, ds_is_free(DS_PAID), 0, st) 22 23 // cheapest legal preference 24 chk("prefer raw over tier" as *u8, ds_prefer(DS_FREE_RAW, DS_FREE_TIER), DS_FREE_RAW, st) 25 chk("prefer tier over paid" as *u8, ds_prefer(DS_FREE_TIER, DS_PAID), DS_FREE_TIER, st) 26 27 // polite access 28 chk("EDGAR polite: robots+UA-sent+within-rate" as *u8, ds_polite_ok(1, 1, 1, 5, 0), 1, st) 29 chk("EDGAR IMPOLITE: UA required but not sent" as *u8, ds_polite_ok(1, 1, 0, 5, 0), 0, st) 30 chk("AlphaVantage within 25/day ok" as *u8, ds_polite_ok(1, 0, 0, 20, 25), 1, st) 31 chk("AlphaVantage over 25/day -> throttle" as *u8, ds_polite_ok(1, 0, 0, 30, 25), 0, st) 32 chk("robots disallow -> not polite" as *u8, ds_polite_ok(0, 0, 0, 1, 0), 0, st) 33 34 // access allowed (free + polite) vs the paid wall 35 chk("EDGAR FREE_RAW + polite -> ALLOWED" as *u8, ds_access_allowed(DS_FREE_RAW, 0, 1, 1, 1, 5, 0), 1, st) 36 chk("EDGAR no-UA -> NOT allowed (be polite)" as *u8, ds_access_allowed(DS_FREE_RAW, 0, 1, 1, 0, 5, 0), 0, st) 37 chk("AlphaVantage FREE_TIER over rate -> NOT allowed" as *u8, ds_access_allowed(DS_FREE_TIER, 0, 1, 0, 0, 30, 25), 0, st) 38 chk("PAID + NO license -> WALL (never circumvent)" as *u8, ds_access_allowed(DS_PAID, 0, 1, 0, 0, 1, 0), 0, st) 39 chk("PAID + license held -> allowed" as *u8, ds_access_allowed(DS_PAID, 1, 1, 0, 0, 1, 0), 1, st) 40 41 // honest must-license signal 42 chk("PAID + no free alt -> MUST license" as *u8, ds_must_license(DS_PAID, 0), 1, st) 43 chk("PAID + free alt exists -> use the alt" as *u8, ds_must_license(DS_PAID, 1), 0, st) 44 chk("FREE_RAW -> never must license" as *u8, ds_must_license(DS_FREE_RAW, 0), 0, st) 45 46 gw("nx_fin_datasource_gate: PASS=" as *u8); gn(st[0]); gw(" FAIL=" as *u8); gn(st[1]); gw("\n" as *u8) 47 if st[1] == 0 { gw("nx_fin_datasource: GREEN (free-first, polite, legal -- paid wall enforced)\n" as *u8); return 0 } 48 gw("nx_fin_datasource: RED\n" as *u8) 49 return 1 50}