Lendasat LogoLendasat Docs
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:

ParameterTypeDescription
fromstringSource token ID (e.g., btc_arkade)
tostringDestination token ID (e.g., usdc_pol)
baseAmountnumberAmount in smallest unit (satoshis for BTC)

Quote Response

FieldTypeDescription
exchange_ratestringExchange rate (BTC per 1 stablecoin)
network_feenumberNetwork fee estimate in satoshis
protocol_feenumberProtocol fee in satoshis
protocol_fee_ratenumberProtocol fee rate (e.g., 0.0025 = 0.25%)
min_amountnumberMinimum swap amount in satoshis
max_amountnumberMaximum 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

  1. Use Quotes for Accuracy - Always get a fresh quote before creating a swap
  2. Quotes are Time-Limited - Quotes are typically valid for 30-60 seconds
  3. Tiered Pricing - Larger swaps may get better rates
  4. Real-Time for UIs - Use the WebSocket price feed for live trading interfaces
  5. Handle Slippage - The minAmount in quotes accounts for slippage protection