<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Crystal Ball Markets Developers]]></title><description><![CDATA[Crystal Ball Markets Developers]]></description><link>https://crystalballmarkets.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:16:28 GMT</lastBuildDate><atom:link href="https://crystalballmarkets.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A gold price ticker for a jeweller's site in about 30 lines of JavaScript]]></title><description><![CDATA[Show gold in local money and units (dirhams a gram, rupees for 10 grams) on any site with a free rates API and a few lines of JavaScript.]]></description><link>https://crystalballmarkets.hashnode.dev/gold-price-ticker-javascript</link><guid isPermaLink="true">https://crystalballmarkets.hashnode.dev/gold-price-ticker-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[api]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[gold]]></category><dc:creator><![CDATA[Crystal Ball Markets]]></dc:creator><pubDate>Tue, 01 Dec 2026 22:41:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6afb9d5315bf2ad6f8121736/42cfa7bb-72f3-4761-ba76-e4f27a34bd29.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most people who buy gold check the price in their own money and their own unit: dirhams a gram in Dubai, rupees for 10 grams in Mumbai, naira a gram in Lagos. A jeweller's site that shows that figure answers the first question every visitor has. This tutorial builds a small ticker that does it, with no server code, no API key and no build step.</p>
<p>The figures come from the free rates API of Crystal Ball Markets (I work there). Its <code>gold.json</code> file gives the gold price in local currency for 69 countries, in the unit and purity each country usually buys in, and is refreshed every few minutes. It is free on one condition: the page that shows the figures also shows the link "Rates by Crystal Ball Markets", visible and without <code>nofollow</code>. The ticker below includes it.</p>
<h2>What the file looks like</h2>
<p><code>https://crystalballmarkets.com/markets/api/v1/gold.json</code> returns:</p>
<pre><code class="language-json">{
  "attribution": { "required": true, "text": "Rates by Crystal Ball Markets", "url": "https://crystalballmarkets.com/markets" },
  "updated": "2026-12-01T21:10:00Z",
  "data": {
    "usdPerOunce": 3610.99,
    "countries": [
      { "country": "AE", "currency": "AED", "unit": "gram", "purity": "k24", "price": 426.85 },
      { "country": "IN", "currency": "INR", "unit": "tenGrams", "purity": "k24", "price": 107389 }
    ]
  }
}
</code></pre>
<p>The figures above are an example, and each country entry has a few more fields than shown (the full list is in the <a href="https://crystalballmarkets.com/markets/api/openapi.json">OpenAPI description</a>). The ones we need:</p>
<ul>
<li><code>country</code>: the ISO code, <code>AE</code>, <code>IN</code>, <code>PK</code>, <code>NG</code> and so on.</li>
<li><code>currency</code>: the ISO currency code, which <code>Intl.NumberFormat</code> understands directly.</li>
<li><code>unit</code> and <code>purity</code>: how gold is sold there (<code>tenGrams</code> and <code>k24</code> in India, <code>tola</code> in Pakistan).</li>
<li><code>price</code>: one unit at that purity, in local money.</li>
</ul>
<h2>The ticker</h2>
<p>Paste this where the price should appear and set <code>data-country</code> to your country's code:</p>
<pre><code class="language-html">&lt;div id="gold-ticker" data-country="AE"&gt;
  &lt;strong class="gold-price"&gt;Loading the gold price…&lt;/strong&gt;
  &lt;span class="gold-unit"&gt;&lt;/span&gt;
  &lt;small class="gold-time"&gt;&lt;/small&gt;
  &lt;a href="https://crystalballmarkets.com/markets"&gt;Rates by Crystal Ball Markets&lt;/a&gt;
