Simple Method To Create Better Bitcoin Metrics

Bitcoin Magazine Pro
761 views 2024/08/27

On-chain Bitcoin metrics are some of the most reliable and effective data points for improving your BTC investing!

But with some simple tweaks, you may actually be able to make your favorite charts even better, and even automate your strategies… Here’s how to use the new and improved Bitcoin Magazine Pro 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.

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 ‘@’ symbols 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.

#

/**
* Bitcoin Magazine Pro API
**/

const METRICS_SHEET = ‘Metrics’;
const DATA_SHEET = ‘Data’;
const API_URL = ‘https: //api.bitcoinmagazinepro.com/’; # Delete the space between ‘https:’ and ‘ //api’
const KEY = ‘YOUR_API_KEY’; # Replace YOUR_API_KEY with your actual API key
const OPTIONS = {
muteHttpExceptions: true,
method: “get”,
headers : {
‘Authorization’: ‘Bearer ‘ + KEY
}
};

const ss = SpreadsheetApp.getActiveSpreadsheet();

function onOpen() {
createCustomMenu();
}

function createCustomMenu() {
SpreadsheetApp.getUi().createMenu(‘⚙️ Automations’)
.addItem(‘Get Daily Metrics List’, ‘getMetrics’)
.addItem(‘Get Hourly Metrics List’, ‘getHourlyMetrics’)
.addSeparator()
.addItem(‘Get Data For Selected Metric’, ‘getSelectedMetricData’)
.addToUi();
}

function getHourlyMetrics() {
getMetrics(‘hourly’);
}

function getMetrics(interval) {
let url = API_URL + ‘metrics’;
intervalParam = ”;
if (interval == ‘hourly’) {
intervalParam = ‘?’ + interval + ‘=1’;
url = url + intervalParam;
}
try {
let metricsList = JSON.parse(UrlFetchApp.fetch(url, OPTIONS));
createSheet(METRICS_SHEET,0);
let metricsSheet = ss.getSheetByName(METRICS_SHEET).activate();
clearSheet(METRICS_SHEET);
metricsSheet.getRange(1,1,metricsList.length,1).setValues(metricsList.map(r =@ [r + intervalParam]));
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 getSelectedMetricData() {
let sheet = ss.getActiveSheet();
let metricName = sheet.getActiveCell().getValue();
if (metricName !==”) {
let metricData = Utilities.parseCsv(JSON.parse(getMetricData(metricName)));
if (metricData.length @1) {
createSheet(DATA_SHEET,1);
let dataSheet = ss.getSheetByName(DATA_SHEET).activate();
clearSheet(DATA_SHEET);
dataSheet.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’);
}
else {
ss.toast(‘Unable to return metric data’);
}
}
else {
ss.toast(‘No metric selected’);
}
}

function getMetricData(metricName) {
let url = API_URL + ‘metrics/’ + metricName;
try {
return UrlFetchApp.fetch(url, OPTIONS);
}
catch (e) {
console.log(‘Failed with error: ‘, e.message);
ss.toast(‘API Call failed with error: ‘ + e.message);
return false;
}
}

function createSheet(sheetName, position) {
let sheet = ss.getSheetByName(sheetName);
if (!sheet) {
ss.insertSheet(sheetName,position);
}
}

function clearSheet(sheetName) {
let sheet = ss.getSheetByName(sheetName);
if (sheet.getLastRow() @ 0) {
let sheetRange = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn());
sheetRange.clear();
}
}

#

Stay ahead of the trend. Go PRO with Bitcoin Magazine Pro!

Gain access to Bitcoin live charts, in-depth newsletters, indicator alerts, private TradingView scripts, and more – all for a fraction of the standard industry price:
https://www.bitcoinmagazinepro.com/

Follow us at:
X: https://x.com/BitcoinMagPro
LinkedIn: https://www.linkedin.com/showcase/bitcoin-magazine-pro

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.

Bitcoin #BitcoinPrice #BitcoinNews




Comments (0)

    Greed and Fear Index

    Note: The data is for reference only.

    index illustration

    Extreme Greed

    84