Skip to content

Latest commit

 

History

History
205 lines (131 loc) · 3.52 KB

README.md

File metadata and controls

205 lines (131 loc) · 3.52 KB

local-quote

This SDK allows partners to quote for their customers without reaching RemessaOnline SaaS.




Custom Types


Direction = 'INBOUND' | 'OUTBOUND'

Purpose = 'CRYPTO' | 'PAYMENT_PROCESSING' | 'EFX_OWN_ACCOUNT_ABROAD' | 'EFX_UNILATERAL_TRANSFERS' | 'OTHER_TECHNICAL_SERVICES' | 'CAPITAL_INCREASE' | 'GAMBLING_AND_BETS'

CurrencyISO = 'USD' | 'BRL' | 'EUR' | 'AUD' | 'CHF'

Quote = {
  id: string, //uuid
  direction: string, // Direction
  purpose: string, // Purpose
  baseCurrencyISO: string, // CurrencyISO
  quotedCurrencyISO: string, // CurrencyISO
  exchangeRate: number,
}

LocalQuote = {
  id: string, //uuid
  direction: string,
  purpose: string,
  baseCurrencyISO: string,
  quotedCurrencyISO: string,
  amount: number,
  totalBaseAmount: number,
  exchangeRate: number,
  tax: number,
}



Methods


calculate(quote: Quote, amount:number) :LocalQuote

Example:

import {quoteCalculator} from '@beetech/partner-sdk'

const quote = {
  id: '123e4567-e89b-12d3-a456-426655440000',
  direction: 'OUTBOUND',
  purpose: 'CRYPTO',
  baseCurrencyISO: 'USD',
  quotedCurrencyISO: 'BRL',
  exchangeRate: 5.4,
}

const amount = 10000;

const localQuote = quoteCalculator.calculate(quote, amount)



Currency Pair


A currency pair is defined by two ordered ISO-4217 (three letters) currencies: BASE/QUOTED.

Examples:

  • The outbound case USD / BRL means we want to buy our base (USD) using, quoting by or selling (BRL).
  • The inbound case BRL / USD means we want to buy our base (BRL) using, quoting by or selling (USD).



Exchange math for outbound


IOF

IOF tax rate is set at 0.38% of the value in BRL.

const IOF = 0.0038;

Outbound - direct flow

In the direct flow, the value of USD is known and the BRL value needs to be found.

const totalAmount = (amount * exchangeRate) * (1 + tax);
return totalAmount;

Outbound - inverse flow

In the inverse flow, the value of BRL is known and the value in USD needs to be found.

const totalAmount = (amount / (1 + tax)) / exchangeRate;
return totalAmount;


Exchange math for inbound


IOF

IOF tax rate is set at 0% of the value.

const IOF = 0.0038;

Inbound - direct flow

In the direct flow, the value of BRL is known and the value in USD must be found.

const totalAmount = (amount / exchangeRate) * (1 + tax);
return totalAmount;

Inbound - inverse flow

In the inverse flow, the value of USD is known and the value in BRL needs to be found.

const totalAmount = (exchangeRate * totalAmount) * (1 - tax);
return totalAmount;

After calculating the USD value it is necessary to find the new exchange-rate



How to calculate the exchange-rate

const spread = 0.005;
const bankFee = 0;
const fixedTaxAmount = 0;
const totalPercentualTax = 0.0038;
const totalReadjustedTax = 0;
const spreadPrecision = 1 - spread;
const marketRate = (amount + bankFee + fixedTaxAmount) /
(totalQuotedAmount * spreadPrecision * (1 - totalPercentualTax - totalReadjustedTax));

const exchangeRate = marketRate * spreadPrecision;

return exchangeRate;



Precision and Rounding

  • Amounts have two decimal places.
  • Rates have six decimal places.
  • Rounding rule is ROUND_HALF_EVEN.
  • Rounding is only done right before attributions.