Last active
August 22, 2017 15:08
-
-
Save josephros/f89cbd8c419554c222017cc9325d5972 to your computer and use it in GitHub Desktop.
Get basic ticker info from a token contracts name/symbol using the coinmarketcap.com API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getTokenPriceData (symbol, name) { | |
symbol = symbol.toLowerCase(); | |
name = name.toLowerCase(); | |
let tickers = await request('https://api.coinmarketcap.com/v1/ticker/', { | |
json: true | |
}); | |
return _.find(tickers, function (ticker) { | |
var tickerSymbol = ticker.symbol.toLowerCase(); | |
var tickerName = ticker.name.toLowerCase(); | |
if (symbol) { | |
if (symbol == tickerSymbol || symbol === tickerName) return true; | |
} | |
if (name) { | |
if (name === tickerName || name === tickerSymbol) return true; | |
} | |
return false; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment