Get Mysore Gold 22k (MYSO-22k) - Per Gram — in Python prices using this API
If you price jewelry, hedge inventory, or analyze regional spreads, you’ve probably needed Mysore Gold 22k (MYSO-22k) per gram in Python. This guide shows how to derive a transparent, reproducible MYSO-22k per-gram stream by combining global gold benchmarks from the Metals-API and a simple karat/units transformation. We will: fetch real-time XAU (gold) rates, compute 22k per gram, localize to INR for Mysore, and backfill a clean historical series for analytics—all with a few HTTP calls and concise Python code. Along the way, we’ll cover units (troy ounce vs gram), karat math, base currency effects, caching, timezones, and robust error handling.
Why Mysore 22k per gram—what you’re building
Mysore’s jewelry market typically quotes retail and wholesale gold in 22 karat, per gram, in INR. Institutional feeds often publish gold as XAU (24k fine gold), per troy ounce, in USD. To power product pricing, risk alerts, or research dashboards, you need a deterministic pipeline that transforms XAU-per-USD-oz to MYSO-22k-per-INR-gram. This is exactly where the Metals-API Website fits: a simple, production-ready JSON REST API for metals and FX that you can integrate into trading tools, fintech products, ERP, and e-commerce pricing engines.
Main concept: derive MYSO-22k per gram from XAU
Metals-API publishes gold as XAU with a default base currency of USD and a default unit of “per troy ounce.” Mysore 22k per gram is a transformation of that benchmark:
- Purity adjustment (22k vs 24k): factor = 22 / 24 = 0.916666…
- Unit conversion (troy ounce to gram): 1 troy ounce = 31.1034768 grams
- Currency localization: USD → INR (or another local currency if needed)
Important: MYSO-22k is a derived market convention for Mysore. It is not a native Metals-API symbol. Always verify available symbols on the Metals-API Supported Symbols page. We’ll build the MYSO-22k per-gram quote from XAU plus a karat/unit transformation and currency conversion.
Endpoints we’ll use
To stay focused and production-relevant, we’ll use these two Metals-API endpoints:
- Latest Rates: fetch current XAU and currency rates.
- Time-series: backfill a daily history for analytics or charts.
We’ll also show the Convert endpoint to convert a monetary amount to XAU or vice versa, useful for pricing logic. For full capabilities, see the Metals-API Documentation.
Units, purity, currency: the three transformations that matter
1) Unit conversion: troy ounce to gram
Metals-API quotes XAU “per troy ounce” by default. If the API returns XAU as a rate relative to your base currency, interpret the unit carefully:
- If the response shows base USD and unit “per troy ounce,” the rate for XAU is expressed as “troy ounces of XAU per 1 USD.” Price per ounce in USD is then 1 / rate.
- To get per gram: price_per_gram = price_per_ounce / 31.1034768.
2) Purity conversion: fine gold (24k) to 22k
- Karat fraction for 22k = 22/24 ≈ 0.9166667.
- 22k price per gram = 24k price per gram × 0.9166667.
3) Currency localization: USD to INR
You can either:
- Request latest rates with base=INR so the resulting XAU rate is relative to INR, then derive per-gram and 22k, or
- Request XAU in USD and convert USD→INR yourself using Metals-API currency rates.
Either path is fine, but be consistent and document your logic. If you want the fewest moving parts, using base=INR often simplifies downstream code.
Step-by-step: compute MYSO-22k per gram, in INR
We’ll fetch latest XAU with base=USD (as shown in the examples below), compute USD per ounce, then convert to INR using the Convert endpoint, and finally compute per gram and 22k purity. You can also reverse the order—convert to INR first, then adjust units/purity.
Latest Rates: example response and field meanings
Call the latest endpoint to get a snapshot. Below is a representative JSON payload format for latest rates where base=USD and unit is per troy ounce. We’ll focus on the XAU field for gold:
{
"success": true,
"timestamp": 1789949543,
"base": "USD",
"date": "2026-09-21",
"rates": {
"XAU": 0.000482,
"XAG": 0.03815,
"XPT": 0.000912,
"XPD": 0.000744,
"XCU": 0.294118,
"XAL": 0.434783,
"XNI": 0.142857,
"XZN": 0.344828
},
"unit": "per troy ounce"
}
Key fields you will actually use:
- success: boolean status. Always check before using data.
- timestamp: UNIX epoch seconds for when the rates were last updated. Use this to time-align with other market data.
- base: the currency against which rates are quoted. Default is USD; you can choose another base depending on your plan.
- date: ISO date of the data snapshot; useful for display and archival checks.
- rates.XAU: gold quoted relative to base. With base=USD and unit=per troy ounce, interpret as troy ounces per 1 USD. Price per ounce in USD = 1 / rates.XAU.
- unit: confirms the measurement unit (“per troy ounce”). This is critical for unit conversions.
Compute per-ounce, per-gram, and 22k adjustments
- USD per troy ounce = 1 / rates.XAU
- USD per gram (24k) = (USD per troy ounce) / 31.1034768
- USD per gram (22k) = (USD per gram 24k) × (22 / 24)
Then either convert USD→INR using the Convert endpoint or request base=INR to begin with and adapt the same math.
cURL: fetch latest rates and then convert
Below is a practical sequence: fetch latest rates in USD (XAU), then convert a USD price to INR. Replace YOUR_ACCESS_KEY with your key. If you don’t have one, get started now on the Metals-API Website—there’s a free tier to test.
1) Get latest XAU snapshot
curl -s "https://metals-api.com/api/latest?access_key=YOUR_ACCESS_KEY&base=USD&symbols=XAU"
Interpret the JSON as shown above. If you request only XAU, the response’s rates object will contain XAU.
2) Convert USD to INR for localization
Use the Convert endpoint when you have a USD-denominated amount and need the INR equivalent. For example, after you compute USD per gram 22k, convert that scalar to INR:
curl -s "https://metals-api.com/api/convert?access_key=YOUR_ACCESS_KEY&from=USD&to=INR&amount=1"
Multiply your USD-per-gram-22k by the returned INR-per-USD amount. Alternatively, if your plan supports setting base=INR on latest/timeseries, you can avoid this step by requesting INR directly.
Python: end-to-end calculation for MYSO-22k per gram
This Python snippet fetches XAU latest, computes 24k per gram, adjusts to 22k, and localizes to INR using the Convert endpoint. It prints Mysore 22k per gram (derived) with metadata so you can audit the pipeline.
import os
import math
import time
import json
import urllib.request
import urllib.parse
API_BASE = "https://metals-api.com/api"
ACCESS_KEY = os.getenv("METALS_API_KEY", "YOUR_ACCESS_KEY")
TROY_OUNCE_TO_GRAM = 31.1034768
KARAT_22_FACTOR = 22.0 / 24.0
def http_get(url, params):
q = urllib.parse.urlencode(params)
with urllib.request.urlopen(f"{url}?{q}", timeout=15) as resp:
return json.loads(resp.read().decode("utf-8"))
# 1) Fetch latest XAU with base USD
latest = http_get(f"{API_BASE}/latest", {
"access_key": ACCESS_KEY,
"base": "USD",
"symbols": "XAU"
})
if not latest.get("success"):
raise RuntimeError(f"Latest failed: {latest}")
rates = latest["rates"]
xau_rate = rates["XAU"] # ounces per 1 USD, unit: per troy ounce
timestamp = latest["timestamp"]
unit = latest.get("unit", "per troy ounce")
# 2) Compute USD per ounce and per gram (24k), then 22k
usd_per_oz_24k = 1.0 / xau_rate
usd_per_g_24k = usd_per_oz_24k / TROY_OUNCE_TO_GRAM
usd_per_g_22k = usd_per_g_24k * KARAT_22_FACTOR
# 3) Convert USD to INR for localization (1 USD => ? INR)
fx = http_get(f"{API_BASE}/convert", {
"access_key": ACCESS_KEY,
"from": "USD",
"to": "INR",
"amount": 1
})
if not fx.get("success"):
raise RuntimeError(f"Convert failed: {fx}")
usd_to_inr = fx["result"] # INR per 1 USD
inr_per_g_22k = usd_per_g_22k * usd_to_inr
print(json.dumps({
"symbol": "MYSO-22k (derived)",
"base_currency": "INR",
"unit": "per gram",
"karat": 22,
"timestamp": timestamp,
"source_base": latest["base"],
"source_unit": unit,
"xau_rate_raw": xau_rate,
"usd_per_oz_24k": usd_per_oz_24k,
"usd_per_g_24k": usd_per_g_24k,
"inr_per_g_22k": inr_per_g_22k
}, indent=2))
What to do with the response fields
- timestamp: store it with your calculated price for reproducibility and time alignment.
- xau_rate_raw: keep it to diagnose changes, spreads, or feed anomalies.
- source_unit and source_base: log for auditability. If a downstream team changes base from USD to INR, you’ll notice immediately.
- inr_per_g_22k: your final MYSO-22k per gram quote.
Backfilling a Mysore 22k per gram history with Time-series
To analyze seasonal patterns, spreads vs futures, or to train pricing models, backfill a daily series. Use the time-series endpoint, then apply the same gram and karat transformations to each day.
Time-series response: structure you’ll consume
{
"success": true,
"timeseries": true,
"start_date": "2026-09-14",
"end_date": "2026-09-21",
"base": "USD",
"rates": {
"2026-09-14": {
"XAU": 0.000485,
"XAG": 0.03825,
"XPT": 0.000915
},
"2026-09-16": {
"XAU": 0.000483,
"XAG": 0.0382,
"XPT": 0.000913
},
"2026-09-21": {
"XAU": 0.000482,
"XAG": 0.03815,
"XPT": 0.000912
}
},
"unit": "per troy ounce"
}
How to use it:
- Loop the date keys in rates.
- For each date, compute USD per ounce = 1 / XAU, then per gram, then 22k factor.
- Localize to INR either by:
- Querying time-series with base=INR (if supported by your plan) so per-day values are already INR-relative, or
- Fetching a parallel INR time-series or using daily converts to transform USD→INR per day.
Be mindful of weekends and market holidays: some days may repeat the last available rate or show fewer updates. Always verify the date coverage and handle gaps gracefully.
A note on symbols and regional naming
MYSO-22k is a regional convention, not a standard ISO-like symbol. Metals-API standardizes gold as XAU (fine/24k). To check current official coverage for metal and currency symbols, consult the Metals-API Supported Symbols page. If you do not see “MYSO-22k” in that list, derive it as shown here—this is a best-practice approach used by trading desks and retailers: start from a benchmark (XAU), apply unit and purity, then add local currency (e.g., INR).
Interpreting the Convert endpoint response
Converting USD amounts to XAU or currency to currency is often part of product pricing logic (e.g., pricing a ring with a known gram weight). Here is a representative Convert response format:
{
"success": true,
"query": {
"from": "USD",
"to": "XAU",
"amount": 1000
},
"info": {
"timestamp": 1789949543,
"rate": 0.000482
},
"result": 0.482,
"unit": "troy ounces"
}
How to use it:
- query: echo of your request parameters. Log for traceability.
- info.timestamp: time of the conversion rate applied; align it with your XAU timestamp if combining data sources.
- info.rate and result: The result is the conversion of your input amount into the target unit/currency. In the example, 1000 USD converts to 0.482 troy ounces of gold.
- unit: when converting to a metal, you’ll get a unit like “troy ounces.” Respect this in your downstream math.
Putting it all together: practical tips developers often miss
- Base currency awareness: If you request base=USD, then rates.XAU is ounces per USD. If you request base=INR, then rates.XAU is ounces per INR. You’ll invert accordingly to get currency per ounce.
- Unit consistency: Always confirm unit in the response. Metals-API returns “per troy ounce” units for metals, which is standard in bullion markets. Never assume grams.
- Karat conversion: Karat is a linear proportion of fine content. 22k is 91.6667% of 24k by mass. Multiply after your per-gram calculation.
- Timestamp discipline: Store and display the timestamp from the API. This matters for audit, reconciliation, and charting against other series.
- Weekends/holidays: Expect fewer updates or repeated values. Implement logic to forward-fill carefully (for charts) but keep track of “stale” flags for trading logic.
- Caching: Cache results for your UI and for repeated calculations (e.g., per minute). This reduces requests and smooths your UX.
- Retry and fallback: Handle transient network errors with exponential backoff. Log and alert if data is stale beyond your risk tolerance.
cURL: time-series backfill for a date range
Fetch daily XAU for a period, then transform to INR 22k per gram. Example:
curl -s "https://metals-api.com/api/timeseries?access_key=YOUR_ACCESS_KEY&base=USD&start_date=2026-09-14&end_date=2026-09-21&symbols=XAU"
Iterate through the “rates” dates, compute per-day INR-per-gram-22k. If your plan permits base=INR on timeseries, switch base=INR to get INR-relative rates directly and remove a separate USD→INR conversion step.
Data analytics and market insights for gold (XAU)
Digital transformation in precious metals increasingly centers on programmatic access to high-quality data and transparent transformations. By treating MYSO-22k as a deterministic function of XAU plus currency and karat math, you create a robust lineage from a global benchmark to a local retail/wholesale quote. This supports:
- Technology integration in trading: align regional pricing with exchange-traded gold exposures.
- Innovation in price discovery: quantify regional spreads (e.g., Mysore vs. London spot) and optimize procurement timing.
- Digital asset solutions: standardize inputs for tokenized gold grams at 22k purity, including automated mark-to-market.
- Data analytics for retailers: simulate margins by overlaying making charges and taxes on the derived per-gram feed.
Security, reliability, and performance patterns
Authentication
- Always pass your access_key as a query parameter.
- Keep keys out of client-side code in public websites. Proxy via your backend and store keys in secure environment variables.
Rate limiting and quotas
- Batching: Request only the symbols you need (e.g., XAU). This reduces payload size and latency.
- Caching: Cache latest for a short TTL aligned with your plan’s update frequency. Many downstream calculations (karat, grams) can be done locally without additional API calls.
Error handling
- Check success in every response. If false, inspect error fields (if present) and back off.
- Validate presence of fields like rates.XAU before computing inverses to avoid division by zero or KeyError.
- Implement retries with jitter. Log HTTP status, response time, and correlation IDs if you add them.
Data validation and sanitization
- Reject nonsensical rates (e.g., negative values) and alert operators.
- Clamp extremely large jumps and require manual confirmation if the move exceeds a predefined threshold.
Performance optimization
- Parallelize conversions in your application layer. Perform per-gram and karat transforms in memory.
- Precompute lookup tables for karat factors if you also publish 18k, 20k, etc.
- Serve calculated quotes from an in-memory store (e.g., Redis) with strict TTL.
Designing a clean “Mysore 22k” pipeline
Recommended architecture
- Ingest: a scheduler hits latest and/or timeseries endpoints.
- Transform: derive per ounce → per gram → 22k factor; convert currency to INR.
- Validate: sanity-check stats and thresholds; include timestamp and unit metadata.
- Distribute: expose as a service endpoint for internal teams and frontends; include a “stale” flag if data age > threshold.
- Observe: metrics for latency, error rates, and price staleness; alert when anomalies occur.
OHLC, fluctuation, and bid/ask—when to use them
For most Mysore 22k workflows, latest and timeseries are sufficient. However, if you want volatility signals or chart candles, consider:
- OHLC endpoint for daily open/high/low/close per symbol. Apply the same gram and karat transforms to each field.
- Fluctuation endpoint to track percent changes over a window; again, apply transforms after you get XAU rates.
- Bid/Ask endpoint to understand spreads; useful for inventory hedging logic and quoting engines.
Representative OHLC format (unit: per troy ounce):
{
"success": true,
"timestamp": 1789949543,
"base": "USD",
"date": "2026-09-21",
"rates": {
"XAU": {
"open": 0.000485,
"high": 0.000487,
"low": 0.000481,
"close": 0.000482
}
},
"unit": "per troy ounce"
}
Transform each field: invert to price-per-oz, divide by 31.1034768 to per-gram, then multiply by 22/24 and convert to INR if needed. For documentation beyond our focused scope here, see the Metals-API Documentation.
Common pitfalls when building MYSO-22k per gram
- Forgetting inversion: If rates.XAU is ounces per USD, you must invert to get USD per ounce.
- Using avoirdupois ounce instead of troy ounce: Always use 31.1034768 g per troy ounce for precious metals.
- Mixing base currencies mid-pipeline: Standardize your pipeline on one base at a time to avoid silent errors.
- Not storing timestamps: You’ll need them to reconcile anomalies and to align with other feeds (e.g., FX or futures).
- Ignoring market closures: Implement graceful fallback for weekends and holidays; consider “last known” with a stale marker.
Quality checks for production
- Recompute parity: Confirm that USD per ounce × rates.XAU ≈ 1 within tolerance.
- Cross-validate INR via base=INR vs USD→INR conversion if your plan allows both. Differences should be minimal; alert on large gaps.
- Snapshot archiving: Persist raw payloads for traceability.
Quick reference: fields you’ll log and expose
- final_price: inr_per_g_22k
- final_unit: per gram
- final_purity: 22k
- source_symbol: XAU
- source_unit: per troy ounce
- source_base: USD or INR
- timestamp: epoch seconds from API
- fx_method: base=INR direct or USD→INR convert
Get started
Sign up and get a key at the Metals-API Website. Then skim the Metals-API Documentation and confirm symbol coverage at Metals-API Supported Symbols. With that, you can stand up a MYSO-22k per-gram stream in under an hour and plug it into pricing pages, inventory revaluations, or alert systems.
Additional resources
- Official Metals-API Documentation – endpoints, parameters, and limits.
- Supported Symbols – check XAU and currency availability.
- Main Website – get your free API key to start prototyping.
- Bureau of Indian Standards (BIS) – background on hallmarking and karatage standards.
- Reserve Bank of India – macro and FX policy context around INR.
Conclusion
To quote Mysore Gold 22k per gram in Python using Metals-API, start with XAU (fine gold per troy ounce), invert to get price per ounce in your base currency, convert to per gram, apply the 22k factor, and localize to INR. This deterministic, auditable pipeline bridges global benchmarks and local market practice. With careful handling of base currency, units, timestamps, and caching, you can deliver a fast, stable, and transparent MYSO-22k per-gram feed into any fintech, trading, or retail system. Ready to build? Visit the Metals-API Website to get a free API key and start integrating today.
FAQ
Is MYSO-22k a native Metals-API symbol?
No. It’s a regional convention. Derive it from XAU with unit and purity transforms, then convert to INR.
What unit does Metals-API use for gold?
Per troy ounce by default. Convert to grams with 31.1034768 grams per troy ounce.
How do I handle weekends and holidays?
Expect fewer updates or repeats. Forward-fill for charts with a “stale” marker; avoid using stale data for trading decisions.
What about making charges and taxes?
Metals-API provides the raw benchmark. Add making charges, GST, and other fees downstream based on your business rules.
Can I fetch rates directly in INR?
Depending on your plan, you can set base=INR on endpoints. Otherwise, fetch USD and convert to INR using the Convert endpoint.
How often are latest rates updated?
Update frequency depends on your subscription plan. See the Metals-API Documentation for details.