Package Exports
- trm-api
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (trm-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
TRM API
The trm-api package is a wrapper to simplify GET requests and JSON response parsing from the Tasa Representativa del Mercado API.
Install
npm install trm-apiUsage
The TrmApi class provides three methods: latest(), between(options), and history(options?).
const TrmApi = require('trm-api');
const trmapi = new TrmApi();App Token
A limited number of requests can be made without an app token, but they are subject to much lower throttling limits than request that do include one.
With an app token, your application is guaranteed access to it's own pool of requests.

You can pass your app token in the constructor:
const TrmApi = require('trm-api');
const trmapi = new TrmApi('YOUR-APP-TOKEN-HERE');latest()
Provides the most recent quote:
trmapi
.latest()
.then((data) => console.log(data))
.catch((error) => console.log(error));The response is an object with the latest information from the Tasa Representativa del Mercado API:
{
valor: '3792.98',
unidad: 'COP',
vigenciadesde: '2020-08-05T00:00:00.000',
vigenciahasta: '2020-08-05T00:00:00.000'
}between(options)
Returns an array with the quotes between two dates: startAt and endAt.
The options argument is an object with the following fields:
| Field | Type | Description |
|---|---|---|
| startAt | Required | The initial date of the data to be retrieved in YYYY-MM-DD format. |
| endAt | Required | The final date of the data to be retrieved in YYYY-MM-DD format. |
| order? | Optional | Can be 'ASC' or 'DESC'. Defaults to 'ASC'. |
trmapi.trmapi
.between({ startAt: '2020-07-02', endAt: '2020-07-7', order: 'DESC' })
.then((data) => console.log(data))
.catch((error) => console.log(error));Will return the following array:
[
{
valor: '3633.32',
unidad: 'COP',
vigenciadesde: '2020-07-07T00:00:00.000',
vigenciahasta: '2020-07-07T00:00:00.000',
},
{
valor: '3645.90',
unidad: 'COP',
vigenciadesde: '2020-07-04T00:00:00.000',
vigenciahasta: '2020-07-06T00:00:00.000',
},
{
valor: '3660.18',
unidad: 'COP',
vigenciadesde: '2020-07-03T00:00:00.000',
vigenciahasta: '2020-07-03T00:00:00.000',
},
{
valor: '3723.67',
unidad: 'COP',
vigenciadesde: '2020-07-02T00:00:00.000',
vigenciahasta: '2020-07-02T00:00:00.000',
},
];history(?options)
Returns an array with all the values starting from the most recent value.
The options optional argument is an object with the following fields:
| Field | Type | Description |
|---|---|---|
| order? | Optional | Can be 'ASC' or 'DESC'. Defaults to ASC. |
| limit? | Optional | Maximum number of results to return. Defaults to 1,000. Maximum of 50,000. |
trmapi
.history({ limit: 30 })
.then((data) => console.log(data))
.catch((error) => console.log(error));TypeScript
The module is written in TypeScript and type definitions files are included.
Contributing
Contributions, issues and feature requests are welcome!
Show your support
Give a ⭐️ if you like this project!