Introducing go-goldapi: a Go Package for Querying Precious Metal Prices

Photo by Stanislaw Zarychta on Unsplash

Would you like to have automation workflows or alerting related to current spot pricing of gold, silver, platinum or palladium? Of course you would! But first you need to grab the price…

Introducing go-goldapi, a Go package for querying current and historical precious metal prices from Note: I am the author of the Go package ( but I have no affiliation with

This API and package can be used to query current and historical prices of gold, silver, platinum and palladium in the following currencies:

  • USD — United States dollar
  • AUD — Australian dollar
  • GBP — British pound
  • EUR — European Euro
  • CHF — Swiss franc
  • CAD — Canadian dollar
  • JPY — Japanese yen
  • INR — Indian rupee
  • SGD — Singapore Dollar
  • BTC — Bitcoin
  • CZK — Czech Krona
  • RUB — Russian Ruble
  • PLN — Polish Złoty
  • MYR — Malaysian Ringgit
  • XAG — Gold/Silver Ratio

To start fetching spot prices with Go get your free API key here and then import into your project.

Try this code sample after you replace “YOUR API KEY” with your API key from

Then try replacing “USD” with any of the above currency codes.

Then try different metals using the following consts goldapi.Gold, goldapi.Silver, goldapi.Platinum, goldapi.Palladium.

Then try different dates in the YYMMDDD format for the third argument.

package main

import (


func main() {
// Get your API key from
api := goldapi.NewAPIClient("YOUR API KEY")

// Use one of the 4 const Metals from goldapi package:
// Must include currency in ISO 4217.
// Date is optional but must be in YYYYMMDD format.
// If date is left blank today's date will be used.
silverReport, err := api.GetPrice(goldapi.Silver, "USD", "")
if err != nil {

fmt.Printf("The price of silver is %f\n",silverReport.Price)
fmt.Printf("%+v", silverReport)

// A report of your API usage
stats, err := api.GetStats()
if err != nil {

fmt.Printf("\nYou have used %d requests this month", stats.RequestsMonth)

Have fun and as always, bother me on Twitter.




Software Engineer / Racecar Driver

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Can MongoDB really deliver ACID?

AWS Case Study : Dish TV

My Story with Google Code-in and SCoRe Lab

Hello World To Clean Architecture

Classifying Sounds with the SoundAnalysis framework and custom CoreML models in Swift

Speed up your coding using Anki

Webhooks Are Everywhere — It’s Time To Learn Them

ripe dandelion seeds being blown off the flower

Complete Flutter Set Up in VS Code

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Joel Guerra

Joel Guerra

Software Engineer / Racecar Driver

More from Medium

Binary protection using go embed and plugins

Keep your dependencies up-to-date

Go Puzzlers: JSON Unmarshaling

Converting transparent background images to color background using Golang