Skip to content

Add NBP gold reference price#330

Merged
hakanensari merged 2 commits intomainfrom
nbp-gold
Apr 26, 2026
Merged

Add NBP gold reference price#330
hakanensari merged 2 commits intomainfrom
nbp-gold

Conversation

@lineoffligbot
Copy link
Copy Markdown
Collaborator

Summary

Extends the existing Provider::Adapters::NBP adapter to also fetch NBP's daily gold fixing alongside its FX tables.

  • Endpoint: https://api.nbp.pl/api/cenyzlota/{from}/{to}/?format=json (max 93 days per request, same cap as the FX tables and reusing each_chunk)
  • Sample response: [{"data":"2026-04-25","cena":407.18}] where cena is PLN per gram of fine gold
  • Values are normalized from per-gram to per-troy-ounce via the shared Provider::Adapters::Adapter::GRAMS_PER_TROY_OUNCE constant, matching the convention introduced by CBR (Add CBR precious-metal reference prices #327) and BNR (Fix BNR XAU unit and current-year archive fetch #326)
  • Records emitted as { date:, base: "XAU", quote: "PLN", rate: } — no other precious metals because NBP only fixes gold

Strategic context

NBP runs its own daily gold fixing (not LBMA-derived), so adding it brings XAU coverage to five providers (BNR, CBA, NBU, CBR, NBP). The extra independent source improves median stability for the blender.

Test plan

  • Unit test: parse_gold converts PLN per gram to PLN per troy ounce
  • Integration test: live API returns XAU/PLN over a small date range (2026-03-01..2026-03-05)
  • Existing NBP FX tests still pass
  • APP_ENV=test bundle exec rake rubocop
  • APP_ENV=test bundle exec rake (lint + full suite)
  • Post-merge: Provider["NBP"].backfill(after: Date.new(2002, 1, 1)) to backfill historical XAU

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends the existing NBP provider adapter to additionally fetch and parse NBP’s daily gold fixing, emitting normalized XAU/PLN rates (per troy ounce) alongside the existing FX tables.

Changes:

  • Add NBP gold endpoint fetching and parsing, converting PLN/gram to PLN/troy-ounce.
  • Update NBP adapter specs + VCR cassette to cover the new gold request and a smaller integration range.
  • Document the new NBP gold coverage in the changelog.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/provider/adapters/nbp.rb Adds gold endpoint fetch + parse_gold, and appends XAU/PLN records to the fetched dataset.
spec/provider/adapters/nbp_spec.rb Updates VCR request matching and adds unit/integration assertions for XAU/PLN.
spec/vcr_cassettes/nbp.yml Re-records NBP cassette for shorter date range and includes the new gold endpoint interaction.
CHANGELOG.md Notes the addition of NBP gold reference price coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/provider/adapters/nbp.rb Outdated
Comment thread lib/provider/adapters/nbp.rb
Extend the NBP adapter to fetch XAU from
https://api.nbp.pl/api/cenyzlota/. Values arrive in PLN per gram and
are normalized to per troy ounce via GRAMS_PER_TROY_OUNCE, mirroring
the CBR metals pattern. NBP only fixes gold, so no other metals are
added.
Restructure fetch to iterate each_chunk once, processing Table A, B, and
gold within the same loop. Saves ~95s of redundant inter-chunk sleeps on
full backfill.

Add response.value after 404 special-case in both fetch_rates and fetch_gold
so non-404, non-success HTTP responses raise Net::HTTPError instead of
failing later on JSON parse.
@hakanensari hakanensari merged commit 2583afc into main Apr 26, 2026
7 checks passed
@hakanensari hakanensari deleted the nbp-gold branch April 26, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants