So my partner and I have been documenting everything we can with our ever-evolving mining operation. One of the things we do is keep track of our wallet transactions and balance in a Google Spreadsheet. We're looking at how to automate the process, but that's another post all-together. One problem we ran into is how to pull the latest price of LTC/USD from BTC-E and calculate our wallet worth. So I did some searching and couldn't really come up with anything specific to Google Spreadsheets. There could be something like this out there but I couldn't find it. So I'm going to post it here if anyone is looking for this.
So to get this running, you need to create a new spreadsheet, or use an existing spreadsheet in Google Apps. Click on "Tools" in the menu bar, then "Script Editor". Once it opens, rename the script, and paste in the following code:
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "Refresh", functionName: "onOpen"} ];
ss.addMenu("BTCE Ticker", menuEntries);
var range = ss.getSheets()[0].getRange("A1:A1");
var url = 'https://btc-e.com/api/2/ltc_usd/ticker';
var content = UrlFetchApp.fetch(url).getContentText();
SpreadsheetApp.setActiveRange(range);
SpreadsheetApp.getActiveRange().setValue(content);
};
Save the script and press the play button. It will pull the API info set with the "var url" variable, so set it to whatever API ticker you want (LTC/USD, LTC/BTC, etc...). The "var range" variable sets the active cell with the "getRange("XX:XX") option. I'm not a pro at scripting, so this was the first quick and dirty way to set the active cell that I could find. The "menuEntries" variable adds a menu at the top of the spreadsheet with a "Refresh" option listed under it. The script is called when the spreadsheet is first opened, and whenever you hit the "Refresh" menu item.
From here you can use functions to separate out the data, but at least getting the data into the spreadsheet is done. I may or may not post the functions to separate the data depending on when I get time to do so at work. I'll reserve the first reply on this post for that info if I get the chance.
Let me know if this helped you out. Happy hashing!