Created
November 10, 2020 06:30
-
-
Save Roms1383/23a195fd77c183a6eb4d15e262f180ac to your computer and use it in GitHub Desktop.
Google sheet : quickly replace CRYPTOFINANCE
This file contains hidden or 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
// use as before: e.g. CRYPTOFINANCE("XLM/USD") | |
// there's no way to use CRYPTOFINANCE("BINANCE:XLM/USD") without a paid account, so I didn't implement it | |
const API_KEY = 'YOUR_COINMARKETCAP_API_KEY' // do not forget to replace it with your own API key ;) | |
const domain = 'https://pro-api.coinmarketcap.com'; | |
const ticker = 'v1/cryptocurrency/quotes/latest'; | |
const options = { | |
method: 'GET', | |
headers: { | |
'X-CMC_PRO_API_KEY': API_KEY, | |
} | |
}; | |
function CRYPTOFINANCE (PAIR) { | |
const [BASE, QUOTE] = PAIR.split('/') | |
const uri = domain + '/' + ticker | |
const symbol = 'symbol=' + BASE | |
const convert = 'convert=' + QUOTE | |
const url = uri + '?' + symbol + '&' + convert | |
const response = UrlFetchApp.fetch(url, options) | |
const json = JSON.parse(response) | |
const price = json.data[BASE].quote[QUOTE].price | |
return price | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment