Skip to content

Instantly share code, notes, and snippets.

@Hiutaky
Created January 11, 2024 12:24
Show Gist options
  • Save Hiutaky/4f12441c2929f6c3582ef61a7f6a2095 to your computer and use it in GitHub Desktop.
Save Hiutaky/4f12441c2929f6c3582ef61a7f6a2095 to your computer and use it in GitHub Desktop.
Google Sheet Crypto Price Fetch via KuCoin API
/**
Paste this script in Google Apps Script, will be available as function in Sheet by using =fetchPrice('SYMBOL') ex =fetchPrice('BTC')
If you want to auto-update the price every time your open the Sheet, in Apps Script click on Triggers and add a new trigger
Select the behavior you prefer and save.
*/
function fetchPrice(symbol = 'BTC') {
const res = UrlFetchApp.fetch(`https://api.kucoin.com/api/v1/market/stats?symbol=${symbol}-USDT`);
const obj = JSON.parse(res.getContentText());
return parseFloat(obj.data.buy)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment