Skip to main content

Estimate Payment Amount

POST
/rates/calculate/

Calculate the equivalent amount in a target cryptocurrency based on a source amount and currency. This endpoint is useful for showing users how much cryptocurrency they need to pay for a fiat amount.

Authentication

Requires OAuth 2.0 authentication with read scope.

Request Body

ParameterTypeRequiredDescription
amountdecimalYesThe amount to convert
from_currencystringYesSource currency code (e.g., "USD")
to_currencystringYesTarget currency code (e.g., "USDTERC20")
is_fee_paid_by_userbooleanNoWhether user pays the fee (default: true)

Example Request

curl -X POST https://api.cryptofuse.io/rates/calculate/ \
-H "Authorization: Bearer your_access_token" \
-H "Content-Type: application/json" \
-d '{
"amount": 100.00,
"from_currency": "USD",
"to_currency": "USDTERC20",
"is_fee_paid_by_user": true
}'

Response

Success Response (200 OK)

{
"from_currency": "USD",
"from_amount": "100.00",
"to_currency": "USDTERC20",
"to_amount": "100.050000",
"exchange_rate": "0.9999",
"fee_amount": "0.050000",
"fee_currency": "USDTERC20",
"total_amount": "100.050000",
"rate_expires_at": "2025-01-15T10:05:00Z",
"calculation_timestamp": "2025-01-15T10:00:00Z"
}

Response Fields

FieldTypeDescription
from_currencystringSource currency code
from_amountstringSource amount
to_currencystringTarget cryptocurrency code
to_amountstringConverted amount (before fees)
exchange_ratestringExchange rate used
fee_amountstringFee amount (if user pays)
total_amountstringTotal amount user needs to pay
rate_expires_atdatetimeWhen this rate expires

Error Responses

400 Bad Request

{
"error": {
"code": "invalid_request",
"message": "Invalid request parameters",
"details": {
"amount": ["Must be greater than 0"]
}
}
}

422 Unprocessable Entity

{
"error": {
"code": "invalid_currency",
"message": "Currency not supported",
"details": {
"currency": "FAKECOIN",
"supported_currencies": ["USDTERC20", "USDCERC20", "DAIERC20"]
}
}
}

Supported Currency Pairs

From Currencies (Fiat)

  • USD - US Dollar
  • EUR - Euro
  • GBP - British Pound

To Currencies (Crypto)

  • USDTERC20 - Tether USD on Ethereum
  • USDCERC20 - USD Coin on Ethereum
  • DAIERC20 - DAI Stablecoin on Ethereum
  • ETH - Ethereum
  • WETH - Wrapped Ethereum

Fee Calculation

When is_fee_paid_by_user is true:

Base Amount: 100.00 USD
Exchange Rate: 0.9999 (1 USD = 0.9999 USDT)
Converted Amount: 99.99 USDT
Network Fee: 0.05 USDT
Transaction Fee: 0.01 USDT (0.01%)
Total Fee: 0.06 USDT
Total Amount: 100.05 USDT

When is_fee_paid_by_user is false:

Base Amount: 100.00 USD
Exchange Rate: 0.9999
Converted Amount: 99.99 USDT
Fees paid by merchant
User Pays: 99.99 USDT

Rate Validity

  • Exchange rates are updated every minute
  • Rates are typically valid for 5 minutes
  • Always check rate_expires_at field
  • For volatile pairs, rates may expire sooner

Usage Examples

E-commerce Checkout

// Show customer how much crypto to pay for $100 order
async function calculateCryptoAmount(orderAmount) {
const response = await fetch('https://api.cryptofuse.io/rates/calculate/', {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: orderAmount,
from_currency: 'USD',
to_currency: 'USDTERC20',
is_fee_paid_by_user: true
})
});

const data = await response.json();

// Display to customer
console.log(`Pay ${data.total_amount} ${data.to_currency}`);
console.log(`Exchange rate: 1 USD = ${data.exchange_rate} USDT`);
console.log(`Includes ${data.fee_amount} USDT in fees`);
}

Gaming/Casino Deposits

def show_deposit_options(deposit_usd):
"""Show player crypto deposit amounts for different currencies."""

currencies = ['USDTERC20', 'USDCERC20', 'DAIERC20']
options = []

for currency in currencies:
response = requests.post(
'https://api.cryptofuse.io/rates/calculate/',
json={
'amount': deposit_usd,
'from_currency': 'USD',
'to_currency': currency,
'is_fee_paid_by_user': True
},
headers={'Authorization': f'Bearer {access_token}'}
)

if response.status_code == 200:
data = response.json()
options.append({
'currency': currency,
'amount': data['total_amount'],
'expires': data['rate_expires_at']
})

return options

# Show deposit options for $100
deposit_options = show_deposit_options(100.00)
for option in deposit_options:
print(f"Deposit {option['amount']} {option['currency']}")

Important Notes

  • This endpoint does not create a payment - it only calculates amounts
  • Use the calculated amount within the validity period
  • Actual payment amount may differ slightly due to rate changes
  • For stablecoins (USDT, USDC, DAI), rates are typically near 1:1 with USD
  • Network congestion may affect fee calculations

Next Steps