&lt;/div&gt;
&lt;script&gt;
(function () {
  const box = document.getElementById('gold-ticker');
  const units = { gram: 'gram', tenGrams: '10 grams', tola: 'tola', ounce: 'troy ounce', bhori: 'bhori', pavan: 'pavan', mithqal: 'mithqal' };
  const karats = { k24: '24K', k22: '22K', k21: '21K', k18: '18K', k14: '14K', th965: '96.5%' };
  const show = (cls, text) =&gt; { box.querySelector(cls).textContent = text; };

  async function update() {
    try {
      const res = await fetch('https://crystalballmarkets.com/markets/api/v1/gold.json');
      const body = await res.json();
      if (!res.ok) return show('.gold-price', body.message || 'The price is not available right now.');
      const row = body.data.countries.find((c) =&gt; c.country === box.dataset.country);
      if (!row) return show('.gold-price', 'No gold price for this country.');
      const money = new Intl.NumberFormat(undefined, { style: 'currency', currency: row.currency });
      show('.gold-price', money.format(row.price));
      show('.gold-unit', `per ${units[row.unit] || row.unit}, ${karats[row.purity] || row.purity}`);
      show('.gold-time', `Updated ${new Date(body.updated).toLocaleTimeString()}`);
    } catch (err) {
      // Network trouble: keep the last price on screen and try again at the next refresh.
    }
  }

  update();
  setInterval(update, 5 * 60 * 1000);
})();
&lt;/script&gt;
</code></pre>
<p>For <code>data-country="AE"</code> it shows something like <code>AED 426.85 per gram, 24K</code>; for <code>IN</code>, <code>₹107,389.00 per 10 grams, 24K</code>.</p>
<h2>How it works</h2>
<p><strong>Formatting.</strong> <code>Intl.NumberFormat</code> with <code>style: 'currency'</code> takes the ISO code from the file and writes the right symbol, separators and decimals for the visitor's locale. Passing <code>undefined</code> as the locale uses the visitor's browser setting; pass <code>'en-IN'</code> or <code>'ar-AE'</code> to fix it.</p>
<p><strong>Units and purity.</strong> The file names them with codes so they can be translated; the two small maps turn them into words. Add the units your country uses (the full list is in the OpenAPI description) or write them in your own language.</p>
<p><strong>Refresh.</strong> Every five minutes is plenty: gold rarely moves enough in that time to change what a customer decides, and it keeps the page light.</p>
<p><strong>Errors.</strong> Two kinds are handled differently. If the network fails, the last price stays on screen and the next refresh tries again. If the API answers with an error, for example because the credit link is missing from the page, the ticker shows the API's own message, which says what to fix. Showing that message is more useful to the site owner than a silent blank.</p>
<h2>The credit link</h2>
<p>The link is part of the HTML, not added by the script, so it is there even before the price loads and for visitors without JavaScript. The API checks pages that use its files once a day; a page whose link is missing or marked <code>nofollow</code> gets a warning in the API's answers, and is refused a day later if the link is still not there. Keep it visible and unchanged and nothing else is needed: no key, no sign-up.</p>
<h2>Calling it from a server instead</h2>
<p>The snippet above runs in the visitor's browser, which is the simplest case. If you fetch the file from your own server (to cache it, or for a WordPress plugin), the API asks you to name the page that shows the figures with <code>site=</code> and to send a secret of your own in an <code>X-Site-Key</code> header. The <a href="https://crystalballmarkets.com/markets/rates-api">API page</a> has the details.</p>
<h2>No code at all</h2>
<p>If you would rather not write any code, the same figures come as a ready-made widget: pick the country on the <a href="https://crystalballmarkets.com/markets/widgets">widgets page</a> and paste the embed code it gives you.</p>
<hr />
<p><em>The gold prices in the file are indicative, converted from the international price at the exchange rates the file names; a jeweller's selling price adds making charges and local premiums. Information only, not investment advice.</em></p>
]]></content:encoded></item><item><title><![CDATA[Free gold price and exchange rate API: JSON, no sign-up]]></title><description><![CDATA[Free JSON API: exchange rates for 60 currencies, gold prices for 69 countries and live quotes. No sign-up, CORS on.]]></description><link>https://crystalballmarkets.hashnode.dev/free-gold-price-and-exchange-rate-api-json-no-sign-up</link><guid isPermaLink="true">https://crystalballmarkets.hashnode.dev/free-gold-price-and-exchange-rate-api-json-no-sign-up</guid><category><![CDATA[api]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Crystal Ball Markets]]></dc:creator><pubDate>Tue, 17 Nov 2026 00:21:33 GMT</pubDate><content:encoded><![CDATA[<p>Crystal Ball Markets publishes three free JSON files: exchange rates against the US dollar for 60 currencies, the gold price in local money for 69 countries, and live quotes for 212 markets. There is no sign-up and cross-origin requests are allowed. The condition is a visible, followed link back to us, on a site of your own, wherever the figures appear.</p>
<p>This is a short guide for developers: what each file holds, how to call it, a worked example, and the limits. The full terms and live examples are on the <a href="https://crystalballmarkets.com/markets/rates-api">rates API page</a>.</p>
<h2>What does the API return?</h2>
<ul>
<li><strong>rates.json</strong>: units of each currency per US dollar. Each rate names its source: our own forex quote where we quote the pair, an official fixed rate (a peg), the European Central Bank’s reference rate, or for other currencies the reference rate of the country’s own central bank, with the day it was published.</li>
<li><strong>gold.json</strong>: the gold price in each country’s money, in the unit and purity people there buy in: 10 grams of 24 karat in India, the tola in Pakistan, the baht weight of 96.5% gold in Thailand, the tael in Hong Kong, the troy ounce in a few countries and the gram in most, plus the price of one gram of 24 karat gold and the source of the exchange rate behind it.</li>
<li><strong>quotes.json</strong>: our live bid and ask for every market on our markets hub, from forex and metals to energy, indices, shares and crypto, with the day’s change, high and low, the decimals each market is quoted to and a link to its page.</li>
</ul>
<p>Each file is refreshed every minute and carries the same wrapper: <code>attribution</code> (the link to show), <code>terms</code>, <code>notice</code>, <code>updated</code> (when the newest figure was priced, in UTC) and <code>data</code>.</p>
<h2>How do I call it?</h2>
<p>From a web page, the browser names your site for you. Build the credit link from the file’s own <code>attribution</code> field:</p>
<pre><code class="language-javascript">const res = await fetch('https://crystalballmarkets.com/markets/api/v1/gold.json');
const { data, attribution } = await res.json();
const india = data.countries.find((c) =&gt; c.country === 'IN');
const price = new Intl.NumberFormat('en-IN', { style: 'currency', currency: india.currency }).format(india.price);

