Language selection

Search


Exchange Rates Application Programming Interface ( API )

Download the .json file (12.4 KB)

Usage

This API allows users to query for active foreign exchange rates. The recorded rates indicate the number of Canadian dollars required to buy a single unit of the foreign currency. New rates are released by the Bank of Canada (BoC) daily at 16:30. The Canada Border Services (CBSA) retrieves these updates between 4:30pm and 5:00pm EST.

BoC provides 23 foreign exchange rates. All other rates are maintained by the CBSA.

Exchange rates from the BoC are updated daily in the system while other exchange rates are updated by the CBSA at set intervals. The updated rates are available for retrieval between 7:00 pm and 11:59 pm EST.

If the above mentioned window is missed, the user can still fetch active foreign exchange rates by using the Historical Exchange Rate API.

Please note, when using the Historical Exchange Rate API:

  1. The StartDate and EndDate parameters are required.
  2. If fetching a large amount of data use the limit and skip parameters.

Update frequency

As BoC publishes exchange rates every business day, it is recommended that exchange rate data be retrieved on a daily basis. This retrieval should occur after 7:00 pm EST to ensure retrieval of the latest updates.

Technical notes

The Exchange Rate API uses LoopBack 4, an open source framework to create dynamic end-to-end REST API. Please refer to AWS API Gateway for further details. There will be two servers provided, one for development and testing and a second for actual production data. Please ensure these are accessed appropriately during the development lifecycle.

Error codes

Type: Data Validation
HTTP status code: 400 (Bad Request)
Description: The client sends some invalid data in the request, for example, missing or incorrect content in the payload or parameters. Could also represent a generic client error.

Type: Throttling
HTTP status code: 429 (Too Many Requests)
Description: The client is sending more than the allowed number of requests per unit time.

Type: Dependency Issues
HTTP status code: 502 (Bad Gateway)-504 (Gateway Timeout)
Description: A dependent service is throwing errors (502) or timing out (504).

Type: Unhandled Errors
HTTP status code: 500 (Internal Server Error)-503 (Service Unavailable)
Description: The service failed in an unexpected way (500), or is failing but is expected to recover (503).

Paths

GET /exchange-rates

(exchangeRateControllerExternal.find)

Finds all of the exchange rates that match the filter (If no filter is specified all rates are returned)

Query parameters

filter (optional)
Query Parameter

Return type

Example data

Content-Type: application/json
 "ForeignExchangeRates": [
	{
            "ExchangeRateId": 719352,
            "Rate": "0.1589",
            "ExchangeRateEffectiveTimestamp": "2021-11-03T00:00:00.000Z",
            "ExchangeRateExpiryTimestamp": "2021-11-03T23:59:59.000Z",
            "ExchangeRateSource": "BoC",
            "FromCurrency": {
                "Value": "HKD"
            },
            "FromCurrencyCSN": 87,
            "ToCurrency": {
                "Value": "CAD"
            },
            "ToCurrencyCSN": 36
        },
 ]

Produces

This API call produces the following media types according to the Accept request header; the media type will be conveyed by the Content-Type response header.
  • application/json

Responses

200
Array of ExchangeRate model instances

Models

Table of Contents

ExchangeRate.Fields - ExchangeRate.Fields Up

ExchangeRateId
ExchangeRateSourceCSN
FromCurrency
FromCurrencyCSN
ToCurrency
ToCurrencyCSN
Rate
ValidStartDate
ValidEndDate

ExchangeRate.Filter - ExchangeRate.Filter Up

offset (optional)
limit (optional)
example: 100
skip (optional)
order (optional)
oneOf:
where (optional)
fields (optional)

ExchangeRateWithRelations - ExchangeRateWithRelations Up

Model for communicating exchange rates (tsType: ExchangeRateWithRelations, schemaOptions: { includeRelations: true })
ExchangeRateId
Number type: number maxLength: 20 minLength: 1 nullable: false example: CAD to USD
Description: A unique identifier for all active and historical exchange rates
ExchangeRateSourceCSN
Number type: number minLength: 3 maxLength: 4 enum: - BOC - Banque du Canada (BdC) - CBSA - ASFC
Description: A pointer to the source the exchange rate (Primarily Bank of Canada (BoC) and CBSA)
FromCurrency
String type: Char
Description: A pointer to the three character currency description, which represents the currency of the 'Rate'
FromCurrencyCSN
Number type: Char
Description: A pointer to the three character currency code, which represents the currency of the 'Rate'
ToCurrency
String type: Char
Description: A pointer to the three character currency description, which represents the currency of the 'Rate'
ToCurrencyCSN
Number type: Char
Description: A pointer to the three character currency code, which represents the currency of the output when dividing an amount of money (in the 'FromCurrency') by the 'Rate'
Rate
String type: Char
Description: The number of 'FromCurrency' units required to buy a single 'ToCurrency' unit
ValidStartDate
Date type: string format: date-time
Description:The date when the exchange rate is active (inclusive bound)
ValidEndDate
Date type: string format: date-time
Description: The date when the exchange rate is no longer active (exclusive bound)

