Crypto-Aggregator: An Open Source Alternative to CoinMarketCap by@Ourarash

August 31st 2019 631 reads

;

A NodeJs library for calculating Volume Weighted Average Market Pair Price (VWAMPP)

**Summary:** I provide an open-source code for calculating the Volume Weighted Average Market Pair Price (VWAMPP) for all cryptocurrencies. The code continuously fetches the prices from all given exchanges and calcualtes the average price, where the price from each exchange is weighted by its volume. This is an open source alternative to websites such as coinmarketcap. You can download the code from NpmJS.

Let’s begin with a simple question:

What is the true price of Bitcoin or any other cryptocurrency?

**Answer:**

It depends on who you ask from: Bitcoin is currently traded on hundreds of exchanges. all over the world. Each exchange reports a different price. In fact, people make money from taking advantage of this price difference in a process called arbitrage.

So among all these prices which one is the true price of Bitcoin? Let’s take a simple example:

Suppose there are only two exchanges who report the price of BTC in USD:

**Exchange1**reports**$10,000****Exchange2**reports**$12,000**

Which one is the true price?

One way is to report the average of the two prices, i.e., $11,000. The problem with this approach is that there might be only a few trades on **Exchange1**, but millions of trades on **Exchange2**. So a better approach is to give more weight to the exchange that has more trades (or more traffic).

The amount of a cryptocurrency that was traded on an exchange is called the volume.

We would like to give more weight to the exchange with higher volume.

So assume:

**Exchange1**reports**$10,000**with a daily volume of**$1 B****Exchange2**reports**$12,000**with a daily volume of**$99 B**

Now the volume-weighted average price in USD would be:

Image from BitcoinCrazYness.com

Exchanges usually report the price of a market pair, for example: BTC/USD = 10,000 means each BTC is 10,000 USD.

The currency that is used as the reference is called the **quote currency** and the currency that is quoted in relation is called the **base currency. **In this example, BTC is the base, and USD is the quote.

Moreover, exchanges report a volume for each market pair.

Volume-Weighted Average Market Market Pair Price (VWAMPP) is the average of the market pair prices from all exchanges where each market pair price is weighted by its volume.

CoinMarketCap.com and coinGecko.com are among the leading websites to report a volume weighted average price for each coin which is calculated on hundreds of exchanges.

Image from BitcoinCrazYness.com

The **VWAMPP **is a great approach in calculating a fair price for each cryptocurrency, but the problem is that not every exchange reports the price of each cryptocurrency directly in US Dollars (USD).

Picture from unsplash.com

Suppose our example two exchanges report the following:

**Exchange1:**BTC/USD**= 10,000.**Daily volume =**3 B****Exchange2:**BTC/EUR**= 8,000.**Daily volume = 1**B**

What is the VWAMPP?

Since the first pair is in USD, and the second is in EUR, we should first convert both the price and the volume of **Exchange2** from EUR to USD, before calculating the volume average price.

Suppose EUR/USD is 1.2, i.e. each EUR is 1.2 USD. Then we can write:

**Exchange1:**BTC/USD**= 10,000.**Daily volume =**3****B****Exchange2:**BTC/EUR**= 8,000*1.2.**Daily volume =**1*1.2 B**

Therefore **VWAMPP** for BTC is $9,886.71**.**

Image from BitcoinCrazYness.com

Similarly, rather than reporting the price in USD, exchanges might report the price of one cryptocurrency relative to another cryptocurrency.

Suppose our imaginary exchanges report the following:

**Exchange1:**BTC/USD**= 10,000.**Daily volume =**3 B****Exchange2:**ETH/BTC**= 0.02.**Daily volume = 5**M**

What is **VWAMPP** in USD?

We need to find two things:

**1. BTC/USD on Exchange2**

**Exchange2** only reports the price of ETH to be 0.02 BTC. But what we need is the price of BTC in USD on **Exchange2.**

In order to get to BTC/USD, we can write:

This means if we knew ETH/USD, we can calculate BTC/USD as follows:

Assuming we keep a database of all cryptocurrency prices and in our latest calculations we had the **VWAMPP** of ETH/USD=204, we can write

**2. The Volume on Exchange2**

Since **Exchange2** is reporting ETH/BTC, the reported 1 B volume unit is in ETH. In order to calculate the volume in USD, again we should use the latest **VWAMPP** for ETH/USD from our last calculations. Assuming this value is 204, the volume on Exchange2 would be 5 M * 204 ≈ 1 B

Now, we can rewrite our original data as:

**Exchange1:**BTC/USD**= 10,000.**Daily volume =**3 B****Exchange2:**BTC/USD**= 10,200.**Daily volume =**1 B**

Therefore, the new **VWAMPP** for BTC/USD is:

Image from wikipedia.com

For one reason or another the price of a cryptocurrency on one exchange might be significantly different from the price on other exchanges. It is often desired to exclude that exchange in our calculations of **VWAMPP**.

An outlier price is:

A price that “lies outside” (is much smaller or larger than) most of the other prices

This can be done by first calculating the mean among all exchanges, and then exclude the prices that are significantly distant from the mean.

We can define an outlier to be more than 1 to 5 standard-deviation away from the mean.

I mentioned CoinMarketCap.com and coinGecko.com already calculate **VWAMPP** for all cryptocurrencies, so why would you want to calculate it yourself?

- Their API is not free or not guaranteed to remain free, specially for commercial use
- Sometimes there is some politics involved in selecting which market pairs and what exchanges should be accounted for in calculating
**VWAMPP** - You may want to customize and exclude specific exchanges or market pairs from your calculationYou may want to calculate
**VWAMPP**at a faster speed

For each cryptocurrency **C**, we need to have a snapshot of all the pairs involving **C** (either as a quote or as base), on all exchanges of interest in our database. Once we have this data, we can iterate through all of these pairs, convert them to **C/USD**, and then calculate the **VWAMPP** on them.

At the minimum, we need the following the following API’s:

Exchange API’s to get all the pair information

- A Forex price provider API to be able to convert to Forex values
- For getting crypto prices, I used ccxt which did a great job in unifying all APIs from various exchanges.

For Forex prices, I used the free API from openexchangerates.org.

There are several issues with **VWAMPP** that you may want to consider before using it:

- Because the price comes from various exchanges and gathering the information from all exchanges takes time, there is some delay associated between the real
**VWAMPP**and the**VWAMPP**that is calculated due to delay. - The volume on exchanges may not be accurate. In fact, it has been reported that some exchanges intentionally misrepresent the real volume.

Picture from unsplash.com

You can download a NodeJS implementation for calculating VWAMPP from here. This code can be run on a simple Linux-compatible machine and calculate the **VWAMPP** for each cryptocurrency.

Issues and pull requests are welcome!

Join Hacker Noon

Create your free account to unlock your custom reading experience.