graphology-currency-exchange
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Proof of concept project for Currency Exhange using graphs for Job Manager

Base libray: https://graphology.github.io/

What this package is aimed to solve

Suppose you have to convert rom a local currency to a foreign currency and you keep different values per each currency (e.g.: tourism and commercial rates).

This is as yeasy as multiplying the origin currency to the destination currency.

The problem starts when you need to use two currencies which don't have direct conversions, AKA wick currencies, like Brazillian Real and Japanese YEN.

So you'll need an intermediary currency, such as USD or EUR or GBP. In that case you could convert your destination currency for one of those and then back to your original currency.

In the sample above, 1 YEN = 0.0088 USD (today 2021-11-16). So, to get the value in USD you would get your 1 YEN item and multiply by 0.0088 = 0.0088 USD

Now you need to convert it to BRL (Brazillian Real) As of today, 1 USD is equivalent to 5.46. Therefore, your cost of 0.0088 USD becomes 0.0088 * 5.46 = BRL 0.048048

Keeping track of this currencies can be a bug challenge, to solve this issue, I've created this library, in which you can create your currencies and conversions and it will handle all the possible conversions AS YOU REQUEST IT and store back to the graph.

It is based in Graphology package.

Installing

npm install graphology --save
npm install graphology-types --save

Running

ts-node tests/approach.ts #basic approach showing how the algorithm works
ts-node tests/dynamicApproach.ts

Sample

Consider this graph

BRL <-> USD USD <-> EUR CAD <-> USD BRL <-> EUR CAD <-> EUR

Our goal here is, given a base currency and a destination currency, be able to know: a) is there a possible path to get from currency source to currency destination (e.g.: CAD -> BRL) b) get the correct exchange rate or fail

In the graph defined above, it is possible to get from CAN to BRL, passing through USD (CAD -> USD -> BRL).

The approach will be to first find a way to do it. You might note that CAD -> EUR -> BRL is also a possible approach, however as described above I'm not interested in this path right now

Package Sidebar

Install

npm i graphology-currency-exchange

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

12.5 kB

Total Files

4

Last publish

Collaborators

  • gabrielgoiscastor