LesterCovax / crypto-sheets

Google Sheets script editor code for managing a cryptocurrency tracking spreadsheet
https://www.reddit.com/r/cryptosheets
GNU General Public License v3.0
482 stars 67 forks source link

Ability to convert BTC prices to ETH prices #37

Closed ddarbs closed 6 years ago

ddarbs commented 6 years ago

request from: https://www.reddit.com/r/cryptosheets/comments/7t3djc/possible_to_add_price_eth_to_cryptosheets/

this is what I have so far, use it with '=getEthereumConversion(E2)' and copy paste down

function getEthereumConversion(input) {

  //Pause to not trigger API limit
  Utilities.sleep(300);  

  var url = 'https://api.coinmarketcap.com/v1/ticker/ethereum/'
  var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
  var json = response.getContentText();
  var data = JSON.parse(json);
  var usd = parseFloat(data[0]['price_usd']); 
  var usdtoeth = (input/usd);

  return usdtoeth; 

}
robtylerphillips commented 6 years ago

Hey iKrazy, thanks for the help. My code is giving me the correct ETH conversion but it's off by a factor of 100. As in the decimal is 2 places to the left. Is it me or the code?

ddarbs commented 6 years ago

@robtylerphillips my fault, I think I fixed it

robtylerphillips commented 6 years ago

@iKrazy, I just copied and pasted that code in there and it moved the decimal over to the left two more places (now 4 places to the left from where it should). I just pasted this at the end overwriting your former code.

Sorry I am trudging through learning java...

ddarbs commented 6 years ago

@robtylerphillips yeah you will need to delete the old code, and make sure you update the formula in the sheet to use E2. I will get you a pastebin of my script tomorrow, so you can copy paste the whole thing.

ddarbs commented 6 years ago

@robtylerphillips https://pastebin.com/raw/f3FL9sps if you want to try copy pasting the one I am working with. Be sure to copy your current coin list before you delete it.

ddarbs commented 6 years ago

https://www.reddit.com/r/cryptosheets/comments/7t3djc/possible_to_add_price_eth_to_cryptosheets/dtm8vz6/

zomskii showed you can do the ETH conversion with no new functions by changing

var targetCurrency = 'usd' to var targetCurrency = 'eth'

robtylerphillips commented 6 years ago

I'm getting an error for some reason now.

2/3/18 5:52 PM | getData | Cannot call SpreadsheetApp.getUi() from this context. (line 64, file "Code") | time-based | 2/3/18 5:52 PM

LesterCovax commented 6 years ago

Try just running the function that's pulling the data. Are you getting this when running it manually or through triggers? If you don't have the page open you can get this error.

Here are the triggers I use:

image