Live Updated Cryptocurrencies Investment Tracking with Google Sheets

in #bitcoin7 years ago (edited)

cois.png

Today I play around with Google Spreadsheet and some markets api to control my Cryptocurrencies investment, I get the prices from Poloniex, Bittrex, BTC-e and keep them updateing every minute into my Google Sheet

First step:

  • Create a Google Sheets and named it what you want
  • Go to Tools > Script editor...
  • Replace the code with below code

1. Update Poloniex prices

function updatePoloniex()
{
var response = UrlFetchApp.fetch("https://poloniex.com/public?command=returnTicker");
// TODO: set your sheet name here
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Coins");
var json = JSON.parse(response.getContentText());
var rateeth = json.BTC_ETH.last;
var rateetc = json.BTC_ETC.last;

// TODO: set column coordinates here in format (column, row); this is now set to A2 , B2
sheet.getRange(2, 1).setValue(rateeth);
sheet.getRange(2, 2).setValue(rateetc);

}

2. Update Bittrex prices (I not programmer so I do my way :) )

I create one more sheet to get the result from Bittrex API return and use Excel command to get the last price
a. Get the API result with this function

function updateBittrex()
{
var responseltc = UrlFetchApp.fetch("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc");
// TODO: set your sheet name from your new Sheet here
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("BTC");
// TODO: set column coordinates here in format (column, row); this is now set to A2
sheet.getRange(2, 1).setValue(responsltc);
}

b. Get the price
I get the LTC price with command below, replace BTC! with your Sheet name

=LEFT((LEFT(RIGHT(BTC!A2,LEN(BTC!A2)-(SEARCH("last",BTC!A2,"1")+5)),10)),SEARCH(",",(LEFT(RIGHT(BTC!A2,LEN(BTC!A2)-(SEARCH("last",BTC!A2,"1")+5)),14)),"1")-1)

3. Update BTC-e prices

The same way with Bittrex but replace

https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc

with

https://btc-e.com/api/2/btc_usd/ticker

4. Last step

This step will tell you how to update Sheets every 1 minute or manual update
This function will create a menu for you manual update Poloniex, BTC-e or update all

function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Update Poloniex rate",
functionName : "updatePoloniex"
}, {
name : "Update BTCe rate",
functionName : "updateBTCe"
}, {
name : "Update all",
functionName : "updateAll"
}];
sheet.addMenu("Scripts", entries);
};

If you want auto update price every one minute, from Script editor, select Edit then Current project's triggers, click *
No triggers set up. Click here to add one now.* to create new one
auto.png

You can see demo here: https://docs.google.com/spreadsheets/d/1hIVEOdUQzP5JsYtuzR-MNdapV3ByxyBw9HLlXJK4l2c/edit?usp=sharing

All code you can see here: https://anotepad.com/notes/n6d3kw

Sort:  

Great timing for this post.
I was going to look into doing something like that this weekend. I had no idea where to start.
Now I do. Thank you

You're wellcome :)

This is awesome, thank you!

Thanks for sharing! This is great!

Thanks for sharing. This is awesome!

Congratulations @thanhtamdc! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 3 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!