We're excited to introduce a highly requested feature, now ready to be used - mathematical operations support for the live rates endpoint.
This feature allows you to calculate spreads, markups, and other price adjustments directly through the API. This feature is particularly useful for forex traders, payment providers, and businesses that need to factor in additional costs or calculate custom pricing.
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 exchange rates:
To add 50 basis points (0.5%) to the exchange rate:
/api/v1/latest?api_key=YOUR_API_KEY&base=USD¤cies=EUR&math=multiply(value,1.005)
This would return the EUR rate with a 50 bips markup. For example, if EUR is 0.92, the result would be 0.9246.
To add a 2% spread to the GBP rate:
/api/v1/latest?api_key=YOUR_API_KEY&base=USD¤cies=GBP&math=multiply(value,1.02)
If GBP is 0.79, this would return 0.8058 (0.79 * 1.02).
You can combine operators for more complex calculations. For example, to add a fixed fee of 0.001 and then apply a 1% markup:
/api/v1/latest?api_key=YOUR_API_KEY&base=USD¤cies=EUR&math=multiply(add(value,0.001),1.01)
Here's an example that calculates a weighted average between spot rate and premium rate (80% spot, 20% premium), where the premium adds 0.01:
/api/v1/latest?api_key=YOUR_API_KEY&base=USD¤cies=EUR&math=add(multiply(value,0.8),multiply(add(value,0.01),0.2))
If EUR is 0.92, this would calculate:
80% of spot rate: 0.92 × 0.8 = 0.736
Premium rate: (0.92 + 0.01) × 0.2 = 0.186
Final weighted rate: 0.736 + 0.186 = 0.922
Adding 25 bips spread for retail customers:
/api/v1/latest?base=USD¤cies=EUR,GBP,JPY&math=multiply(value,1.0025)
Adding 100 bips for credit card transactions:
/api/v1/latest?base=USD¤cies=EUR&math=multiply(value,1.01)
Cross-border payment with 1.5% fee:
/api/v1/latest?base=USD¤cies=EUR&math=multiply(value,1.015)
Adding fixed processing fee of 0.002 plus 0.5% markup:
/api/v1/latest?base=USD¤cies=GBP&math=multiply(add(value,0.002),1.005)
The math operator feature provides flexibility in rate calculations while maintaining the simplicity and reliability of our API. Whether you're a trading platform adding spreads or a business calculating transfer 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.