How to fetch Mumbai Silver (MUMB-XAG) - Per Gram Price API in Python
You need the live per-gram silver price for Mumbai (symbol: MUMB-XAG) inside a Python workflow so you can quote jewelry SKUs, run a manufacturing cost model, or alert a trader when the local city price moves. In this guide you’ll learn how to request MUMB-XAG from Metals-API, handle the specific symbol restriction you’ll encounter, and structure your Python code so it routes to the required endpoint and converts to grams correctly.
What “MUMB-XAG” represents and why per-gram matters
MUMB-XAG is a city-indexed silver symbol for Mumbai. City prices are useful when you:
- Price retail jewelry or coins against the locally observed market rather than an international benchmark.
- Model silver inputs in smart manufacturing workflows where procurement is tied to Indian city spot references.
- Run digital market analysis that blends industrial demand signals with localized price moves.
In most production systems, per-gram prices are more convenient than troy ounces. Silver is widely used in electronics, solar, and advanced manufacturing; BOMs and ERP item masters often store weights in grams, so converting correctly from the API’s base unit is critical.
Endpoint rules you must know before coding
Metals-API returns rates in JSON with a base currency, timestamp, and a unit. By default the base is USD and metals are quoted “per troy ounce” unless the endpoint specifies otherwise. For global benchmark symbols like XAG you can use endpoints such as Latest or Time-series. However, Indian city symbols have a special rule: you can’t request them from the generic endpoints.
When you try to fetch MUMB-XAG via the Latest endpoint, Metals-API responds with a precise error that tells you which endpoint to use instead. Here is a copy-pasteable request and the exact error envelope returned for MUMB-XAG:
curl -s "https://metals-api.com/api/latest?access_key=YOUR_API_KEY&symbols=MUMB-XAG"
{"success":false,"error":{"code":403,"type":"restricted_symbols","info":"The specified symbols are restricted to the gold-price-india endpoint only.","restricted_symbols":["MUMB-XAG"],"endpoint_required":"\/api\/gold-price-india","message":"Indian gold city symbols can only be used with the \/api\/gold-price-india endpoint."}}
What this tells you:
- success: false — the request failed, so don’t try to parse prices.
- error.code: 403 — a permissions or access constraint, not a network error.
- error.type: restricted_symbols — the symbol exists but is not allowed on this endpoint.
- error.restricted_symbols: ["MUMB-XAG"] — confirms the specific symbol causing the issue.
- error.endpoint_required: /api/gold-price-india — the endpoint you must call for Indian city symbols.
- error.message — a human-readable explanation.
Action: route MUMB-XAG to the /api/gold-price-india endpoint in your code. Don’t retry Latest or Time-series with this symbol. See the full list of supported symbols and their categories here: Metals-API Supported Symbols.
Python: detect restricted symbols and route correctly
The snippet below demonstrates a robust pattern you can drop into your codebase: try the request, detect “restricted_symbols,” and instruct your client to call the required endpoint for MUMB-XAG. The example logs the restriction and shows where you’d plug in the city endpoint call (not expanded here, because its schema is distinct and access is plan-dependent; refer to the docs link that follows).
import os
import requests
API_BASE = "https://metals-api.com/api"
API_KEY = os.getenv("METALS_API_KEY", "YOUR_API_KEY")
def get_mumb_xag_latest():
url = f"{API_BASE}/latest"
params = {
"access_key": API_KEY,
"symbols": "MUMB-XAG"
}
r = requests.get(url, params=params, timeout=10)
data = r.json()
if not data.get("success", False):
err = data.get("error", {})
if err.get("type") == "restricted_symbols" and "MUMB-XAG" in err.get("restricted_symbols", []):
# Route to the required endpoint for Indian city symbols
required = err.get("endpoint_required", "/api/gold-price-india")
raise RuntimeError(
f"MUMB-XAG must be requested from {required}. "
"Update your code to call that endpoint and parse its unit field."
)
# Propagate other errors
raise RuntimeError(f"Metals-API error: {err}")
return data
if __name__ == "__main__":
try:
payload = get_mumb_xag_latest()
# If success were true (it is not, by design for this symbol on /latest),
# you would parse payload['rates']['MUMB-XAG'] and payload['unit'] here.
print(payload)
except Exception as e:
print(f"[MUMB-XAG] routing required: {e}")
Implementation note:
- Keep routing logic at the symbol layer. A small mapping (e.g., {"MUMB-XAG": "/api/gold-price-india"}) prevents unnecessary retries and makes your client predictable.
- Persist and reuse the “unit” and “base” metadata from the response to do correct conversions.
- When you implement the city endpoint call, read its unit field to confirm whether values come back per gram or per troy ounce before converting.
For current, endpoint-specific parameters and response fields, refer to the Metals-API Documentation. If you don’t yet have an API key, start here: Register.
From troy ounces to grams: how to convert correctly
Whether your city endpoint payload returns per ounce or per gram, you should always inspect and trust the response’s “unit” field. If the response indicates “per troy ounce,” use this conversion:
- 1 troy ounce = 31.1034768 grams
- Price per gram = Price per troy ounce / 31.1034768
Conversely, if your payload is already “per gram,” no additional weight conversion is needed. If the payload is per kilogram, divide by 1,000 to get per gram.
Currency base is equally important. Metals-API defaults to base: USD in many endpoints, meaning the numeric rate for a metal is “metal per 1 USD.” In other words, for silver:
- rates.XAG means troy ounces per 1 USD (oz/USD).
- To get USD per troy ounce (USD/oz), invert it. Example: USD/oz = 1 / (oz/USD).
Several endpoints also support direct currency conversions. If you later combine a USD-denominated silver price with an INR exchange rate, ensure both are aligned in time (same timestamp or acceptable tolerance) and adjust to per gram only once to avoid double conversion.
Practical workflow for MUMB-XAG per-gram in production
Since MUMB-XAG requires the gold-price-india endpoint, here is a pattern to implement end-to-end:
- Symbol routing:
- If symbol starts with or matches a known Indian city code (e.g., MUMB-XAG), call the city endpoint indicated in the error above.
- Else, call generic endpoints (Latest, Historical, etc.) for global symbols.
- Verify the returned unit:
- If unit is “per troy ounce,” divide by 31.1034768 for a per-gram view.
- If unit is “per gram,” use as-is.
- Normalize the currency:
- If your downstream system expects INR/gram, ensure the payload base is INR. If the payload is in USD, convert to INR before or after weight conversion, but not both. Consistency is key.
- Cache and throttle:
- Persist the last response keyed by symbol + endpoint + date to avoid repetitive calls within your UI or batch window.
- Respect that precious metals pricing may not update on weekends/holidays; handle unchanged timestamps gracefully.
- Display with context:
- Always surface unit and currency next to the numeric price in UIs (“INR/gram” or “USD/gram”).
- Log the timestamp and source endpoint for auditability.
Handling timestamps, weekends, and market closures
Metals-API responses include a UNIX timestamp and a date. Time alignment matters when you blend metal prices and currency FX rates across endpoints. Cache the timestamp with your stored price and, if you pair it with an FX rate, choose one with a timestamp within your defined tolerance window.
On weekends and some holidays, prices may be unchanged or updated less frequently. You should:
- Treat a repeated timestamp as a valid “no change” event rather than an error.
- Fallback to the last known good price for read-only experiences, and flag the staleness in your UI if it exceeds your threshold.
- Use time-series endpoints (for non-restricted symbols) for backfills; for MUMB-XAG, rely on the required city endpoint’s historical capabilities if offered on your plan.
Building reliable alerts and dashboards for Mumbai silver
For alerts, set a polling interval that matches your plan’s update cadence. Debounce alert triggers to avoid noise from small ticks. Store the last alert state and only notify when a threshold is crossed.
For dashboards or ERP integrations, coalesce updates to limit API traffic. A background worker can refresh MUMB-XAG on a schedule and write normalized values as INR/gram into your datastore, making point-of-sale or BOM calculations fast and offline-tolerant.
Error handling patterns worth copying
Beyond restricted symbols, implement guards for:
- Transport errors: retry with exponential backoff up to a small cap; do not hammer the API.
- success: false: inspect error.code and error.type. Log error.info for operators.
- Missing fields: assert that “unit,” “base,” and symbol-specific rates exist before computing.
- Unexpected units: if unit is not one of the expected values, stop and alert. Do not perform guessed conversions.
This discipline prevents silent unit drifts that can misprice your product catalog or P&L.
Why silver per-gram data unlocks better manufacturing and analytics
Silver’s industrial footprint—from conductive pastes in photovoltaics to high-reliability contacts in smart devices—benefits from granular cost control. In practice, linking MUMB-XAG per-gram prices to:
- Procurement bids: auto-refresh component quotes tied to gram-level silver loads.
- Smart manufacturing: feed per-gram silver costs into MES/ERP to compute batch costs on the fly.
- Digital market analysis: map localized price shifts to production plans or hedging strategies.
Using a unified API lets developers stitch these workflows together without juggling multiple feeds and unit systems.
Quick reference: units, base currency, and inversion
- Weight:
- 1 troy ounce = 31.1034768 grams
- Base currency:
- Many endpoints default to base: "USD". Metals fields like rates.XAG represent oz per 1 USD (oz/USD).
- To get USD per oz, invert: USD/oz = 1 / (oz/USD).
- For per-gram in a local currency, confirm unit first, then convert weight, then convert currency (or vice versa, but consistently).
- Caching:
- Cache by (symbol, endpoint, date/timestamp). Expire based on your plan’s update cadence.
- Staleness:
- Check timestamp fields to detect market closures or unchanged sessions.
Two endpoints relevant to this use case
- Latest (shown above) — good for non-restricted symbols; will return a structured restriction error for MUMB-XAG.
- Gold-price-India — required for Indian city symbols including MUMB-XAG, as the error envelope specifies. Consult the docs for parameters and response fields and confirm the unit returned before converting.
For endpoint specifics, request parameters, and plan details, see the Metals-API Documentation. To explore additional commercial capabilities such as managed connectivity, visit MCP.
FAQ
Can I get MUMB-XAG from the Latest endpoint?
No. As shown above, MUMB-XAG is restricted; Metals-API returns an error with endpoint_required: /api/gold-price-india. Route your request there.
How do I convert to INR per gram?
Confirm the payload’s unit and base. If the city endpoint returns INR per gram, you are done. If it returns per ounce, divide by 31.1034768. If it returns USD-based values, convert to INR using an appropriate FX rate aligned in time, then apply the gram conversion.
Why does my timestamp not change on weekends?
Metals markets and localized references may not update on weekends/holidays. Treat repeated timestamps as “no update,” not an error. Cache the last good value and display a staleness indicator.
Is there a free trial?
No. Metals-API does not offer a free trial. Review plans and get an API key here: Register. For example, Copper Monthly is $19.99/month.
Where can I verify symbols like MUMB-XAG?
Use the official list at Metals-API Supported Symbols. If a symbol is restricted, route to the endpoint indicated by the API error.
Ready to add Mumbai silver per-gram pricing to your Python app with proper routing, units, and timestamps? Get your key and start building today: Register. Keep the docs handy as you wire in the city endpoint: Metals-API Documentation.