npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trm-api

v1.4.17

Published

A wrapper to simplify GET requests and JSON response parsing from the Tasa Representativa del Mercado API

Downloads

207

Readme

TRM API

npm version build and release codecov CodeFactor

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-api

Usage

The TrmApi class provides five methods: latest(), between(options), history(options?), date(date), and query(query).

CommonJS

const TrmApi = require("trm-api").default;

const trmApi = new TrmApi();

ES6 Modules

import TrmApi from "trm-api";

const trmApi = new TrmApi();

TypeScript

The module is written in TypeScript and type definitions files are included.

App Token

A limited number of requests can be made without an app token, but they are subject to much lower throttling limits than requests that do include one.

With an app token, your application is guaranteed access to it's own pool of requests.

👉 Sign up for an app token!

app-token

You can pass your app token in the constructor:

const trmApi = new TrmApi("YOUR-APP-TOKEN-HERE");

Methods

latest()

Provides the most recent quote:

trmApi
  .latest()
  .then((data) => console.log(data))
  .catch((error) => console.log(error));

The response is a single 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
  .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));

date(date)

Returns the TRM for an specific date given in YYYY-MM-DD format.

trmApi
  .date("2020-08-09")
  .then((data) => console.log(data))
  .catch((error) => console.log(error));

The response is a single object with the information for the given date:

{
  valor: '3769.67',
  unidad: 'COP',
  vigenciadesde: '2020-08-07T00:00:00.000',
  vigenciahasta: '2020-08-10T00:00:00.000'
}

query(query)

This method allows you to use any custom SoQL query.

For example:

trmApi
  .query(
    "SELECT valor, vigenciadesde WHERE valor >= 4150 AND vigenciadesde < '2020-08-01'"
  )
  .then((data) => console.log(data))
  .catch((error) => console.log(error));

It will return an array of objects each with the requested fields (or all the fields if no SELECT clause used):

[
  {
    valor: "4153.91",
    vigenciadesde: "2020-03-20T00:00:00.000",
  },
];

CLI

The packages provides a simple CLI to quickly get TRM quotes.

If called without arguments it will return the current exchange rate:

$ npx --quiet trm-api
3767.05

It can also be called with a given date in YYYY-MM-DD format to get the exchange rate for that date:

$ npx --quiet trm-api 2010-09-23
1803.71

Contributing

Contributions, issues and feature requests are welcome!

Show your support

Give a ⭐️ if you like this project!

License

MIT