How To Best Utilise The Look Into Bitcoin API
2024-12-24T16:41:51+0800

Here's a quick start tutorial on how you can best utilise one of Look Into Bitcoin's most requested and long awaited features, data via API! This method uses Google Sheets as a free and beginner friendly way to easily dip your toes into accessing and manipulating Bitcoin data directly. We're sure this will help you to begin exploring new avenues into creating bespoke and unique combinations of BTC metrics to improve and potentially even automate your investing and analysis. If you have any further questions or requests please don't hesitate to reach out! *Below is the code used in this video that you can copy and paste and follow along with. ################################################## ~READ ME~ Don't forget to add in your own API key. Replace all question marks (?) in the code with an angular bracket (Greater-than sign) by using Ctrl + F (or Command + F on mac) and pressing the 'Replace All' button within the code editor. YouTube is trying to alter the 2 URL's within the code to shortened re-directs, look out for the following snippets below: "Delete the space between 'https:' and ' //api'" - then make sure to delete the added space within the code editor so it simply reads 'https://api' at the start of each URL. ################################################## /** * Look Into Bitcoin API Example **/ const METRICS_TAB = 'Metrics'; const DATA_TAB = 'Data'; const key = 'YOUR_API_KEY'; # Replace YOUR_API_KEY with your actual API key const options = { muteHttpExceptions: true, method: "get", headers : { 'Authorization': 'Bearer ' + key } }; var ss = SpreadsheetApp.getActiveSpreadsheet(); function onOpen() { createCustomMenu(); } function createCustomMenu() { SpreadsheetApp.getUi().createMenu('⚙️ LIB Automations') .addItem('Get Metrics List', 'getMetrics') .addItem('Get Data For Selected Metric', 'getSelectedMetricData') .addSeparator() .addItem('Clear Metrics List', 'clearMetrics') .addItem('Clear Data', 'clearData') .addToUi(); } function getSelectedMetricData() { var sheet = ss.getActiveSheet(); var metricName = sheet.getActiveCell().getValue(); var metricData = Utilities.parseCsv(JSON.parse(getMetricData(metricName))); var dataTab = ss.getSheetByName(DATA_TAB); clearData(); dataTab.getRange(1,1,metricData.length,metricData[0].length).setValues(metricData); ss.toast(metricName + ' metric data returned from API call - ' + metricData.length + ' rows, ' + metricData[0].length + ' columns'); } function getMetrics() { var url = 'https: //api.lookintobitcoin.com/metrics'; # Delete the space between 'https:' and ' //api' try { var metricsList = JSON.parse(UrlFetchApp.fetch(url, options)); var metricsTab = ss.getSheetByName(METRICS_TAB); clearMetrics(); metricsTab.getRange(1,1,metricsList.length,1).setValues(metricsList.map(r =? [r])); ss.toast(metricsList.length + ' Metrics returned from API call'); } catch (e) { console.log('Failed with error: ', e.message); ss.toast('API Call failed with error: ' + e.message); return false; } } function getMetricData(metricName) { var url = 'https: //api.lookintobitcoin.com/metrics/' + metricName; # Delete the space between 'https:' and ' //api' try { return UrlFetchApp.fetch(url, options); } catch (e) { console.log('Failed with error: ', e.message); return false; } } function clearMetrics() { var metricsTab = ss.getSheetByName(METRICS_TAB); if (metricsTab.getLastRow() ? 0) { var metricsRange = metricsTab.getRange(1,1,metricsTab.getLastRow(),1); metricsRange.clear(); ss.toast('Metrics list cleared'); } else { ss.toast('List already cleared'); } } function clearData() { var dataTab = ss.getSheetByName(DATA_TAB); if (dataTab.getLastRow() ? 0) { var dataRange = dataTab.getRange(1,1,dataTab.getLastRow(),dataTab.getLastColumn()); dataRange.clear(); ss.toast('Data cleared'); } else { ss.toast('Data already cleared'); } } ################################################## Gain access to live charts, in-depth newsletters, indicator alerts, private TradingView scripts, and more - all for a fraction of the standard industry price: https://www.lookintobitcoin.com/subscribe/ Let us know what you think is most likely to happen in the coming weeks/months in the comments below! Follow us on Twitter: https://twitter.com/Lookintobtc Disclaimer: Nothing within this video should be misconstrued as financial advice. The information provided is for educational purposes only. You are responsible for your own investment decisions.