The Easiest Way to Get ProShares UltraShort Gold (GLL) - Per Ounce Historical Rates using a REST API
If your goal is to chart, backtest, or report ProShares UltraShort Gold (GLL) “per ounce” historical performance inside a trading tool or analytics pipeline, the most practical REST approach is to drive your calculations from robust spot gold (XAU) per‑troy‑ounce data and programmatically transform it into a GLL‑style, daily rebalanced series. This article shows the easiest way to do that using Metals-API: fetch clean, per‑ounce historical gold prices with 1–2 endpoints, convert them into daily returns, and synthesize a GLL‑like, -2x inverse return curve you can align to any base value. Along the way, we’ll explain units, base currency handling, timestamps, weekends/market closures, and caching strategies, with curl and JavaScript examples. For reference, see the official API docs at the Metals-API Website and Metals-API Documentation, and check supported symbols on the Metals-API Supported Symbols page.
Why use Metals-API for a GLL-style historical curve?
GLL is a daily-reset, -2x inverse ETF designed to move opposite to gold returns (targeting -2x the daily performance of gold futures). While Metals-API does not provide ETF symbols like GLL directly, it does deliver institutional-grade gold (XAU) prices per troy ounce via a simple, reliable JSON REST interface. With those per‑ounce rates in hand, you can:
- Compute daily gold percentage returns from historical per‑ounce XAU prices.
- Transform gold returns into a -2x inverse daily return stream to approximate GLL’s mechanics.
- Index this stream to any base starting value (e.g., 100, 10, or a known GLL NAV on a given date) for realistic tracking and visualization.
- Export the synthetic “GLL per ounce” series into your charts, factor models, and dashboards.
This approach keeps you fully inside an API-first workflow, with no web scraping, and clean control of your methodology. If you need authoritative reference on gold symbol support, see Metals-API Supported Symbols. To get started, request your free key at the Metals-API Website.
Key concept: “Per ounce” means troy ounce, USD base by default
Metals-API quotes gold as XAU relative to a base currency. By default, the API returns values where base=USD and unit=per troy ounce. That means the numeric field you’ll use is expressed as XAU per USD, or more precisely: how many troy ounces one USD buys. To get the conventional dollars-per-ounce price, invert that rate (USD_per_oz = 1 / rate). This distinction is critical for consistent return calculations when you transform into a GLL-style return series.
Units and conversions in practice
- Unit: The API returns “per troy ounce” in its unit field. 1 troy ounce ≈ 31.1034768 grams. Do not confuse it with avoirdupois ounces.
- Base currency: The base is typically USD unless you pass a different base. If you do change base, maintain the same base across your entire time window or normalize carefully before computing returns.
- Inverse convention: The “rates” map uses metals as symbols with values representing the amount of metal per base currency unit. For standard price charts in USD per ounce, invert the rate first.
Which endpoints you actually need
To build a GLL-style series from per-ounce gold prices, two endpoints cover almost all use cases:
- Time-Series Endpoint: Pull a daily series of historical per-ounce XAU rates over your chosen window for return calculations, backtests, and charting.
- OHLC Endpoint: When you need the daily open/high/low/close (XAU per USD per troy ounce), useful for volatility analysis or for matching to a specific open/close methodology when approximating GLL’s daily reset.
We will use these endpoints below; for additional features (e.g., historical point-in-time, convert, bid/ask, or fluctuation) refer to the Metals-API Documentation.
Workflow overview: From XAU per ounce to a GLL-style curve
- Fetch XAU per‑troy‑ounce historical rates for your date range via the Time-Series endpoint.
- Convert each rate to USD per ounce (USD_per_oz = 1 / XAU_rate).
- Compute daily percentage returns from the USD per ounce series (e.g., close-to-close).
- Create a -2x inverse daily return series: gll_return_d = -2 * gold_return_d.
- Index the GLL series to a base value (e.g., 100) and compound daily returns: index_t = index_{t-1} * (1 + gll_return_t).
- Optionally align to a real GLL price or NAV on a chosen anchor date to calibrate level (not required for returns-only work).
Time-Series endpoint for per-ounce historical gold (XAU) data
The Time-Series endpoint returns daily historical rates between two dates. We’ll request XAU, per troy ounce, with base=USD (default behavior), then show how to interpret the response and convert into USD per ounce.
Endpoint purpose
Returns daily historical rates for a set of symbols over a date window. For GLL-style synthesis, the target symbol is XAU; the unit is “per troy ounce.” You’ll use the daily close as the canonical input for returns (or choose open/close from OHLC for specific rules).
Request parameters
- access_key: Your API key. Get one at the Metals-API Website.
- start_date, end_date: YYYY-MM-DD. Ensure inclusive bounds and sufficient history for your analysis.
- base (optional): The base currency; default is USD. Keep it consistent across the entire series.
- symbols: Include XAU for gold. Avoid mixing units or bases when computing returns.
Example curl request
curl -s "https://metals-api.com/api/timeseries?access_key=YOUR_API_KEY&start_date=2026-09-18&end_date=2026-09-25&symbols=XAU"
Representative JSON response and how to read it
{
"success": true,
"timeseries": true,
"start_date": "2026-09-18",
"end_date": "2026-09-25",
"base": "USD",
"rates": {
"2026-09-18": {
"XAU": 0.000485
},
"2026-09-20": {
"XAU": 0.000483
},
"2026-09-25": {
"XAU": 0.000482
}
},
"unit": "per troy ounce"
}
Key fields you’ll actually use:
- success: Boolean; check before processing.
- timeseries: Confirms this is a timeseries response.
- base: The base currency across the series; assume USD here.
- rates: A map keyed by date in YYYY-MM-DD to XAU values representing troy ounces per USD.
- unit: “per troy ounce,” confirming the unit of measure.
To compute conventional USD-per-ounce gold price for each date, invert each XAU value: USD_per_oz(d) = 1 / rates[d].XAU. Compute returns, then build the -2x inverse daily return stream and compound.
Weekend and holiday behavior
Gold spot markets may have reduced or no updates on weekends/holidays. The timeseries may include non-trading dates or missing days depending on your parameters. For return calculations:
- Use only dates with available XAU data.
- When gaps exist, compute returns from the most recent available prior day to the next available day.
- Document your interpolation or carry-forward rules for auditability.
OHLC endpoint when you need daily open/high/low/close
GLL resets daily; if you want to align your synthetic GLL series to a particular methodology (e.g., close-to-close), OHLC can help you test alternatives (open-to-close, close-to-close, etc.).
Endpoint purpose
Returns daily open, high, low, close for a specified date, per symbol. Use it to anchor calculations to a specific session definition or to study intraday ranges when designing risk controls for leveraged or inverse replicators.
Request parameters
- access_key: Your API key.
- date: Target date in YYYY-MM-DD.
- base (optional): Base currency; default USD.
- symbols: XAU.
Example curl request
curl -s "https://metals-api.com/api/ohlc/2026-09-25?access_key=YOUR_API_KEY&symbols=XAU"
Representative JSON response and how to read it
{
"success": true,
"timestamp": 1790295753,
"base": "USD",
"date": "2026-09-25",
"rates": {
"XAU": {
"open": 0.000485,
"high": 0.000487,
"low": 0.000481,
"close": 0.000482
}
},
"unit": "per troy ounce"
}
Key fields:
- rates.XAU.open/high/low/close: Values are troy ounces per USD. Invert to USD per ounce before return math.
- date and timestamp: Use for alignment with your daily rollover logic. Document timezone assumptions.
Use OHLC to test sensitivity of your synthetic GLL returns to the choice of gold reference price (open vs. close). Since GLL targets daily inverse returns of gold futures, your synthetic track may differ depending on which spot reference you use and how you handle session boundaries.
Complete JavaScript example: Fetch XAU timeseries and synthesize a GLL-style index
The following JavaScript example shows how to request a gold per‑ounce time series (XAU), convert to USD per ounce, compute daily gold returns, and then build a -2x inverse (GLL-style) index rebalanced daily. Adjust the window, base currency, or anchoring as needed.
// 1) Fetch historical XAU timeseries from Metals-API (per troy ounce, base=USD)
async function fetchXauTimeseries(apiKey, startDate, endDate) {
const url = `https://metals-api.com/api/timeseries?access_key=${encodeURIComponent(apiKey)}&start_date=${encodeURIComponent(startDate)}&end_date=${encodeURIComponent(endDate)}&symbols=XAU`;
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const json = await res.json();
if (!json.success) throw new Error(`API error: ${JSON.stringify(json)}`);
return json;
}
// 2) Transform XAU (oz per USD) to USD per ounce and compute returns
function buildGllStyleIndex(timeseriesJson, anchorValue = 100) {
const dates = Object.keys(timeseriesJson.rates).sort(); // sort ascending
const usdPerOz = [];
for (const d of dates) {
const xauPerUsd = timeseriesJson.rates[d].XAU;
if (typeof xauPerUsd !== 'number' || xauPerUsd <= 0) continue;
const priceUsdPerOz = 1 / xauPerUsd;
usdPerOz.push({ date: d, price: priceUsdPerOz });
}
// compute daily close-to-close returns
const goldReturns = [];
for (let i = 1; i < usdPerOz.length; i++) {
const prev = usdPerOz[i - 1].price;
const curr = usdPerOz[i].price;
const r = (curr - prev) / prev;
goldReturns.push({ date: usdPerOz[i].date, r });
}
// -2x inverse daily returns for GLL-style
const gllIndex = [];
let level = anchorValue;
// Optionally, seed first date with anchorValue without a return
gllIndex.push({ date: usdPerOz[0].date, level });
for (let i = 0; i < goldReturns.length; i++) {
const invReturn = -2 * goldReturns[i].r;
level = level * (1 + invReturn);
gllIndex.push({ date: goldReturns[i].date, level });
}
return { usdPerOz, goldReturns, gllIndex };
}
// 3) Run end-to-end
(async () => {
const apiKey = 'YOUR_API_KEY';
const startDate = '2026-09-18';
const endDate = '2026-09-25';
const ts = await fetchXauTimeseries(apiKey, startDate, endDate);
const { usdPerOz, goldReturns, gllIndex } = buildGllStyleIndex(ts, 100);
console.log('USD per ounce series:', usdPerOz);
console.log('Gold daily returns:', goldReturns);
console.log('GLL-style -2x inverse index:', gllIndex);
})();
What the code computes and why it matters
- usdPerOz: The conventional USD-per-troy-ounce gold price, derived by inverting the API rate.
- goldReturns: Daily close-to-close percentage returns based on USD-per-ounce prices.
- gllIndex: A synthetic index that starts at anchorValue (e.g., 100) and compounds daily at -2x the gold daily return, approximating GLL’s daily reset behavior.
To match a real GLL historical level, set anchorValue to the fund’s official NAV or close on your start date. Keep in mind that ETF tracking, futures basis, expense ratios, and intraday behavior differ from spot; this synthetic is best for research or internal analytics where you primarily need a robust, API-driven approximation.
curl-only example: One-day OHLC to validate session logic
curl -s "https://metals-api.com/api/ohlc/2026-09-25?access_key=YOUR_API_KEY&symbols=XAU"
Use the returned open and close to measure the sensitivity of your GLL-style return to session selection. For example, you could compute returns using XAU open-to-close instead of close-to-close if that better reflects your model of daily ETF reset timing.
Interpreting response fields that matter for a GLL-style derivation
- timestamp: Unix time for when the snapshot was produced. Useful for ordering and verifying freshness; store it for provenance.
- date: The ISO date the data corresponds to. Use it as the primary join key for returns and index compounding.
- base: The base currency. If you deviate from USD, you must consistently handle FX translation to avoid mixing bases in return calculations.
- rates: A mapping from date or symbol to the rate. For XAU, rate values represent troy ounces per base currency unit; invert to get USD per ounce.
- unit: “per troy ounce.” Validate this is present, and avoid mixing with grams or kilograms in the same pipeline stage.
Security, authentication, and key handling
- API key: Pass your access_key securely via environment variables or a secrets manager. Never hard-code in source control.
- Transport: Use HTTPS. Avoid proxies or MITM that can log sensitive traffic.
- Least privilege in pipelines: Only the service that needs to invoke the API should hold the key.
- Rotation: Rotate keys periodically. On rotation, plan a graceful fallback path and alerting so data ingestion isn’t silently broken.
To obtain your key and start testing, visit the Metals-API Website and the Metals-API Documentation.
Error handling and robustness
- Check success in JSON responses before processing. If false, log the error payload.
- HTTP errors: Retry with exponential backoff on 429/5xx. Respect recommended retry windows; introduce jitter to reduce thundering herd effects.
- Data validation: Verify unit=“per troy ounce,” base=“USD” (or your expected base), and presence of XAU values.
- Gaps/missing dates: Implement a forward-fill policy or skip dates; document the choice. Never fabricate prices.
Caching and performance optimization
- Daily historical windows: Cache immutable historical responses in object storage keyed by endpoint+params+hash.
- Incremental fetches: Extend the known series by fetching only new days since the last processed date.
- Compression: If bandwidth is a constraint, compress stored JSON or transform into columnar formats (e.g., Parquet) after ingestion.
- Batching: Prefer a single timeseries call over many single-day historical calls, within allowed limits.
Data architecture and scaling considerations
- Immutable raw layer: Store raw JSON responses unmodified for audit.
Curated layer: Normalize to USD per ounce, add computed returns, and persist as time-series data. - Metadata lineage: Tag each record with access_key ID (not the secret), base currency, unit, timestamp, and endpoint version.
- Job orchestration: Schedule daily jobs post market close. If using OHLC alignment, define session boundaries and run accordingly.
- Idempotency: Make transforms idempotent. Re-running a date range should not duplicate rows or produce drift.
Handling weekends, holidays, and market closures
- Availability: Metals-API may report fewer updates on non-trading days. Your daily series may skip some calendar days.
- Return logic: Compute returns between consecutive available days. Don’t divide across missing data; explicitly handle gaps.
- Backtest documentation: Record your day-counting conventions and how you treat missing days for reproducibility.
Validation against reference sources
- Compare your synthetic GLL-style index to public GLL charts (e.g., the issuer’s fund page or financial portals) to sanity-check directionality and magnitude.
- Understand differences: GLL references gold futures with fees, tracking error, and daily reset mechanics that may not match spot exactly.
Helpful external references:
Units and measurement detail: troy ounces vs grams
- Metals-API unit: per troy ounce.
- If your downstream app expects grams, convert after you invert the API rate to USD per ounce: USD_per_gram = USD_per_oz / 31.1034768.
- Keep all return math in a single unit system to avoid rounding artifacts mid-pipeline.
Transforming XAU to a GLL-style “per ounce” perspective
“Per ounce” is the core observable from Metals-API. Your synthetic GLL can inherit that per-ounce orientation by treating the index as a unitless level tied to daily per-ounce returns. Best practice:
- Compute gold USD per ounce each day.
- Compute returns from that per-ounce series.
- Transform returns to -2x and compound. The resulting index level is unitless, but every step references a per-ounce gold price, keeping the derivation clear and consistent.
Practical tips a beginner might miss
- Base currency drift: If you switch base mid-series (e.g., USD to EUR), you’ll inject FX effects into the gold return stream. Keep base constant.
- Precision: Use sufficient numerical precision when inverting small XAU-per-USD values to USD per ounce to avoid float errors.
- Anchoring: Anchor the synthetic GLL series to a known start level for easier visual comparisons.
- Intraday vs daily: GLL resets daily. Align your “daily” to your chosen cutover time and stick to it for all runs.
Common pitfalls and troubleshooting
- Forgetting to invert XAU rates: Metals-API returns ounces per USD, not USD per ounce. Invert before return calculations.
- Mixing open and close: If you compute returns with close on one day and open on another, your synthetic will drift. Standardize on a convention.
- Gaps: If a date is missing, your return between the last available date and the next available date will span multiple calendar days. Document and accept or adjust your window.
- Assuming ETF parity: Spot gold is not gold futures, and GLL has expenses and tracking differences. Treat your synthetic as an approximation.
Security best practices for production deployments
- Secret management: Store access keys in Vault/KMS or your cloud secrets manager; inject at runtime.
- Network egress: Restrict outbound traffic to the API domain. Monitor for anomalies.
- Logging: Redact access_key from logs. Log request IDs, timestamps, and response hashes for reproducibility.
- Access control: Separate duties—developers don’t need production keys; CI/CD injects them just-in-time.
Performance and cost controls
- Memoize static windows: Historical data doesn’t change. Cache aggressively.
- Differential updates: Each day, fetch only the new day. Avoid re-pulling long windows unless you must.
- Parallelization: When fetching multiple symbols, batch sensibly. For this use case, you likely need XAU only.
Versioning and change management
- Pin endpoints and fields you rely on; implement schema guards so field changes don’t break production.
- Contract tests: Periodically validate a known date’s response structure and units.
Putting it all together: Step-by-step recipe
- Get a free API key from the Metals-API Website.
- List symbols to confirm XAU availability: see Metals-API Supported Symbols.
- Call the Time-Series endpoint for XAU over your backtest window.
- Invert to USD per ounce and compute close-to-close gold returns.
- Multiply each daily return by -2 to approximate GLL’s -2x inverse profile.
- Compound returns into a synthetic index, anchored to your chosen start value.
- (Optional) Use OHLC to refine session selection, test open/close sensitivity.
- Cache results and persist raw responses for audit; re-run daily with incremental updates.
Example: Interpreting API fields in context
{
"success": true,
"base": "USD",
"rates": {
"2026-09-25": { "XAU": 0.000482 }
},
"unit": "per troy ounce"
}
- rates["2026-09-25"].XAU = 0.000482 oz per USD ⇒ USD per oz ≈ 2074.690 (1 / 0.000482)
- Use this as the close for that date to compute the next day’s return.
- Repeat across dates to produce a continuous per-ounce USD series, then transform to -2x inverse returns.
Advanced techniques
- Volatility alignment: If you measure gold returns with a particular close time, ensure you fetch or align prices to that cutover for consistency.
- Outlier handling: Detect and quarantine anomalous spikes before compounding leveraged returns; report and review anomalies.
- Scenario testing: Run sensitivity tests using OHLC opens vs closes to bracket tracking uncertainty relative to spot vs futures timing differences.
Where to learn more
- Metals-API Documentation for endpoints, parameters, and examples.
- Metals-API Supported Symbols to confirm XAU and units.
- Metals-API Website to get your API key and start building.
Conclusion
The most straightforward, API-native path to “ProShares UltraShort Gold (GLL) – per ounce” historical analytics is to construct a GLL-style return series from high-quality per‑troy‑ounce XAU data. Metals-API delivers exactly that: clean, auditable, per‑ounce gold rates via simple REST calls. With the Time-Series endpoint, you can backfill full windows. With OHLC, you can align session logic. Then, invert to USD per ounce, compute daily returns, and transform to a -2x inverse daily series with clear, reproducible math. This keeps your research, risk tools, and product pipelines consistent and explainable. Ready to implement? Visit the Metals-API Website and the Metals-API Documentation to get your free key and start integrating today.
FAQ
- Does Metals-API provide GLL directly?
No. Metals-API provides metals prices (e.g., XAU). You can synthesize a GLL-style series by transforming XAU daily returns to -2x inverse and compounding. - What unit does Metals-API use for gold?
Per troy ounce. Invert the XAU-per-USD rate to get USD per troy ounce. - Can I use a different base currency?
Yes, but keep it consistent across your window or normalize to a single base before computing returns. - How do weekends affect my series?
Some dates may not have updates. Compute returns between consecutive available dates and document your policy. - Where can I find the list of supported symbols?
See the Metals-API Supported Symbols. - Where do I get an API key?
Request one at the Metals-API Website and review the Metals-API Documentation to start calling endpoints.