Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: empoweoqwj on May 18, 2013, 07:12:10 AM



Title: getting live btc price into spreadsheet
Post by: empoweoqwj on May 18, 2013, 07:12:10 AM
Any easy way to get latest mtgox price into google spreadsheet cell?

tia


Title: Re: getting live btc price into spreadsheet
Post by: DaSheep on May 18, 2013, 10:08:02 AM
I build a function to do this.
Just go to Tools -> Script-Manager -> New
Name it something like MtGox.gs and insert the following code:
Code:
function getMtGoxPrice(s1, s2) {
  if (s1 == null){ s1 = "btc"; }
  if (s2 == null){ s2 = "usd"; }
  var symbol = s1+""+s2;
  symbol = symbol.toUpperCase();
  var url = "https://data.mtgox.com/api/2/"+symbol+"/money/ticker";
  var data = UrlFetchApp.fetch(url);
  var btcdata = data.getContentText();
  var object = JSON.parse(btcdata);
  var price = parseFloat(object["data"]["last"]["value"]);
  return price;
}

Now you can simply click into a spreadsheet cell and enter
Code:
=getMtGoxPrice()
or
Code:
=getMtGoxPrice("BTC", "EUR")