Adding nine more central banks to the Bullion API's gold data
I added nine central banks to the Bullion API's gold holdings data, and had to make one rule about showing changes hold across every page.
The Bullion API reports what central banks hold in gold. I wanted that to cover more countries, so I added nine more of them in one sweep: Denmark, Iceland, North Macedonia, Rwanda, Angola, Oman, Tajikistan, Tanzania and Moldova.
The central-bank gold pages now cover 52 countries. Getting there turned out to be about something other than copying numbers.
Every central bank publishes differently
There is no common format for this. Some report a weight in ounces, some report a value in their own currency, some report both. Some publish monthly, some quarterly, some weekly, and Tajikistan publishes a single audited figure a year. The dates are their own too, so a monthly report is dated at the end of its month while a weekly one carries the exact day it was published.
Two things came out of it. Where a country reports a value but no weight, I can derive the weight by dividing that value by the gold price on the reference date, and the result is labelled as my calculation rather than theirs. And Tajikistan reports each year end in two separate statements, so where the two disagree on the value or the price I leave that year out rather than pick between them.
One rule, everywhere
The part that took the longest was not the parsing. Several separate places decided whether a country's change in holdings could be shown, and they did not agree. For the countries reported through the ECB, the public series hid the change while the dashboard and the digest email still showed a number, and the dashboard could label a change it had derived itself as buying.
I settled on one rule and made it apply everywhere, a source whose reporting direction is unknown shows no tonnes change at all, and a change we derived ourselves keeps its number but is never labelled as buying or selling.
The reason to be strict about this is that a change in reported holdings is not a purchase. I have written about that separately, and here it became a rule the code has to enforce rather than a sentence on a page. The monthly change pages say which countries added to or reduced their reported holdings, with the caveat attached.