Skip to content

Commit

Permalink
Documented code, ReadMe is next
Browse files Browse the repository at this point in the history
  • Loading branch information
LesterCovax committed Dec 26, 2017
1 parent b7a8395 commit 970791a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 15 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@ Google Sheets script editor code for managing a cryptocurrency tracking spreadsh

This is a template for creating your own spreadsheet to track your cryptocurrency balances and current prices. It assumes the use of Google Sheets and the built in script editor (Tools > Script editor...).

1. Click "Tools > Script editor..." on the menu bar
2. Select all of the text in the right pane and delete it (unless you have already written your own functions)
3. Paste the contents of scripteditor.js into the pane on the right
4. Add in as many currencies that you want to track

There are comments in the code, and I'll add better instructions here in the future.

More instructions to follow.

## To Do

1. Add detailed instructions for configuring your own Google Sheets tracker
1. Add detailed instructions for configuring your own Google Sheets crypto tracker
2. Templatize the script to pull in lists of cryptos to track, and account balances to track
3. Historical data

## Donations

They are appreciated but not expected

XRB - xrb_3ix8dfgn7hkz3choqi1qr6jgopoodh1jr1giwixzqaohks7d1f98dau45c11
ETH - 0x7E9DDB5343a583705Ed9ADE065C0595EFB55D681
VTC - Vo8EXgAtxCVUtMaTQECuzLD2tZU1HqLbhT

## License

This project is licensed under the GNU General Public License v3.0
68 changes: 54 additions & 14 deletions scripteditor.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,73 @@
function getData() {
var queryString = Math.random();
var ss = SpreadsheetApp.getActiveSpreadsheet();

//
//IMPORTANT: Create a sheet called 'Rates'. This is where the values will be written
//
var ssRates = ss.getSheetByName('Rates');

//Grabbing values that are on CoinMarketCap but not in the API

var ZYX = '=IMPORTXML("https://coinmarketcap.com/currencies/zyx?' + queryString + '","//span[@id=\'quote_price\']")';
var YXW = '=IMPORTXML("https://coinmarketcap.com/currencies/yxw?' + queryString + '","//span[@id=\'quote_price\']")';
var XWV = '=IMPORTXML("https://coinmarketcap.com/currencies/xwv?' + queryString + '","//span[@id=\'quote_price\']")';

//Grabbing values from CoinMarketCapAPI

//Change the variable name to match the trading symbol
//Change the name in the quotes (e.g. are-bees-carebears) to match the 'id' field from https://api.coinmarketcap.com/v1/ticker/
//Copy/paste to add more lines as needed

var ABC = getRate('are-bees-carebears');
var BCD = getRate('berry-cool-doge');
var CDE = getRate('coin-dank-enigma');

//Grabbing values that are on CoinMarketCap but not in the API
//Change the variable name to match the trading symbol
//Go to the CoinMarketCap page for the currency (e.g. https://coinmarketcap.com/currencies/zeeyx)
//Change the name in quotes (e.g. zeeyx) to match the end of the URL for your currency
//Copy/paste to add more lines as needed

var ZYX = getWebRate('zeeyx');
var YXW = getWebRate('yaaxw');
var XWV = getWebRate('xoowv');

//Setting values in a sheet called 'Rates' (defined at the top)
//Change the values in getRange() to match the cells in the 'Rates' sheet you want to userAgent
//Use the coin symbols from above in setValue()

ssRates.getRange('B1').setValue(ABC);
ssRates.getRange('B2').setValue(BCD);
ssRates.getRange('B3').setValue(CDE);

ssRates.getRange('B4').setValue(ZYX);
ssRates.getRange('B5').setValue(YXW);
ssRates.getRange('B6').setValue(XWV);

//VTC balances using function below
//VTC wallet balances
//Add more as needed with different variable names

var VtcMining = getVtcBalance("yourAddressHere");
var VtcWallet = getVtcBalance("yourAddressHere");

//Putting this value in spreadsheet
//Change the value in getRange() to match the cell in spreadsheet
//Change the value in setValue() to match the variable above

ssRates.getRange('E3').setValue(VtcMining);
ssRates.getRange('E3').setValue(VtcWallet);

//ETH Balances using function below
//Ethereum Wallet Balances
//Create an account on Etherscan.io
//Create an API key at https://etherscan.io/myapikey
//Put your API key in below, replacing yourEtherscanApiKey
//Add Ethereum address, replacing yourEthAddress

var EthApiKey = "yourEtherscanApiKey";
var EthMew = getEthBalance(EthApiKey,"yourEthAddress");
var EthWallet = getEthBalance(EthApiKey,"yourEthAddress");

//Putting this value in spreadsheet
//Change the value in setValue() to match the variable above

ssRates.getRange('E1').setValue(EthBalance);
ssRates.getRange('E1').setValue(EthWallet);
}

//
// DON'T TOUCH ANYTHING BELOW
// IT MAKES THE MAGIC HAPPEN
//

function getEthBalance(ethApiKey,ethAddress) {

var obj = JSON.parse (UrlFetchApp.fetch("https://api.etherscan.io/api?module=account&action=balance&address="+ethAddress+"&tag=latest&apikey="+ethApiKey));
Expand All @@ -63,3 +92,14 @@ function getRate(currencyId) {

return parseFloat(data[0]['price_usd']);
}

function getWebRate(currencyId) {

//Example Output:
// '=IMPORTXML("https://coinmarketcap.com/currencies/zeeyx?3908288283","//span[@id=\'quote_price\']")';

var coinScrape1 = '=IMPORTXML("https://coinmarketcap.com/currencies/';
var coinScrape2 = '","//span[@id=\'quote_price\']")';

return coinScrape1 + currencyId + '?' + queryString + coinScrape2;
}

0 comments on commit 970791a

Please sign in to comment.