Precious Metals Integration
This document outlines the new precious metals feature. Users can add holdings of Gold and Silver by specifying the quantity they own. The application automatically fetches current metal prices so the market value is tracked and included in daily snapshots and net worth calculations.API Options for Price Data
Below are a few APIs that can provide real-time or near real-time precious metals pricing.1. MetalsAPI (metals-api.com)
- Pros
- Free tier for basic usage with paid tiers for higher limits
- Simple REST interface and supports multiple metals (Gold –
XAU, Silver –XAG) - JSON responses and historical data available
- Cons
- Rate limits on the free tier are fairly low
- Requires an additional paid plan for minute-level updates
2. GoldAPI.io
- Pros
- Offers spot prices for precious metals
- Straightforward pricing and generous free tier
- Provides multiple currency conversions
- Cons
- Limited historical data compared to MetalsAPI
- Smaller community and less documentation
3. AlphaVantage Commodities
- Pros
- Unified with other AlphaVantage data sources (stocks, forex)
- Free tier includes some commodity endpoints
- Cons
- Data is updated daily rather than intraday
- API responses are CSV-oriented and sometimes inconsistent
Data Model
precious_metals table
uuid– primary keyclerk_id– user identifiermetal–'gold'or'silver'quantity_oz– number of ounces ownedcost_basis– optional cost basisnotes– optional textis_active– soft delete flagcreated_at/updated_at
Price Fetching
The server side uses theMETALS_API_KEY environment variable and fetches prices from MetalsAPI. A helper function fetchMetalPrice(metal) returns the current USD price per ounce for Gold (XAU) or Silver (XAG).
Daily Snapshots
During the daily snapshot cron job the application- Queries all active records in
precious_metalsfor the user. - Fetches the current price for each metal.
- Multiplies quantity by price to derive market value.
- Adds the total to assets, net worth, and market value in
daily_snapshots_summary.