We're excited to introduce a highly requested features, now ready to be used - mathematical operations support for the live rates endpoint.
This feature allows you to calculate premiums, discounts, and other price adjustments directly through the API. This feature is particularly useful for dealers and businesses that need to factor in additional costs or calculate custom pricing that may not have the ability to do so in their own systems.
You can use basic mathematical operators (add, subtract, multiply, divide) using function notation. The operators are applied to the result of the query.
Let's look at some practical examples using gold prices:
To add a $50 premium to the gold price:
/api/v1/latest?api_key=YOUR_API_KEY&base=XAU&symbols=USD&math=add(value,50)
This would return the gold price plus $50. For example, if gold is $2,000/ troy oz, the result would be $2,050/troy oz.
To add a 5% dealer premium using EUR as the base currency:
/api/v1/latest?api_key=YOUR_API_KEY&base=XAU&symbols=EUR&math=multiply(value,1.05)
If gold is €2,000/troy oz, this would return €2,100/troy oz (2000 * 1.05).
You can combine operators for more complex calculations. For example, to add a $10 premium to silver and then apply a 3% tax:
/api/v1/latest?api_key=YOUR_API_KEY&base=XAG&symbols=USD&math=multiply(add(value,10),1.03)
Here's an example that calculates a weighted average between spot price and premium price (80% spot, 20% premium), where the premium is spot + $100:
/api/v1/latest?api_key=YOUR_API_KEY&base=XAU&symbols=USD&math=add(multiply(value,0.8),multiply(add(value,100),0.2))
If gold is $2,000/troy oz, this would calculate:
80% of spot price: $2,000 × 0.8 = $1,600
Premium price: ($2,000 + $100) × 0.2 = $420
Final weighted price: $1,600 + $420 = $2,020/troy oz
Adding $75 premium for 1oz gold coins
/api/v1/latest?base=XAU&symbols=USD&math=add(value,75)
Adding 7% premium for wholesale orders
/api/v1/latest?base=XAU&symbols=USD&math=multiply(value,1.07)
18k gold calculation (75% of pure gold price)
/api/v1/latest?base=XAU&symbols=USD&math=multiply(value,0.75)
Adding manufacturing cost of $100 plus 20% markup
/api/v1/latest?base=XAU&symbols=USD&math=multiply(add(value,100),1.2)
The math operator feature provides flexibility in price calculations while maintaining the simplicity and reliability of our API. Whether you're a dealer adding premiums or a manufacturer calculating costs, you can now perform these calculations directly through the API.
For more detailed information about our API endpoints and features, visit our documentation page.