Skip to content

Gosu-Team/gold-price-api

Repository files navigation

Deploy to Cloudflare

Gold Price API

A Cloudflare Worker that fetches and caches current gold prices from goldprice.org using Puppeteer.

Features

  • Automated Price Fetching: Runs every 6 hours via cron triggers
  • R2 Storage: Caches latest price with historical metadata
  • On-Demand Updates: Fetches fresh data if cache is empty
  • Puppeteer Integration: Uses Cloudflare Browser Workers for scraping

API Usage

# Get current gold price
curl https://your-worker.workers.dev/

# Fetch from specific URL
curl https://your-worker.workers.dev/?url=https://goldprice.org/

Response Format

{
  "price": "$2,345.67",
  "source": "https://goldprice.org/",
  "fetchedAt": "2025-10-08T12:00:00.000Z"
}

Environment Variables (optional)

  • GOLD_PRICE_ORG: Default gold price URL
  • TARGET_URL: Alternative target URL

Requirements

  • Cloudflare Workers account
  • R2 bucket named misc
  • Browser binding enabled

Use on Google Sheets

Create a custom function using Apps Script:

  1. In your Google Sheet, go to ExtensionsApps Script
  2. Delete any existing code and paste this:
function GETGOLDPRICE() {
  var url = "https://your-worker.workers.dev/";
  var response = UrlFetchApp.fetch(url);
  var data = JSON.parse(response.getContentText());

  // Return just the price (removes commas and converts to number)
  return parseFloat(data.price.replace(/,/g, ''));
}
  1. Save the project (Ctrl/Cmd + S)
  2. Go back to your sheet and use in any cell =GETGOLDPRICE() - returns just the price as a number