ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.5k stars 7.47k forks source link

Finding total volume for a cryptocurrency #15848

Open everycoinprice opened 1 year ago

everycoinprice commented 1 year ago

So I am trying to calculate total volume of a cryptocurrency in the past 24 hours by adding all the baseVolume's from fetchTicker property of exchanges. Yet the total volume always comes up more than what popular ranking websites like coinmarketcap and coingecko post for the past 24 hours in volume

`

const ccxt = require("ccxt");
const binance = new ccxt.binance();
const symbol = "BTC";
let totalVolume = 0;
binance.fetchTickers().then(function(tickers) {
      const tickValues = Object.values(tickers);
      for(let  t = 0; t < tickers.length; t++) {
          if(tickers[t].symbol.split("/")[0] == symbol) {
              totalVolume  = totalVolume  + tickers[t].baseVolume;
         } // end of if
     } // end of for
   }); // end of then block

`

NOTE- This is just part of the code block (just for binance)- i repeat the same loop for all exchanges in ccxt.exchanges

Using this code i get totalVolume close to 80 million Bitcoins(BTC) traded in the past 24 hours, while coinmarketcap and coingecko report it close to 1 million

What i a missing?

Thanks for the help!

samgermain commented 1 year ago

could you share the coinmarketcap links that you're talking about? It's hard to know why it's different without anything to look into with regards to how they calculate total volume

I can point out that CCXT does not have support for every crypto exchange, so the actual number will be much higher than what you're calculating, I don't know how many exchanges coinmarketcap or coingecko list

everycoinprice commented 1 year ago

Coinmarketcap links-

Bitcoin's volume - https://coinmarketcap.com/currencies/bitcoin/ Screenshot 2022-12-05 at 1 37 48 PM

Volume methodology- https://support.coinmarketcap.com/hc/en-us/articles/360043395912-Volume-Market-Pair-Cryptoasset-Exchange-Aggregate-

everycoinprice commented 1 year ago

could you share the coinmarketcap links that you're talking about? It's hard to know why it's different without anything to look into with regards to how they calculate total volume

I can point out that CCXT does not have support for every crypto exchange, so the actual number will be much higher than what you're calculating, I don't know how many exchanges coinmarketcap or coingecko list

Yes true, that is why CCXT's total volume for a cryptocurrency should be lower than that calculated by coinmarketcap or coingecko. As CCXT might be supporting lower exchanges than them. But, in reality it is higher. While both coingecko and coinmarketcap have similar volume numbers

For bitcoin's volume 24H on 05/12/2022-> Coinmarketcap says volume is $21,443,030,192 while Coingecko says $22,598,703,601

while through CCXT would be at least 10 to 100 times higher than these

ttodua commented 1 year ago

The reason could be because ccxt includes not only spot markets, but some exchanges also load derivatives (swap, futures, ...) and thus, all tickers are including them too. I don't remind whether CMC/CG might be including only spot, check that. If so, then you might try smth like this:

         if(tickers[t].symbol.split("/")[0] == symbol) {
              const market = binance.market(symbol);
              if (market.type === 'spot') {
                  totalVolume  = totalVolume  + tickers[t].baseVolume;
             }

let us know the results.