Poloniex APi to Google Sheet CSV via Json -
i've got following script pulls keys poloniex json output, doesn't put actual data corresponds keys actual sheet...it puts keys titles @ top of sheet.
i'm new api's, , gas, , coding in general, i'm sure i'm missing incredibly obvious, i'd appreciate if point out what.
thanks in advance
function bitcoin_frompolo_tocsv() { //link script spreasdsheet using identifier found in spreadsheet url var ss = spreadsheetapp.openbyid('1cubxxxxxxxxxxxxjdqm'); var apipullsheet = ss.getsheetbyname("apipull"); // clear columns a,b,c,d apipullsheet.getrange('a2:d19999').clearcontent(); var url = "https://poloniex.com/public?command=returnchartdata¤cypair=btc_eth&start=1502344800&end=9999999999&period=14400"; //fetch pulls data url var responseapi = urlfetchapp.fetch(url); //parse json var parceddata = json.parse(responseapi.getcontenttext()); //break parsed data fields //define 'stats' array, , populate parced data pulled // loop iterates on each 'key' in 'parceddata' pushing data 'stats' var stats = []; stats.push(['date','high', 'low', 'open', 'close', 'volume', 'quotevolume', 'weightedaverage']); for(var key in parceddata.stats) { stats.push(parceddata.stats[key]); } statsrange = apipullsheet.getrange(1, 1, stats.length, 8); statsrange.setvalues(stats);
}
how following modification?
modification points :
json data url follows.
[ { "date": 1502352000, "high": 0.0899, "low": 0.08754124, "open": 0.08795499, "close": 0.08988724, "volume": 1390.47552953, "quotevolume": 15727.49124739, "weightedaverage": 0.08841051 }, . . ]
parceddata
doesn't have stats
key.
flow creating data :
- outer
foreach()
retrieves elementparceddata
. - inner
foreach()
retrieves each keystats[0]
, , retrieves data element ofparceddata
using key. - retrieved data imported
temp
1 dimensional array. - the
temp
importedstats
2 dimensional array. after this,temp
initialized.
the script reflected follows.
modified script :
function bitcoin_frompolo_tocsv() { var ss = spreadsheetapp.openbyid('1cubxxxxxxxxxxxxjdqm'); var apipullsheet = ss.getsheetbyname("apipull"); apipullsheet.getrange('a2:d19999').clearcontent(); var url = "https://poloniex.com/public?command=returnchartdata¤cypair=btc_eth&start=1502344800&end=9999999999&period=14400"; var responseapi = urlfetchapp.fetch(url); var parceddata = json.parse(responseapi.getcontenttext()); var stats = []; stats.push(['date','high', 'low', 'open', 'close', 'volume', 'quotevolume', 'weightedaverage']); parceddata.foreach(function(e1){ var temp = []; stats[0].foreach(function(e2){ temp.push(e1[e2]) }); stats.push(temp); }); statsrange = apipullsheet.getrange(1, 1, stats.length, 8); statsrange.setvalues(stats); }
result :
if misunderstand question, i'm sorry.
Comments
Post a Comment