GET /exchange-rates/ exchange-rates?startDate=2021-10-22&endDate=2021-10-23&limit=10&skip=2

(exchangeRateControllerExternal.find)

Finds all of the exchange rates that match the filter (If no filter is specified all rates are returned)

Query parameters

limit (optional)
example: 100
skip (optional)
startDate
Date type: string format: date-time
Description:The date when the exchange rate is active (inclusive bound)
EndDate
Date type: string format: date-time
Description: The date when the exchange rate is no longer active (exclusive bound)

Return type

array[ExchangeRate]

Example data

Content-Type: application/json
"ForeignExchangeRates": [
        
	{
            "ExchangeRateId": 718988,
            "Rate": "0",
            "ExchangeRateEffectiveTimestamp": "2021-10-22T00:00:00.000Z",
            "ExchangeRateExpiryTimestamp": "2021-10-22T23:59:59.000Z",
            "ExchangeRateSource": "CBSA",
            "FromCurrency": {
                "Value": "bpg"
            },
            "FromCurrencyCSN": 267,
            "ToCurrency": {
                "Value": "CAD"
            },
            "ToCurrencyCSN": 36
        },
        {
            "ExchangeRateId": 718990,
            "Rate": "0",
            "ExchangeRateEffectiveTimestamp": "2021-10-22T00:00:00.000Z",
            "ExchangeRateExpiryTimestamp": "2021-10-22T23:59:59.000Z",
            "ExchangeRateSource": "CBSA",
            "FromCurrency": {
                "Value": "mpg"
            },
            "FromCurrencyCSN": 266,
            "ToCurrency": {
                "Value": "CAD"

            },
            "ToCurrencyCSN": 36
        },
 ]

Produces

This API call produces the following media types according to the Accept request header; the media type will be conveyed by the Content-Type response header.
  • application/json

Responses

200
Array of ExchangeRate model instances

Models

Table of Contents

ExchangeRate.Fields - ExchangeRate.Fields Up

ExchangeRateId
ExchangeRateSourceCSN
FromCurrency
FromCurrencyCSN
ToCurrency
ToCurrencyCSN
Rate
ValidStartDate
ValidEndDate

ExchangeRate.Filter - ExchangeRate.Filter Up

limit (optional)
Integer example: 100
Description: A query parameter to specify the maximum number of 100 items to return in a response
skip (optional)
Integer example: 2
Description: A query parameter to exclude the first 2 items from a response body
StartDate (optional)
Date example: 2021-10-22
Description: A query parameter to exclude the first 2 items from a response body
EndDate (optional)
Date example: 2021-10-23
Description: A query parameter to represent the end of the date range within which the rates are being requested
ExchangeRateId
Number type: number maxLength: 20 minLength: 1 nullable: false example: CAD to USD
Description: A unique identifier for all active and historical exchange rates
ExchangeRateSourceCSN
Number type: number minLength: 3 maxLength: 4 enum: - BOC - Banque du Canada (BdC) - CBSA - ASFC
Description: A pointer to the source the exchange rate (Primarily Bank of Canada (BoC) and CBSA)
FromCurrency
String type: Char
Description: A pointer to the three character currency description, which represents the currency of the 'Rate'
FromCurrencyCSN
Number type: Char
Description: A pointer to the three character currency code, which represents the currency of the 'Rate'
ToCurrency
String type: Char
Description: A pointer to the three character currency description, which represents the currency of the 'Rate'
ToCurrencyCSN
Number type: Char
Description: A pointer to the three character currency code, which represents the currency of the output when dividing an amount of money (in the 'FromCurrency') by the 'Rate'
Rate
String type: Char
Description: The number of 'FromCurrency' units required to buy a single 'ToCurrency' unit
ValidStartDate
Date type: string format: date-time
Description:The date when the exchange rate is active (inclusive bound)
ValidEndDate
Date type: string format: date-time
Description: The date when the exchange rate is no longer active (exclusive bound)
Date modified: