Skip to main content

Overview

The SwapClient provides access to exchange rate discovery and swapping functionality for the Bloque platform. It serves as the main entry point for:
  • Finding available exchange rates between asset pairs
  • Accessing PSE payment utilities
  • Managing generic bank transfer cash-outs to Colombian banks

Constructor

The SwapClient is automatically initialized when you create a Bloque SDK instance. Access it via bloque.swap.
import { Bloque } from '@bloque/sdk';

const bloque = new Bloque({ apiKey: 'your-api-key' });
const swapClient = bloque.swap;

Properties

pse

pse
PseClient
required
PSE (Pagos Seguros en Línea) utilities client for listing banks and creating PSE swap orders.See PseClient for details.

bankTransfer

bankTransfer
BankTransferClient
required
Generic bank transfer client for cash-out swaps supporting all Colombian banks.See BankTransferClient for details.

Methods

findRates()

Retrieves available exchange rates for a given asset pair with optional filters.
async findRates(params: FindRatesParams): Promise<FindRatesResult>

Parameters

params
FindRatesParams
required
Rate search parameters

Returns

FindRatesResult
object

Example

const result = await bloque.swap.findRates({
  fromAsset: 'COP/2',
  toAsset: 'DUSD/6',
  fromMediums: ['bancolombia'],
  toMediums: ['kusama'],
  amountSrc: '50000000' // 500000.00 COP (scaled by 2 decimals)
});

console.log('Exchange ratio:', result.rates[0].ratio);
console.log('Fee breakdown:', result.rates[0].fee.components);

Fee Structure

Exchange rates include detailed fee information with multiple components:

Fee Component Types

percentage
FeeComponentType
Percentage-based fee (e.g., 2.5% of transaction)
  • percentage: The percentage value (e.g., 2.5)
  • Used for: Platform fees, take rates
rate
FeeComponentType
Exchange rate-based fee
  • pair: Currency pair (e.g., “USD/COP”)
  • Used for: Exchange rate spreads
fixed
FeeComponentType
Fixed amount fee
  • amount: Fixed fee amount
  • Used for: PSE transaction fees, bank transfer fees

Fee Calculation Example

const rate = result.rates[0];

console.log('Total fee:', rate.fee.value);
console.log('Fee formula:', rate.fee.formula);

// Inspect individual components
for (const component of rate.fee.components) {
  console.log(`${component.name} (${component.type}):`, component.value);
  
  if (component.type === 'percentage') {
    console.log('  Percentage:', component.percentage);
  } else if (component.type === 'rate') {
    console.log('  Pair:', component.pair);
  } else if (component.type === 'fixed') {
    console.log('  Amount:', component.amount);
  }
}

Rate Calculation

Rates are calculated based on:
  1. Base exchange rate: The market rate between the two assets
  2. Medium fees: Fees charged by payment providers (e.g., PSE, bank transfers)
  3. Platform fees: Bloque’s service fee
  4. Amount: The source or destination amount you specify

Understanding the Rate Tuple

The rate field is a tuple [sourceAmount, destinationAmount] representing the conversion:
const [srcAmount, dstAmount] = rate.rate;
const ratio = rate.ratio; // dstAmount / srcAmount

// Example: [100000, 95000] means 1000.00 COP = 950.00 COP after fees
// Ratio: 0.95 (95% conversion after 5% fees)

Amount Limits

Each rate includes minimum and maximum amounts:
const [minSrc, maxSrc] = rate.fromLimits;
const [minDst, maxDst] = rate.toLimits;

console.log(`Source range: ${minSrc} - ${maxSrc}`);
console.log(`Destination range: ${minDst} - ${maxDst}`);
  • FindRatesParams - Parameters for rate search
  • FindRatesResult - Result containing available rates
  • SwapRate - Individual exchange rate details
  • Fee - Fee structure and breakdown
  • FeeComponent - Individual fee component

Build docs developers (and LLMs) love