Skip to main content

FX Rate API Introduction

The FX Rate APIs allow a Merchant to look up Baokim's foreign exchange rates in real time, convert an amount between two currencies and query the rate history.

The rate returned by these APIs is a reference quote for the requesting Merchant. In the current phase the quote is for reference only and does not commit a transaction — locking a quote to a real FX deal is handled in a later phase. Every quote already carries a quote code (quote_code) so that it can be reconciled and, in the future, re-used to lock the rate.

1. API List

APIEndpointMethodPurpose
Get Currencies/cb-core/api/v1/fx/get-currenciesPOSTReturn the list of currency pairs Baokim can quote for the Merchant.
Get FX Rate/cb-core/api/v1/fx/get-ratePOSTGet the bid/ask rate for one pair, several pairs or all supported pairs.
Convert/cb-core/api/v1/fx/convertPOSTConvert an amount between two currencies using the current rate.
Get Historical Rate/cb-core/api/v1/fx/get-historical-ratePOSTQuery past rates of a currency pair for reconciliation and analysis.

2. Authentication

The FX Rate APIs are part of the Cross Border service and use the same request signing mechanism as the other Cross Border APIs, as defined in Introduction to Baokim API. In short:

  • Every request is sent as a signed JSON body. The signature is placed in the Signature header and authenticates the request and guarantees data integrity.
  • Signing uses the RSA256 (SHA256withRSA) algorithm. The RSA public/private key pair is generated by the Merchant; the private key is kept on the Merchant side and the public key is shared with Baokim during integration.
  • Baokim verifies the signature with the Merchant's public key. An invalid signature is rejected with result code 120 Invalid Signature.
NameValueDescription
Content-Typeapplication/jsonData format is JSON
SignatureDigital signatureDigital signature for request authentication

The Signature header value follows the format defined in Introduction to Baokim API:

keyVersion=1.0,algorithm=RSA256,signature=base64-encoded-signature

3. Common Request Fields

Every FX Rate request contains the following fields in addition to the API-specific fields:

ParamsData TypeRequiredDescription
request_idstring(50)YesUnique code that identifies the request. Suggested format: MerchantCode + BK + YYYYMMDD + UniqueId
request_timestring(19)YesTime the Merchant sends the request. Format: YYYY-MM-DD HH:MM:SS
merchant_codestring(20)YesThe Merchant code defined in the Baokim system, provided to the Merchant during integration

4. Common Response Fields

ParamsData TypeRequiredDescription
response_codeint(4)YesResult code from Baokim, as per the Error Codes table
response_messagestring(200)YesDescription of the result code, as per the Error Codes table
merchant_codestring(20)YesMerchant code provided by Baokim before integration
dataObject/ArrayNoAPI-specific payload. Absent or null on error

See Error Codes for the full list of result codes.

5. Terminology

TermExplanation
Currency pairA pair quoted as BASE/QUOTE, e.g. USD/VND. The first currency is the foreign currency, the second is VND.
bidBuying rate — the rate at which the customer sells the foreign currency (inbound).
askSelling rate — the rate at which the customer buys the foreign currency (outbound).
spreadThe difference ask - bid. Always bid < ask.
quote_codeThe quote code returned with every rate. Used for reconciliation and reserved for rate-lock in a later phase.
last_updatedThe time the underlying rate was last refreshed (freshness of the quote). Format: YYYY-MM-DD HH:MM:SS
valid_untilThe time until which the quote is valid. May be null in the current phase.

6. Bid / Ask and Direction

Rates are always returned two-way (bid and ask) for a pair quoted as BASE/QUOTE (foreign currency / VND).

Customer actionRate appliedExample (USD/VND)
Customer sells foreign ccybidUSD → VND uses bid
Customer buys foreign ccyaskVND → USD uses ask

In the Convert API the direction is derived from the order of from_currency / to_currency: converting a foreign currency into VND applies bid, while converting VND into a foreign currency applies ask. The applied side is echoed back in the response (rate_type).

7. Supported Currency Pairs

  • USD/VND is always available.
  • Other pairs (for example CNY/VND) are optional and depend on the upstream source bank and on the Merchant's configuration.
  • Use Get Currencies to retrieve the pairs that are actually quotable for your Merchant. Only pairs that can be reliably quoted are returned.

8. Important Notes

  • Per-Merchant pricing: for the same currency pair, different Merchants may receive different rates according to their configuration/contract.
  • No source disclosure: the APIs return only the final figures. The data source, pricing formula and margin are never exposed.
  • Rate limiting: each Merchant is limited to a maximum number of calls per minute. Exceeding the limit returns a "too many requests, try again later" error (see Error Codes).
  • Traceability: every request carries its own request_id, and every quote carries its own quote_code.
  • Reference only: in the current phase the quote is a reference quote and is not a commitment. If no reliable rate is available at request time, the API returns an "FX rate not available" error.

9. Rate Lookup Flow

Stage 1 — Periodic rate collection (background, on Baokim side)

StepActorDescription
1BaokimCollect rates from the configured source(s).
2BaokimStore the rates together with last_updated.

Stage 2 — Merchant looks up a rate

StepActorDescription
1MerchantSend a rate request for one pair, several pairs or all pairs (optionally with an amount).
2BaokimAuthenticate the request and check the rate limit. If exceeded, return "try again later".
3BaokimRead the stored rate. If still fresh, use it directly; otherwise refresh it from the source.
4BaokimIf the rate cannot be refreshed, return "FX rate not available" and stop.
5BaokimApply the Merchant's pricing configuration, compute bid/ask, generate a quote_code.
6BaokimReturn bid/ask + quote_code + last_updated + valid_until.