Adding Math Operators to the API

Last updated on January 12, 2026

< Back to Blogs

Using Math Operators with ForexRateAPI

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.

Basic Syntax

You can use basic mathematical operators (add, subtract, multiply, divide) using function notation. The operators are applied to the result of the query.

Examples

Let's look at some practical examples using exchange rates:

Adding Basis Points (Bips)

To add 50 basis points (0.5%) to the exchange rate:

/api/v1/latest?api_key=YOUR_API_KEY&base=USD&currencies=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.

Percentage Spread

To add a 2% spread to the GBP rate:

/api/v1/latest?api_key=YOUR_API_KEY&base=USD&currencies=GBP&math=multiply(value,1.02)

If GBP is 0.79, this would return 0.8058 (0.79 * 1.02).

Complex Calculations

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&currencies=EUR&math=multiply(add(value,0.001),1.01)

Advanced Operations

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&currencies=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

Common Use Cases

Trading Spreads

  • Adding bid/ask spreads
  • Calculating percentage-based markups
  • Factoring in transaction costs

Payment Processing

  • Adding payment processor fees
  • Calculating cross-border transfer costs
  • Determining wholesale vs retail rates

Tax & Compliance

  • Adding withholding taxes
  • Including regulatory fees
  • Calculating reporting adjustments


Payment Provider

Adding 25 bips spread for retail customers:

/api/v1/latest?base=USD&currencies=EUR,GBP,JPY&math=multiply(value,1.0025)

Adding 100 bips for credit card transactions:

/api/v1/latest?base=USD&currencies=EUR&math=multiply(value,1.01)

International Business

Cross-border payment with 1.5% fee:

/api/v1/latest?base=USD&currencies=EUR&math=multiply(value,1.015)

Adding fixed processing fee of 0.002 plus 0.5% markup:

/api/v1/latest?base=USD&currencies=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.