const credit = document.createElement('a');
credit.href = attribution.url;
credit.textContent = attribution.text;
document.querySelector('#gold').append(`24K gold, 10 grams: ${price} `, credit);
</code></pre>
<p>From a server, an app or the command line, name the page of your site that shows the figures with <code>site</code>, and send a secret of your own choosing, 16 characters or more, in the <code>X-Site-Key</code> header. The first call reserves that site for your key, and the same site named with another key is refused:</p>
<pre><code class="language-bash">curl -H 'X-Site-Key: your-own-secret-123' \
  'https://crystalballmarkets.com/markets/api/v1/rates.json?site=https://your-site.com/rates'
</code></pre>
<p>From Python:</p>
<pre><code class="language-python">import requests

rates = requests.get(
    'https://crystalballmarkets.com/markets/api/v1/rates.json',
    params={'site': 'https://your-site.com/rates'},
    headers={'X-Site-Key': 'your-own-secret-123'},
    timeout=10,
).json()
naira = rates['data']['rates']['NGN']
print(naira['rate'], naira['source'], naira['time'])
</code></pre>
<p>JSON drops trailing zeros, so a price of 182.50 arrives as 182.5. Each market in quotes.json has a <code>digits</code> field: format bid, ask, high and low to that many decimals.</p>
<h2>Worked example: the gold price in rupees</h2>
<p>At 17:39 UTC on 12 November 2026 gold.json gave gold at $3,873.01 a troy ounce, and rates.json gave the rupee at 94.04 to the dollar (the European Central Bank’s reference rate). A troy ounce is 31.1035 grams, so one gram of 24 karat gold came to 3,873.01 × 94.04 ÷ 31.1035 = ₹11,709.88, and the 10 grams Indian buyers quote came to ₹117,098.76, the figure the file gave for India. Our <a href="https://crystalballmarkets.com/markets/gold-price/india">gold price in India</a> page works it out the same way.</p>
<p>For 22 karat jewellery gold, multiply by the <code>fineness</code> of 0.916. A shop’s price will be higher than either figure: import duty, GST and the making charge are added on top, and dealers set their own margins. Our <a href="https://crystalballmarkets.com/blog/gold-price-today-in-india-how-the-rate-is-set">guide to how the Indian gold rate is set</a> walks through each step.</p>
<h2>What are the limits and terms?</h2>
<ul>
<li>Show this link, visible and unchanged, wherever the figures appear: <code>[Rates by Crystal Ball Markets](https://crystalballmarkets.com/markets)</code>. Do not mark it nofollow, ugc or sponsored.</li>
<li>Calls from a server, an app or a script name the page that shows the figures (<code>site</code>) and carry your own secret (<code>X-Site-Key</code>). The site must be on a domain of your own that does not link to us yet: each new use of the files brings a new link. Sites that already link to us, platforms such as GitHub or <a href="http://dev.to">dev.to</a>, and free hosting such as <a href="http://github.io">github.io</a> or vercel.app cannot be named. Calls that name no site are refused.</li>
<li>Each address may make 60 requests a minute. The files change at most once a minute, so keep each response for at least 60 seconds; beyond the limit the API answers 429.</li>
<li>The figures are indicative, for information only. They are not an offer to buy or sell and must not be shown as dealing prices.</li>
<li>Do not resell the files or offer them as a data feed of your own.</li>
</ul>
<p>Every site that calls the files from its pages, and every page named with <code>site</code>, is checked once a day for the link. Where it is missing, the files carry a warning saying what to fix for 24 hours, then stop answering for that site until the link is back. A named page that does not open counts as missing.</p>
<h2>Is there an OpenAPI description?</h2>
<p>Yes: <a href="https://crystalballmarkets.com/markets/api/openapi.json">openapi.json</a>, in OpenAPI 3.1. Import it into Postman or Insomnia, or feed it to a code generator for typed clients. Every field is described there, with its type and, for currencies and countries, the ISO code it uses.</p>
<h2>Where do the figures come from?</h2>
<p>Market quotes come from our own trading platform. Exchange rates come from our own forex quotes where we quote the pair, then official pegs and the European Central Bank’s daily reference rates; for currencies the ECB does not publish, such as the naira, the Kenyan shilling or the Pakistani rupee, we use the issuing central bank’s own reference rate, collected once a business day through Frankfurter. Rates from commercial data vendors are never included, because their terms do not allow it. Gold in local money is our XAU/USD quote multiplied by that rate. The figures can differ from what banks, exchange offices and jewellers charge.</p>
<h2>What to read next</h2>
<ul>
<li><a href="https://crystalballmarkets.com/markets/rates-api">The rates API page</a>: terms, field list and live examples</li>
<li><a href="https://crystalballmarkets.com/markets/widgets">Free widgets</a>: gold prices, converters and tickers to paste into a page, no code</li>
<li><a href="https://crystalballmarkets.com/markets/learn/what-moves-the-gold-price">What moves the gold price</a>, a lesson in our trading academy</li>
<li><a href="https://crystalballmarkets.com/blog/gold-price-today-in-india-how-the-rate-is-set">Gold price today in India: how the rate is set</a></li>
</ul>
<p>If you want to trade the markets behind these figures, you can <a href="https://crystalballmarkets.com/register">open an account</a> and use the same quotes on our platform. CFDs are complex and carry a high risk of losing money because of leverage.</p>
<h2>Sources</h2>
<ul>
<li><a href="https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html">European Central Bank: euro foreign exchange reference rates</a></li>
<li><a href="https://frankfurter.dev/">Frankfurter: central bank reference rates</a></li>
<li><a href="https://en.wikipedia.org/wiki/Troy_weight">Troy weight: one troy ounce is 31.1034768 grams</a></li>
<li><a href="https://spec.openapis.org/oas/v3.1.0.html">OpenAPI Specification 3.1.0</a></li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS">MDN: cross-origin resource sharing (CORS)</a></li>
<li><a href="https://crystalballmarkets.com/markets/api/v1/gold.json">gold.json</a> and <a href="https://crystalballmarkets.com/markets/api/v1/rates.json">rates.json</a>, read at 17:39 UTC on 12 November 2026</li>
</ul>
]]></content:encoded></item></channel></rss>