0

Code that I'm working with:

function BTC_1hour() {

  var url = '/api/v1/market/candles?type=1min&symbol=BTC-USDT&startAt=1566703297';
  
  var response = UrlFetchApp.fetch(url); // store API fetch in variable named response
  var JSONresponse = JSON.parse(response);
  var formatData = JSONresponse.data;

  for (var i = 0; i < formatData.length; i++)  
  { 
    for (var j =0; j < formatData[i].length; j++)
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName('1h');
    sheet.getRange(1,1,formatData.length, formatData[0].length).setValues(formatData);
    Logger.log(formatData[i][j])
    {
    
    }
  }
  
   
}

output into Google Sheets:

enter image description here

I'm trying to figure out how to no longer get the data that prints in columns F and G as well as format the date in column A from Epoch in seconds to human readable format.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Welchums
  • 19
  • 5
  • Welcome to [so]. Please only include content about the programming issue. It's not clear what you mean by 1d and what exactly you want to do with `formData`. Assumming that you want to add it to a sheet, use `sheet.getRange(1,1,formaData.length, formData[0].length).setValues(formData);`. If you need further help, please start by reading https://developers.google.com/apps-script/guides/sheets, if you still need help, please [edit] the question to add a [mcve]. – Rubén Dec 05 '22 at 20:26
  • Thank you for the quick response! you actually partially answered my question. I'm trying to understand how to manipulate the data from the API response and get it into the Sheet. You got me to the point of understanding how to get into the Sheet. I'm still trying to understand the formatting part. Allow me a few minutes to fix me original post to reflect relevant information. – Welchums Dec 05 '22 at 21:11
  • You can most likely remove the two `for` loops and just use the `.setValues()` call Rubén gave you to write the data. If you continue to need help, please `console.log(response)` and show what it looks like. Please ask only [one question per post](https://meta.stackexchange.com/a/222741). – doubleunary Dec 05 '22 at 21:53
  • Logger.log(response) `{"code":"200000","data":[["1670277600","16934.9","16915.6","16934.9","16915.6","0.63185068","10696.72504369528"],["1670270400","16976.5","16976.5","16976.5","16976.5","0.00000001","0.000169765"],["1670266800","17093.7","16929.722","17169.2","16929.722","0.07803704","1331.10527313872"],["1670263200","16999.8","16992.2","16999.8","16992.2","0.02786584","473.521106872"],["1670259600","17098.9","17227.5","17227.5","17098.9","0.0232647","399.999837734"],["1670256000","17128.4","17227.5","17227.5","17128.4","0.00460114","79.06300624"]]}` @doubleunary – Welchums Dec 05 '22 at 22:13
  • Rubén's solution should work fine. If not, please explain why not. Please [edit](https://stackoverflow.com/posts/74693236/edit) the question and put `response` there rather than in a comment. You can delete the comment. – doubleunary Dec 05 '22 at 22:28
  • 1) Please avoid including stuff like "Long time reader first time poster. Thanks in advance for any guidance brought to the post." as that is considered noise. Whatever that you want to share about yourself should not be included in posts, if you really want to share that you can put in your user profile. 2) Stack Snippet should be used on with HTML/CSS/JavaScript executable code, Google Apps Script is not executable as the services like UrlFetchService will throw and error when running the code in Stack Snippet. – Rubén Dec 05 '22 at 23:25
  • 3) Only include images when is it's necessary do show user interface elements that can't be described using text. To show data from a sheet, add it as text using markdown to format it as table. – Rubén Dec 05 '22 at 23:26

0 Answers0