Get Kanpur Gold 22k (KANP-22k) - Per Gram Historical Prices using this API (REST request example)
You need Kanpur Gold 22k (KANP-22k) per-gram history to backfill charts, validate invoices, reconcile P&L, or run backtests on jewelry margins. In this guide you will pull single-date and date-range historical prices for KANP-22k via simple REST calls, parse the JSON, and handle practical details like units (grams vs troy ounces), base currency, weekends, and caching.
What exactly is KANP-22k, and why the “per gram” detail matters
KANP-22k represents a localized 22-karat gold rate for Kanpur. In retail jewelry and manufacturing flows, 22k (91.6% purity) is commonly quoted per gram rather than per troy ounce. If you build pricing, hedging, or analytics for Indian retail flows, per-gram series align more directly to billing units, inventory costing, and BOM-level rollups than troy-ounce benchmarks.
From a product perspective, serving a per-gram, city-specific gold series bridges digital transformation and price discovery in a market that still moves on regional quoting conventions. It lets your trading tools, e-commerce pricing, and ERP layers speak the same unit and purity as your end users—without constant conversions.
Metals-API exposes KANP-22k like any other symbol, so you can pull current and historical quotes with the same endpoints you already use. Review the complete symbol catalogue on the Metals-API Supported Symbols page to confirm availability and metadata for KANP-22k before you code.
The endpoints you will use
We will keep the workflow compact and production-ready with two core endpoints, plus one optional check:
- Historical (single date): append a date to the base path to fetch the closing rate for that day.
- Time-series: pull a continuous range for chart backfills and backtests.
- (Optional) Latest: a sanity check to compare your last historical point vs the current indicative rate.
Full parameter options and plan-specific details are documented here: Metals-API Documentation. If you still need credentials, you can create a free key at the Metals-API Website.
Single-date historical price for KANP-22k (per gram)
Use the historical endpoint by appending a date (YYYY-MM-DD). Request only the symbol you need. The response structure mirrors the samples in the docs and includes a unit field that tells you whether the price is per troy ounce or per gram for the requested symbol.
curl request
curl -s 'https://metals-api.com/api/2024-08-30?access_key=YOUR_API_KEY&symbols=KANP-22k'
Illustrative JSON response
Values below are illustrative to show structure and fields; do not use them for trading. Always fetch live data from the API.
{
"success": true,
"timestamp": 1724976000,
"base": "USD",
"date": "2024-08-30",
"rates": {
"KANP-22k": 75.00
},
"unit": "per gram"
}
What you will use from this response
- success: Boolean to guard your pipeline.
- date: The trading date the rate applies to.
- rates["KANP-22k"]: The per-gram price for Kanpur 22k gold, expressed relative to base.
- base: The base currency for the quote (default is USD unless you override; confirm in your plan/docs).
- unit: Critical for math—here it’s “per gram,” which avoids converting from troy ounces.
- timestamp: Unix epoch of the data snapshot; store it if you need reproducibility.
Range backfill for charts and backtests: Time-series endpoint
For a rolling chart (30, 90, 180 days) or a historical simulation, use the time-series endpoint. It returns daily closes for your date window—handy for spark-lines, volatility stats, or moving averages.
curl request
curl -s 'https://metals-api.com/api/timeseries?access_key=YOUR_API_KEY&start_date=2024-08-26&end_date=2024-08-30&symbols=KANP-22k'
Illustrative JSON response (trimmed to essentials)
Values are illustrative to show the response layout only.
{
"success": true,
"timeseries": true,
"start_date": "2024-08-26",
"end_date": "2024-08-30",
"base": "USD",
"rates": {
"2024-08-26": { "KANP-22k": 74.50 },
"2024-08-27": { "KANP-22k": 74.80 },
"2024-08-28": { "KANP-22k": 74.60 },
"2024-08-29": { "KANP-22k": 74.90 },
"2024-08-30": { "KANP-22k": 75.00 }
},
"unit": "per gram"
}
Python: turn the time-series into (date, value) pairs
import os
import requests
from datetime import date, timedelta
ACCESS_KEY = os.getenv("METALS_API_KEY", "YOUR_API_KEY")
BASE_URL = "https://metals-api.com/api/timeseries"
params = {
"access_key": ACCESS_KEY,
"start_date": "2024-08-26",
"end_date": "2024-08-30",
"symbols": "KANP-22k"
}
resp = requests.get(BASE_URL, params=params, timeout=15)
resp.raise_for_status()
data = resp.json()
if not data.get("success"):
raise RuntimeError(f"API returned error payload: {data}")
unit = data.get("unit")
base = data.get("base")
# Extract ordered (date, price) tuples
series = []
for d in sorted(data["rates"].keys()):
day_rates = data["rates"][d]
price = day_rates.get("KANP-22k")
if price is None:
# Missing day (holiday/weekend); choose your gap policy
continue
series.append((d, price))
print(f"Unit: {unit}, Base: {base}, Points: {len(series)}")
for d, v in series:
print(d, v)
(Optional) Quick comparison: latest check for KANP-22k
When backfilling, you might validate that the time-series end date aligns with the latest indicative quote. This is optional but useful in reconciliations.
curl request
curl -s 'https://metals-api.com/api/latest?access_key=YOUR_API_KEY&symbols=KANP-22k'
Illustrative JSON response
{
"success": true,
"timestamp": 1725062400,
"base": "USD",
"date": "2024-08-31",
"rates": {
"KANP-22k": 75.10
},
"unit": "per gram"
}
Understanding the fields you will rely on
- success: Always check before parsing. If false, inspect the payload for error info.
- timestamp: Server-side epoch seconds of the data snapshot. Store it to ensure deterministic replays.
- date (latest/historical) or start_date/end_date (time-series): Use these as your index keys.
- base: The currency in which rates are expressed. By default, Metals-API responses are relative to USD. If you need INR, consult the parameters in the Metals-API Documentation.
- rates: A symbol map for single-day endpoints, or a date-to-symbol map for time-series. Access rates["KANP-22k"] or rates[YYYY-MM-DD]["KANP-22k"].
- unit: Use this to confirm if your rate is “per gram” or “per troy ounce.” KANP-22k is typically per gram; still, always read the unit from the response.
Edge cases and operational details that save time
- Units: Do not assume grams. KANP-22k is a per-gram regional quote, but confirm with the unit field every time. If you must convert from troy ounces to grams, use 1 troy ounce = 31.1034768 grams, and be explicit in your code to prevent silent unit bugs. See reference: Troy weight (Wikipedia).
- Base currency: The default base is USD. If your downstream ledger or UX is INR-first, consider converting prices downstream using your own FX source or explore parameters in the documentation to change base where supported.
- Timestamps and timezone: date refers to the API’s market date for the price point. Use timestamp for precise sequencing. Align all your series to a single timezone when merging with other feeds.
- Weekends/holidays: If no trade or quote consolidation occurs, a day may be absent or unchanged. Decide on a gap policy: forward-fill for UI charts, or leave gaps for backtests to avoid bias.
- Maximum range per request: The time-series endpoint supports date windows subject to plan limits. For larger backfills, chunk your calls and stitch the results. Check limits in the Metals-API Documentation.
- Caching and retries: Cache immutable historical responses keyed by (symbol, date). Respect ETag/If-Modified-Since if applicable to your plan. Implement idempotent retries with exponential backoff for transient network issues.
- Purity vs benchmark: KANP-22k series incorporates a 22k purity convention. Avoid comparing it 1:1 with 24k (XAU) ounce rates without adjusting for purity and unit differences.
Minimal end-to-end script for a rolling 90-day backfill
This example demonstrates a common pattern: fetch a window, normalize to (date, price, unit, base), and serialize for your charting store. Customize chunking and persistence for your stack.
import os
import json
import requests
from datetime import date, timedelta
ACCESS_KEY = os.getenv("METALS_API_KEY", "YOUR_API_KEY")
START = (date.today() - timedelta(days=90)).isoformat()
END = date.today().isoformat()
url = "https://metals-api.com/api/timeseries"
params = {
"access_key": ACCESS_KEY,
"start_date": START,
"end_date": END,
"symbols": "KANP-22k"
}
r = requests.get(url, params=params, timeout=20)
r.raise_for_status()
payload = r.json()
if not payload.get("success"):
raise SystemExit(f"API error: {json.dumps(payload, indent=2)}")
unit = payload.get("unit")
base = payload.get("base")
rows = []
for d in sorted(payload["rates"].keys()):
v = payload["rates"][d].get("KANP-22k")
if v is None:
continue
rows.append({"date": d, "symbol": "KANP-22k", "price": v, "unit": unit, "base": base})
# Save or feed to your charting layer
print(json.dumps(rows[:5], indent=2), "... total:", len(rows))
Additional example: single historical date with explicit symbol filtering
When you only need one day (e.g., reconciling an invoice), request just that date and symbol. Keep your payloads minimal to reduce latency and bandwidth.
curl -s 'https://metals-api.com/api/2024-06-14?access_key=YOUR_API_KEY&symbols=KANP-22k'
{
"success": true,
"timestamp": 1718323200,
"base": "USD",
"date": "2024-06-14",
"rates": {
"KANP-22k": 72.10
},
"unit": "per gram"
}
Cross-checking the last historical day with latest (optional)
Useful in ETL pipelines to verify you did not miss the most recent close. If latest is ahead of your time-series end_date, schedule another backfill run.
curl -s 'https://metals-api.com/api/latest?access_key=YOUR_API_KEY&symbols=KANP-22k'
{
"success": true,
"timestamp": 1718409600,
"base": "USD",
"date": "2024-06-15",
"rates": {
"KANP-22k": 72.15
},
"unit": "per gram"
}
Production guidance: data hygiene and integration patterns
- Immutable storage: Treat historical responses as immutable and cache them. If you re-pull, verify timestamps match before overwriting stored values.
- Normalization layer: Persist base and unit alongside each row. This prevents subtle bugs later when merging with other feeds.
- Backfill chunking: If your plan imposes window limits, split the date range (e.g., 180-day slices), fetch sequentially, and de-duplicate on (symbol, date).
- Forward-fill for UX, not risk: For charts, forward-fill missing non-trading days. For P&L or VaR, avoid forward-filling to prevent underestimating risk.
- Purity and fees: 22k per-gram retail rates can embed local dynamics. If you benchmark to XAU, adjust for purity (22k/24k) and convert ounces-to-grams consistently.
- Monitoring: Alert on unexpected gaps (e.g., more than N consecutive missing dates) so ops can investigate symbol availability or holiday effects.
Where to find symbols, docs, and get an API key
- Confirm KANP-22k availability and attributes on the Metals-API Supported Symbols page.
- Review endpoint parameters, plan details, and response schemas in the Metals-API Documentation.
- Register to obtain an access_key at the Metals-API Website and start calling the endpoints within minutes.
If you cross-reference with external macro data (e.g., FX moves, policy days), consider reputable sources like the BIS statistics hub for context when interpreting short-term fluctuations.
Frequently asked questions
Q: Is KANP-22k always quoted per gram?
A: Typically yes, but do not assume. Read the unit field from each response. If it’s not per gram, convert explicitly using the correct factor and document it in your code.
Q: What if I need INR instead of USD as the base?
A: By default, Metals-API returns rates relative to USD. Check the parameter options in the documentation for base currency control and ensure your plan supports it. Alternatively, convert downstream using your FX source.
Q: Why are some dates missing in my time-series?
A: Non-trading days, local holidays, or no consolidated quote for that date. Choose a gap policy that fits your use case: forward-fill for charts, leave gaps for analytics to avoid bias.
Q: How far back can I query KANP-22k?
A: Historical availability varies by symbol and plan. Consult the documentation and the symbols listing for coverage and limits.
Q: Can I mix KANP-22k with XAU in the same request?
A: You can request multiple symbols, but keep units and purity in mind. If you need to compare per-ounce XAU with per-gram KANP-22k, normalize both to a common unit and purity before analysis.
Ready to fetch Kanpur 22k gold history and ship your backtests and charts? Get your free access key from the Metals-API Website, confirm KANP-22k on the Supported Symbols page, and follow the documentation to put the historical and time-series endpoints into production.