Balance Transfers

Currency exchange between virtual accounts

Balance Transfers (Currency Exchange)

Transfer funds between different currency virtual accounts instantly.

What is BALANCE_TRANSFER?

BALANCE_TRANSFER allows you to convert funds from one currency to another within your virtual accounts - instantly and without external bank transfers.

Use cases:

  • Convert COP to USD for international payments
  • Rebalance currency holdings
  • Lock in favorable exchange rates
  • Prepare funds for specific currency payouts

How It Works

Process:

  1. Check source currency balance
  2. Get exchange rate quote
  3. Create BALANCE_TRANSFER order
  4. Funds instantly transferred between accounts

Quick Example

Node.js
1// Convert 1,000,000 COP to USD
2
3// 1. Get quote
4const quote = await axios.post(
5 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/quotes`,
6 {
7 type: 'BALANCE_TRANSFER',
8 originCurrencySymbol: 'COP',
9 destinationCurrencySymbol: 'USD',
10 amountIn: 1000000
11 },
12 { headers: { 'Authorization': `Bearer ${token}` } }
13);
14
15console.log('Exchange rate:', quote.data.exchangeRate); // e.g., 4000 COP per USD
16console.log('Will receive:', quote.data.amountOut, 'USD'); // e.g., 248.75 USD
17console.log('Fee:', quote.data.koyweFee, 'COP'); // e.g., 5000 COP
18
19// 2. Create transfer order
20const order = await axios.post(
21 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/orders`,
22 {
23 type: 'BALANCE_TRANSFER',
24 originCurrencySymbol: 'COP',
25 destinationCurrencySymbol: 'USD',
26 amountIn: 1000000,
27 quoteId: quote.data.id // Lock the rate
28 },
29 { headers: { 'Authorization': `Bearer ${token}` } }
30);
31
32console.log('Transfer completed:', order.data.status); // "COMPLETED"

Instant Settlement: BALANCE_TRANSFER orders complete immediately - no waiting for bank confirmations!


Step-by-Step Integration

Step 1: Check Source Balance

Check Balance
1const balances = await axios.get(
2 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/bank-accounts/balances`,
3 { headers: { 'Authorization': `Bearer ${token}` } }
4);
5
6const copBalance = balances.data.find(b => b.currencySymbol === 'COP');
7
8if (copBalance.availableBalance < 1000000) {
9 throw new Error('Insufficient COP balance');
10}

Step 2: Get Exchange Rate Quote

Get Quote
1const quote = await axios.post(
2 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/quotes`,
3 {
4 type: 'BALANCE_TRANSFER',
5 originCurrencySymbol: 'COP',
6 destinationCurrencySymbol: 'USD',
7 amountIn: 1000000
8 },
9 { headers: { 'Authorization': `Bearer ${token}` } }
10);
11
12// Show rate to user
13console.log(`Rate: 1 USD = ${quote.data.exchangeRate} COP`);
14console.log(`You'll receive: ${quote.data.amountOut} USD`);
15console.log(`Fee: ${quote.data.koyweFee} COP`);
16console.log(`Quote expires in: ${quote.data.validFor} seconds`);

Step 3: Create Transfer Order

Create Transfer
1const order = await axios.post(
2 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/orders`,
3 {
4 type: 'BALANCE_TRANSFER',
5 originCurrencySymbol: 'COP',
6 destinationCurrencySymbol: 'USD',
7 amountIn: 1000000,
8 quoteId: quote.data.id, // Use quote to lock rate
9 externalId: `transfer-${Date.now()}`,
10 description: 'COP to USD conversion'
11 },
12 { headers: { 'Authorization': `Bearer ${token}` } }
13);
14
15console.log('Status:', order.data.status); // "COMPLETED" (instant)

Step 4: Verify New Balances

Check Balances
1const newBalances = await axios.get(
2 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/bank-accounts/balances`,
3 { headers: { 'Authorization': `Bearer ${token}` } }
4);
5
6const copBalance = newBalances.data.find(b => b.currencySymbol === 'COP');
7const usdBalance = newBalances.data.find(b => b.currencySymbol === 'USD');
8
9console.log('COP balance:', copBalance.availableBalance); // Decreased
10console.log('USD balance:', usdBalance.availableBalance); // Increased

Supported Currency Pairs

FromToUse Case
COPUSDInternational payments
BRLUSDCross-border transactions
MXNUSDUS dollar holdings
CLPUSDCurrency hedging
USDCOPLocal currency operations
USDBRLBrazilian operations

Most common: Local currency โ†” USD


Complete Example

Full Transfer Flow
1async function transferCurrency(fromCurrency, toCurrency, amount) {
2 try {
3 // 1. Authenticate
4 const authResponse = await axios.post(
5 'https://api-sandbox.koywe.com/api/v1/auth/sign-in',
6 { apiKey: process.env.KOYWE_API_KEY, secret: process.env.KOYWE_SECRET }
7 );
8 const token = authResponse.data.token;
9
10 // 2. Check source balance
11 const balances = await axios.get(
12 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/bank-accounts/balances`,
13 { headers: { 'Authorization': `Bearer ${token}` } }
14 );
15
16 const sourceBalance = balances.data.find(b => b.currencySymbol === fromCurrency);
17
18 if (!sourceBalance || sourceBalance.availableBalance < amount) {
19 throw new Error(`Insufficient ${fromCurrency} balance`);
20 }
21
22 console.log(`โœ“ Sufficient balance: ${sourceBalance.availableBalance} ${fromCurrency}`);
23
24 // 3. Get quote
25 const quoteResponse = await axios.post(
26 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/quotes`,
27 {
28 type: 'BALANCE_TRANSFER',
29 originCurrencySymbol: fromCurrency,
30 destinationCurrencySymbol: toCurrency,
31 amountIn: amount
32 },
33 { headers: { 'Authorization': `Bearer ${token}` } }
34 );
35
36 const quote = quoteResponse.data;
37 console.log(`โœ“ Quote received`);
38 console.log(` Rate: 1 ${toCurrency} = ${quote.exchangeRate} ${fromCurrency}`);
39 console.log(` Amount out: ${quote.amountOut} ${toCurrency}`);
40 console.log(` Fee: ${quote.koyweFee} ${fromCurrency}`);
41
42 // 4. Create transfer
43 const orderResponse = await axios.post(
44 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/orders`,
45 {
46 type: 'BALANCE_TRANSFER',
47 originCurrencySymbol: fromCurrency,
48 destinationCurrencySymbol: toCurrency,
49 amountIn: amount,
50 quoteId: quote.id
51 },
52 { headers: { 'Authorization': `Bearer ${token}` } }
53 );
54
55 const order = orderResponse.data;
56 console.log(`โœ“ Transfer completed instantly`);
57 console.log(` Order ID: ${order.id}`);
58 console.log(` Status: ${order.status}`);
59
60 return {
61 success: true,
62 orderId: order.id,
63 amountOut: quote.amountOut,
64 currency: toCurrency
65 };
66
67 } catch (error) {
68 console.error('Transfer failed:', error.response?.data || error.message);
69 throw error;
70 }
71}
72
73// Usage
74await transferCurrency('COP', 'USD', 1000000);

Next Steps