A NodeJs library for calculating Volume Weighted Average Market Pair Price (VWAMPP) 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 . Summary: 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: reports Exchange1 $10,000 reports Exchange2 $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 , but millions of trades on . So a better approach is to give more weight to the exchange that has more trades (or more traffic). Exchange1 Exchange2 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: reports with a daily volume of Exchange1 $10,000 $1 B reports with a daily volume of Exchange2 $12,000 $99 B Now the volume-weighted average price in USD would be: Volume Weighted Average PriceVolume-Weighted Average Market Pair Price (VWAMPP) Image from BitcoinCrazYness.com Exchanges usually report the price of a , for example: BTC/USD = 10,000 means each BTC is 10,000 USD. market pair The currency that is used as the reference is called the and the currency that is quoted in relation is called the In this example, BTC is the base, and USD is the quote. quote currency base currency. 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. and are among the leading websites to report a volume weighted average price for each coin which is calculated on hundreds of exchanges. CoinMarketCap.com coinGecko.com It’s a Bit More Complicated Image from BitcoinCrazYness.com The 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). VWAMPP Currency Pairs with Foreign Fiat Currencies Picture from unsplash.com Suppose our example two exchanges report the following: BTC/USD Daily volume = Exchange1: = 10,000. 3 B BTC/EUR Daily volume = 1 Exchange2: = 8,000. 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 from EUR to USD, before calculating the volume average price. Exchange2 Suppose EUR/USD is 1.2, i.e. each EUR is 1.2 USD. Then we can write: BTC/USD Daily volume = Exchange1: = 10,000. 3 B BTC/EUR Daily volume = Exchange2: = 8,000*1.2. 1*1.2 B Therefore for BTC is $9,886.71 VWAMPP . Currency Pairs with Other Cryptocurrencies 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: BTC/USD Daily volume = Exchange1: = 10,000. 3 B ETH/BTC Daily volume = 5 Exchange2: = 0.02. M What is in USD? VWAMPP We need to find two things: 1. BTC/USD on 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 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 of ETH/USD=204, we can write VWAMPP 2. The Volume on Exchange2 Since 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 for ETH/USD from our last calculations. Assuming this value is 204, the volume on Exchange2 would be 5 M * 204 ≈ 1 B Exchange2 VWAMPP Now, we can rewrite our original data as: BTC/USD Daily volume = Exchange1: = 10,000. 3 B BTC/USD Daily volume = Exchange2: = 10,200. 1 B Therefore, the new for BTC/USD is: VWAMPP Outliers 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 away from the mean. standard-deviation Why Calculating on Your Own? VWAMPP I mentioned and already calculate for all cryptocurrencies, so why would you want to calculate it yourself? CoinMarketCap.com coinGecko.com VWAMPP 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 at a faster speed VWAMPP How Should We Organize the Calculation? For each cryptocurrency , we need to have a snapshot of all the pairs involving (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 , and then calculate the on them. C C C/USD VWAMPP 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 which did a great job in unifying all APIs from various exchanges. ccxt For Forex prices, I used the free API from . openexchangerates.org Criticism VWAMPP There are several issues with that you may want to consider before using it: VWAMPP Because the price comes from various exchanges and gathering the information from all exchanges takes time, there is some delay associated between the real and the that is calculated due to delay. VWAMPP VWAMPP The volume on exchanges may not be accurate. In fact, it has been that some exchanges intentionally misrepresent the real volume. reported A NodeJS Implementation Picture from unsplash.com You can download a NodeJS implementation for calculating VWAMPP from . This code can be run on a simple Linux-compatible machine and calculate the for each cryptocurrency. here VWAMPP Issues and pull requests are welcome!