Skip to content

To match symbols and coins between coinmarketcap and cryptocompare

Notifications You must be signed in to change notification settings

slidenerd/Cryptocurrency-Mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cryptocurrency Mapper

Goals: To map symbols between coinmarketcap and cryptocompare

Problem Definition


Cryptocompare and Coinmarketcap offer an API where you can fetch prices and other relevant information.

  1. Coinmarketcap distinguishes each coin with a unique ID. For example BTC has the id bitcoin Two different coins Bytom and Bitmark have the same symbol BTM
  2. Cryptocompare distinguises each coin with a unique symbol. In cases such as Bytom and Bitmark they offer add an * at the end of the symbol
  3. For cryptocompare, Bitmark is BTM and Bytom is BTM*
  4. At the time of creating this repo, coinmarketcap does not offer OHLC data while cryptocompare does
  5. The usual strategy then employed by a trading algorithms developer would be to fetch the list of symbols from coinmarketcap while fetching OHLC, historical and other relevant data from cryptocompare

Solution

  1. Get the unique list of symbols from coinmarketcap
  2. BTM will appear only once in this list
  3. For each such symbol, find the symbol from cryptocompare after removing their differentiating * or any other such extra character
  4. BTM which stands for Bitmark on cryptocompare and BTM* which stands for Bytom on cryptocompare will be mapped from the symbol BTM on coinmarketcap in the following structure
  5. BTM : [BTM, BTM*]
  6. In the case of coins such as IOTA which is represented by MIOTA on coinmarketcap and IOT on cryptocompare, we map the names
  7. function mapCMCToCPC(coinmarketcap, cryptocompare){ //Convert an object with keys into an array of objects cryptocompare = Object.keys(cryptocompare['Data']).map(i=>cryptocompare['Data'][i])

    let ignoreSpaceRegex = /\s/g, nonAlphaNumericRegex = /\W+/g
    let map = {}, symbol1, name1, symbol2, name2, reduced
    
    //Loop through every item in coinmarketcap
    //Note that symbols such as BTM, KNC will be repeated multiple times
    for(let i = coinmarketcap.length - 1; i >= 0; i--){
    
    	//Get the symbol of the current coin on coinmarketcap
    	symbol1 = coinmarketcap[i].symbol
    
    	//Get the name of the current coin on coinmarketcap
    	//Remove all spaces from the name
    	//Trim the name on both sides
    	//Convert the name to lower case
    	name1 = coinmarketcap[i].name.trim().replace(ignoreSpaceRegex, "").toLowerCase()
    
    	//Loop through every item on cryptocompare
    	for(let j = cryptocompare.length - 1;  j >= 0; j--){
    
    		//Get the symbol of the current coin on cryptocompare
    		symbol2 = cryptocompare[j].Symbol
    
    		//Cryptocompare has unique symbols at all times
    		//A coin such as KNC appears twice on coinmarketcap as King N Coin and Kyber
    		//Both coins have the same symbol on coinmarketcap
    		//The same coins however are stored with a unique symbol on cryptocompare
    		//KNC, KNC*, KNC** represent Kyber, Khancoin and King N Coin on cryptocompare
    		//Coins such as B@ represent BankCoin
    		//Take a symbol on cryptocompare
    		//Remove special characters such as * or @
    		//Check if the reduced symbol on cryptocompare matches with some symbol on coinmarketcap
    		//KNC, KNC*, KNC** will be reduced to KNC from cryptocompare
    		//These 3 symbols will match with KNC from coinmarketcap
    		//If we find a match either via reduced symbols or via names
    		//Set the key as the coinmarketcap symbol
    		//Set the values as a unique array of cryptocompare symbols prior to reduction
    		//KNC on coinmarketcap => KNC, KNC*, KNC** on cryptocompare after mapping
    
    		reduced = symbol2.replace(nonAlphaNumericRegex,"")
    		name2 = cryptocompare[j].CoinName.trim().replace(ignoreSpaceRegex, "").toLowerCase()	
    		if(symbol1 === reduced || name1 === name2){
    
    			//Check if the map has the symbol from coinmarketcap
    			if(!map[symbol1]){
    				map[symbol1] = []
    			}
    
    			//Push the cryptocompare key only if it was not pushed previously
    			if(map[symbol1].indexOf(symbol2) < 0){
    				map[symbol1].push(symbol2)	
    			}
    		}
    	}
    }
    return map
    

    }

Todos

  1. The mapping via names is non fuzzy in nature to keep performance levels optimal and as such doesn't include a few coins
  2. Would love to hear your thoughts on how matching can be improved

Where is this used?

I use this on Zupcoin

Zupcoin is bot that can convert from any crypto/fiat to any crypto/fiat

About

To match symbols and coins between coinmarketcap and cryptocompare

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published