Currencies & Pricing
Access real-time cryptocurrency prices to convert token balances to USD values for portfolio tracking, reporting, and accounting.
GET/currencies
Get all currency prices
Retrieve current USD prices for all supported cryptocurrencies.
Request
GET
/currenciescurl https://api.coinspayd.io/currencies \
-H "x-api-key: {your-api-key}"
Response
{
"BTC": 45000.50,
"ETH": 2500.75,
"MATIC": 0.85,
"BNB": 320.40,
"USDC": 1.00,
"USDT": 1.00,
"DAI": 1.00,
"TRX": 0.12,
"XRP": 0.55
}
GET/currencies/:symbol
Get single currency price
Retrieve the current USD price for a specific cryptocurrency by symbol.
Request
GET
/currencies/BTCcurl https://api.coinspayd.io/currencies/BTC \
-H "x-api-key: {your-api-key}"
Response
45000.50
Calculate portfolio value
Use currency prices to convert token balances to USD values:
// Get portfolio balances
const portfolioResponse = await fetch(
'https://api.coinspayd.io/portfolio',
{
headers: { 'x-api-key': 'your-api-key' }
}
)
const { portfolio } = await portfolioResponse.json()
// Get current prices
const pricesResponse = await fetch(
'https://api.coinspayd.io/currencies',
{
headers: { 'x-api-key': 'your-api-key' }
}
)
const prices = await pricesResponse.json()
// Calculate total USD value
let totalValue = 0
portfolio.forEach(entry => {
// Get token info from entry
const symbol = entry.Token?.symbol
const decimals = entry.Token?.decimals || 18
const balance = parseInt(entry.balance) / 10**decimals
// Get price
const price = prices[symbol] || 0
// Calculate value
const value = balance * price
totalValue += value
console.log(`${balance.toFixed(4)} ${symbol} = $${value.toFixed(2)}`)
})
console.log(`\nTotal Portfolio Value: $${totalValue.toFixed(2)}`)
import requests
# Get portfolio balances
portfolio_response = requests.get(
'https://api.coinspayd.io/portfolio',
headers={'x-api-key': 'your-api-key'}
)
portfolio = portfolio_response.json()['portfolio']
# Get current prices
prices_response = requests.get(
'https://api.coinspayd.io/currencies',
headers={'x-api-key': 'your-api-key'}
)
prices = prices_response.json()
# Calculate total USD value
total_value = 0
for entry in portfolio:
# Get token info
symbol = entry.get('Token', {}).get('symbol')
decimals = entry.get('Token', {}).get('decimals', 18)
balance = int(entry['balance']) / 10**decimals
# Get price
price = prices.get(symbol, 0)
# Calculate value
value = balance * price
total_value += value
print(f"{balance:.4f} {symbol} = ${value:.2f}")
print(f"\nTotal Portfolio Value: ${total_value:.2f}")
Example Output:
1000.0000 USDC = $1000.00
0.5000 BTC = $22500.25
10.0000 ETH = $25007.50
500.0000 MATIC = $425.00
Total Portfolio Value: $48932.75
Supported currencies
The following cryptocurrency symbols are available:
| Symbol | Name | Typical Use |
|---|---|---|
| BTC | Bitcoin | Native cryptocurrency |
| ETH | Ethereum | Native cryptocurrency |
| MATIC | Polygon | Native cryptocurrency |
| BNB | BNB | Native cryptocurrency |
| TRX | Tron | Native cryptocurrency |
| XRP | Ripple | Native cryptocurrency |
| USDC | USD Coin | Stablecoin ($1.00) |
| USDT | Tether | Stablecoin ($1.00) |
| DAI | Dai | Stablecoin ($1.00) |
| BUSD | Binance USD | Stablecoin ($1.00) |
| WBTC | Wrapped Bitcoin | Tracks BTC price |
Price data source
Prices are sourced from reliable cryptocurrency market data providers and updated regularly.
Note: Prices are indicative and for informational purposes. For critical financial operations, verify prices against your preferred data source.
Common use cases
Daily Portfolio Valuation
// Get daily snapshot of portfolio value
async function getDailyPortfolioValue() {
const portfolio = await getPortfolio()
const prices = await getCurrencyPrices()
const breakdown = {}
let total = 0
portfolio.forEach(entry => {
const symbol = entry.Token.symbol
const balance = parseInt(entry.balance) / 10**entry.Token.decimals
const price = prices[symbol] || 0
const value = balance * price
if (!breakdown[symbol]) {
breakdown[symbol] = { balance: 0, value: 0 }
}
breakdown[symbol].balance += balance
breakdown[symbol].value += value
total += value
})
return { breakdown, total, timestamp: new Date() }
}
Real-time Deposit Valuation
// Calculate USD value of incoming deposit
function calculateDepositValue(deposit, prices) {
const symbol = deposit.Token.symbol
const decimals = deposit.Token.decimals
const amount = parseInt(deposit.amount) / 10**decimals
const price = prices[symbol] || 0
const usdValue = amount * price
return {
amount,
symbol,
usdValue,
priceAtDeposit: price
}
}
Accounting Reports
def generate_monthly_report(start_date, end_date):
"""Generate monthly accounting report with USD values"""
deposits = get_deposits_between(start_date, end_date)
prices = get_currency_prices()
report = {
'total_deposits_usd': 0,
'by_currency': {}
}
for deposit in deposits:
symbol = deposit['Token']['symbol']
decimals = deposit['Token']['decimals']
amount = int(deposit['amount']) / 10**decimals
price = prices.get(symbol, 0)
usd_value = amount * price
if symbol not in report['by_currency']:
report['by_currency'][symbol] = {
'count': 0,
'total_amount': 0,
'total_usd': 0
}
report['by_currency'][symbol]['count'] += 1
report['by_currency'][symbol]['total_amount'] += amount
report['by_currency'][symbol]['total_usd'] += usd_value
report['total_deposits_usd'] += usd_value
return report
Caching recommendations
To optimize performance and reduce API calls:
// Cache prices for 1 minute
let priceCache = { data: null, timestamp: 0 }
const CACHE_DURATION = 60 * 1000 // 1 minute
async function getCachedPrices() {
const now = Date.now()
if (priceCache.data && (now - priceCache.timestamp) < CACHE_DURATION) {
return priceCache.data
}
const prices = await fetchPrices()
priceCache = { data: prices, timestamp: now }
return prices
}
import time
# Cache prices for 1 minute
price_cache = {'data': None, 'timestamp': 0}
CACHE_DURATION = 60 # seconds
def get_cached_prices():
now = time.time()
if price_cache['data'] and (now - price_cache['timestamp']) < CACHE_DURATION:
return price_cache['data']
prices = fetch_prices()
price_cache['data'] = prices
price_cache['timestamp'] = now
return prices