Quotes & Rates
Get Exchange Rate
Retrieve current exchange rates and quotes for swap pairs
Get Quote
Get a quote for a specific swap amount. The quote includes the exchange rate, fees, and expected output amount.
const quote = await client.getQuote("btc_lightning", "usdc_pol", 100000);
console.log("Rate:", quote.exchange_rate);
console.log("Network fee:", quote.network_fee, "sats");
console.log("Protocol fee:", quote.protocol_fee, "sats");
console.log("Min:", quote.min_amount, "sats");
console.log("Max:", quote.max_amount, "sats");Parameters:
| Parameter | Type | Description |
|---|---|---|
from | string | Source token ID (e.g., btc_arkade) |
to | string | Destination token ID (e.g., usdc_pol) |
baseAmount | number | Amount in smallest unit (satoshis for BTC) |
Quote Response
| Field | Type | Description |
|---|---|---|
exchange_rate | string | Exchange rate (BTC per 1 stablecoin) |
network_fee | number | Network fee estimate in satoshis |
protocol_fee | number | Protocol fee in satoshis |
protocol_fee_rate | number | Protocol fee rate (e.g., 0.0025 = 0.25%) |
min_amount | number | Minimum swap amount in satoshis |
max_amount | number | Maximum swap amount in satoshis |
Real-Time Price Feed
For real-time price updates, use the WebSocket price feed service:
import { PriceFeedService } from "@lendasat/lendaswap-sdk-pure";
const priceFeed = new PriceFeedService("wss://apilendaswap.lendasat.com");
const unsubscribe = priceFeed.subscribe((update) => {
console.log("Updated:", new Date(update.timestamp * 1000));
for (const pair of update.pairs) {
console.log(`${pair.pair}: tier_1=${pair.tiers.tier_1}`);
}
});
// Call unsubscribe() when done, or priceFeed.close()Price Calculation Example
Calculate expected output for different amounts:
import {
calculateSourceAmount,
calculateTargetAmount,
computeExchangeRate,
selectTierRate,
} from "@lendasat/lendaswap-sdk-pure";
// Get rate for amount tier
const rate = selectTierRate(priceTiers, 100000);
const networkFee = 0.0001; // in BTC
// Compute the exchange rate (handles inversion for BTC→EVM)
const exchangeRate = computeExchangeRate(rate, true, true);
// Calculate: "I want to send 100k sats, how much USDC?"
const targetAmount = calculateTargetAmount(0.001, exchangeRate, networkFee, true, false);
// Calculate: "I want to receive 50 USDC, how many sats?"
const sourceAmount = calculateSourceAmount(50, exchangeRate, networkFee, true, false);Best Practices
- Use Quotes for Accuracy - Always get a fresh quote before creating a swap
- Quotes are Time-Limited - Quotes are typically valid for 30-60 seconds
- Tiered Pricing - Larger swaps may get better rates
- Real-Time for UIs - Use the WebSocket price feed for live trading interfaces
- Handle Slippage - The
minAmountin quotes accounts for slippage protection