Add NBP gold reference price#330
Merged
hakanensari merged 2 commits intomainfrom Apr 26, 2026
Merged
Conversation
There was a problem hiding this comment.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the existing
Provider::Adapters::NBPadapter to also fetch NBP's daily gold fixing alongside its FX tables.https://api.nbp.pl/api/cenyzlota/{from}/{to}/?format=json(max 93 days per request, same cap as the FX tables and reusingeach_chunk)[{"data":"2026-04-25","cena":407.18}]wherecenais PLN per gram of fine goldProvider::Adapters::Adapter::GRAMS_PER_TROY_OUNCEconstant, 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){ date:, base: "XAU", quote: "PLN", rate: }— no other precious metals because NBP only fixes goldStrategic 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
parse_goldconverts PLN per gram to PLN per troy ounceAPP_ENV=test bundle exec rake rubocopAPP_ENV=test bundle exec rake(lint + full suite)Provider["NBP"].backfill(after: Date.new(2002, 1, 1))to backfill historical XAU