Skip to content

Instantly share code, notes, and snippets.

@Bruttagente
Last active September 8, 2017 05:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bruttagente/bbdbbb5da840a7f22fb2620c46cfd56a to your computer and use it in GitHub Desktop.
Save Bruttagente/bbdbbb5da840a7f22fb2620c46cfd56a to your computer and use it in GitHub Desktop.
Google Script to fetch the Poloniex balance and fill a Sheet with the retrieved data
//This is a simple Google Script to fetch the personal balance from the Poloniex website and fill a Google Sheet.
//You had to insert you API key and secret where indicated, and use your own Google Sheet address and sheet name.
//
//If you find this script useful, you can send me a tip on my bitcoin address: 17wzVMssHULq3LcJaESBkiB2cu2L9yCYn1
//
function sendHttpPost() {
//if you get an error about the nonce number, change it with a greater one as suggested by the debug
var nonce = 1495932972127042 + new Date().getTime();
var cb = "command=returnCompleteBalances&account=all&nonce="+nonce
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512,
cb,
"your_API_SECRET_here"); //insert your API Secret between the ""
var headers = {
"Key" : "your_API_KEY_here", //insert your API Key between the ""
"Sign" : signature
};
var options = {
"method" : "POST",
"headers": headers,
"payload": cb
};
var response = UrlFetchApp.fetch("https://poloniex.com/tradingApi", options);
var ss = SpreadsheetApp.openById("GoogleSheet_Address"); //add the address of your Google Sheet here
var data = ss.getSheetByName("Sheet_Name"); //and the sheet name here
var json = JSON.parse(response.getContentText());
//BTC
var BTC = [];
BTC.push(['BTC']);
for(var key in json.BTC)
{
BTC[0].push(json.BTC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(2, 1, BTC.length, 4);
askRange.setValues(BTC);
//AMP
var AMP = [];
AMP.push(['AMP']);
for(var key in json.AMP)
{
AMP[0].push(json.AMP[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(3, 1, AMP.length, 4);
askRange.setValues(AMP);
//ARDR
var ARDR = [];
ARDR.push(['ARDR']);
for(var key in json.ARDR)
{
ARDR[0].push(json.ARDR[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(4, 1, ARDR.length, 4);
askRange.setValues(ARDR);
//BCN
var BCN = [];
BCN.push(['BCN']);
for(var key in json.BCN)
{
BCN[0].push(json.BCN[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(5, 1, BCN.length, 4);
askRange.setValues(BCN);
//BCY
var BCY = [];
BCY.push(['BCY']);
for(var key in json.BCY)
{
BCY[0].push(json.BCY[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(6, 1, BCY.length, 4);
askRange.setValues(BCY);
//BELA
var BELA = [];
BELA.push(['BELA']);
for(var key in json.BELA)
{
BELA[0].push(json.BELA[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(7, 1, BELA.length, 4);
askRange.setValues(BELA);
//BLK
var BLK = [];
BLK.push(['BLK']);
for(var key in json.BLK)
{
BLK[0].push(json.BLK[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(8, 1, BLK.length, 4);
askRange.setValues(BLK);
//BTCD
var BTCD = [];
BTCD.push(['BTCD']);
for(var key in json.BTCD)
{
BTCD[0].push(json.BTCD[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(9, 1, BTCD.length, 4);
askRange.setValues(BTCD);
//BTM
var BTM = [];
BTM.push(['BTM']);
for(var key in json.BTM)
{
BTM[0].push(json.BTM[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(10, 1, BTM.length, 4);
askRange.setValues(BTM);
//BTS
var BTS = [];
BTS.push(['BTS']);
for(var key in json.BTS)
{
BTS[0].push(json.BTS[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(11, 1, BTS.length, 4);
askRange.setValues(BTS);
//BURST
var BURST = [];
BURST.push(['BURST']);
for(var key in json.BURST)
{
BURST[0].push(json.BURST[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(12, 1, BURST.length, 4);
askRange.setValues(BURST);
//CLAM
var CLAM = [];
CLAM.push(['CLAM']);
for(var key in json.CLAM)
{
CLAM[0].push(json.CLAM[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(13, 1, CLAM.length, 4);
askRange.setValues(CLAM);
//DASH
var DASH = [];
DASH.push(['DASH']);
for(var key in json.DASH)
{
DASH[0].push(json.DASH[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(14, 1, DASH.length, 4);
askRange.setValues(DASH);
//DCR
var DCR = [];
DCR.push(['DCR']);
for(var key in json.DCR)
{
DCR[0].push(json.DCR[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(15, 1, DCR.length, 4);
askRange.setValues(DCR);
//DGB
var DGB = [];
DGB.push(['DGB']);
for(var key in json.DGB)
{
DGB[0].push(json.DGB[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(16, 1, DGB.length, 4);
askRange.setValues(DGB);
//DOGE
var DOGE = [];
DOGE.push(['DOGE']);
for(var key in json.DOGE)
{
DOGE[0].push(json.DOGE[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(17, 1, DOGE.length, 4);
askRange.setValues(DOGE);
//EMC2
var EMC2 = [];
EMC2.push(['EMC2']);
for(var key in json.EMC2)
{
EMC2[0].push(json.EMC2[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(18, 1, EMC2.length, 4);
askRange.setValues(EMC2);
//ETC
var ETC = [];
ETC.push(['ETC']);
for(var key in json.ETC)
{
ETC[0].push(json.ETC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(19, 1, ETC.length, 4);
askRange.setValues(ETC);
//ETH
var ETH = [];
ETH.push(['ETH']);
for(var key in json.ETH)
{
ETH[0].push(json.ETH[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(20, 1, ETH.length, 4);
askRange.setValues(ETH);
//EXP
var EXP = [];
EXP.push(['EXP']);
for(var key in json.EXP)
{
EXP[0].push(json.EXP[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(21, 1, EXP.length, 4);
askRange.setValues(EXP);
//FCT
var FCT = [];
FCT.push(['FCT']);
for(var key in json.FCT)
{
FCT[0].push(json.FCT[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(22, 1, FCT.length, 4);
askRange.setValues(FCT);
//FLDC
var FLDC = [];
FLDC.push(['FLDC']);
for(var key in json.FLDC)
{
FLDC[0].push(json.FLDC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(23, 1, FLDC.length, 4);
askRange.setValues(FLDC);
//FLO
var FLO = [];
FLO.push(['FLO']);
for(var key in json.FLO)
{
FLO[0].push(json.FLO[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(24, 1, FLO.length, 4);
askRange.setValues(FLO);
//GAME
var GAME = [];
GAME.push(['GAME']);
for(var key in json.GAME)
{
GAME[0].push(json.GAME[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(25, 1, GAME.length, 4);
askRange.setValues(GAME);
//GNO
var GNO = [];
GNO.push(['GNO']);
for(var key in json.GNO)
{
GNO[0].push(json.GNO[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(26, 1, GNO.length, 4);
askRange.setValues(GNO);
//GNT
var GNT = [];
GNT.push(['GNT']);
for(var key in json.GNT)
{
GNT[0].push(json.GNT[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(27, 1, GNT.length, 4);
askRange.setValues(GNT);
//GRC
var GRC = [];
GRC.push(['GRC']);
for(var key in json.GRC)
{
GRC[0].push(json.GRC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(28, 1, GRC.length, 4);
askRange.setValues(GRC);
//HUC
var HUC = [];
HUC.push(['HUC']);
for(var key in json.HUC)
{
HUC[0].push(json.HUC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(29, 1, HUC.length, 4);
askRange.setValues(HUC);
//LBC
var LBC = [];
LBC.push(['LBC']);
for(var key in json.LBC)
{
LBC[0].push(json.LBC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(30, 1, LBC.length, 4);
askRange.setValues(LBC);
//LSK
var LSK = [];
LSK.push(['LSK']);
for(var key in json.LSK)
{
LSK[0].push(json.LSK[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(31, 1, LSK.length, 4);
askRange.setValues(LSK);
//LTC
var LTC = [];
LTC.push(['LTC']);
for(var key in json.LTC)
{
LTC[0].push(json.LTC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(32, 1, LTC.length, 4);
askRange.setValues(LTC);
//MAID
var MAID = [];
MAID.push(['MAID']);
for(var key in json.MAID)
{
MAID[0].push(json.MAID[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(33, 1, MAID.length, 4);
askRange.setValues(MAID);
//NAUT
var NAUT = [];
NAUT.push(['NAUT']);
for(var key in json.NAUT)
{
NAUT[0].push(json.NAUT[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(34, 1, NAUT.length, 4);
askRange.setValues(NAUT);
//NAV
var NAV = [];
NAV.push(['NAV']);
for(var key in json.NAV)
{
NAV[0].push(json.NAV[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(35, 1, NAV.length, 4);
askRange.setValues(NAV);
//NEOS
var NEOS = [];
NEOS.push(['NEOS']);
for(var key in json.NEOS)
{
NEOS[0].push(json.NEOS[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(36, 1, NEOS.length, 4);
askRange.setValues(NEOS);
//NMC
var NMC = [];
NMC.push(['NMC']);
for(var key in json.NMC)
{
NMC[0].push(json.NMC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(37, 1, NMC.length, 4);
askRange.setValues(NMC);
//NOTE
var NOTE = [];
NOTE.push(['NOTE']);
for(var key in json.NOTE)
{
NOTE[0].push(json.NOTE[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(38, 1, NOTE.length, 4);
askRange.setValues(NOTE);
//NXC
var NXC = [];
NXC.push(['NXC']);
for(var key in json.NXC)
{
NXC[0].push(json.NXC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(39, 1, NXC.length, 4);
askRange.setValues(NXC);
//NXT
var NXT = [];
NXT.push(['NXT']);
for(var key in json.NXT)
{
NXT[0].push(json.NXT[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(40, 1, NXT.length, 4);
askRange.setValues(NXT);
//OMNI
var OMNI = [];
OMNI.push(['OMNI']);
for(var key in json.OMNI)
{
OMNI[0].push(json.OMNI[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(41, 1, OMNI.length, 4);
askRange.setValues(OMNI);
//PASC
var PASC = [];
PASC.push(['PASC']);
for(var key in json.PASC)
{
PASC[0].push(json.PASC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(42, 1, PASC.length, 4);
askRange.setValues(PASC);
//PINK
var PINK = [];
PINK.push(['PINK']);
for(var key in json.PINK)
{
PINK[0].push(json.PINK[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(43, 1, PINK.length, 4);
askRange.setValues(PINK);
//POT
var POT = [];
POT.push(['POT']);
for(var key in json.POT)
{
POT[0].push(json.POT[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(44, 1, POT.length, 4);
askRange.setValues(POT);
//PPC
var PPC = [];
PPC.push(['PPC']);
for(var key in json.PPC)
{
PPC[0].push(json.PPC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(45, 1, PPC.length, 4);
askRange.setValues(PPC);
//RADS
var RADS = [];
RADS.push(['RADS']);
for(var key in json.RADS)
{
RADS[0].push(json.RADS[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(46, 1, RADS.length, 4);
askRange.setValues(RADS);
//REP
var REP = [];
REP.push(['REP']);
for(var key in json.REP)
{
REP[0].push(json.REP[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(47, 1, REP.length, 4);
askRange.setValues(REP);
//RIC
var RIC = [];
RIC.push(['RIC']);
for(var key in json.RIC)
{
RIC[0].push(json.RIC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(48, 1, RIC.length, 4);
askRange.setValues(RIC);
//SBD
var SBD = [];
SBD.push(['SBD']);
for(var key in json.SBD)
{
SBD[0].push(json.SBD[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(49, 1, SBD.length, 4);
askRange.setValues(SBD);
//SC
var SC = [];
SC.push(['SC']);
for(var key in json.SC)
{
SC[0].push(json.SC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(50, 1, SC.length, 4);
askRange.setValues(SC);
//SJCX
var SJCX = [];
SJCX.push(['SJCX']);
for(var key in json.SJCX)
{
SJCX[0].push(json.SJCX[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(51, 1, SJCX.length, 4);
askRange.setValues(SJCX);
//STEEM
var STEEM = [];
STEEM.push(['STEEM']);
for(var key in json.STEEM)
{
STEEM[0].push(json.STEEM[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(52, 1, STEEM.length, 4);
askRange.setValues(STEEM);
//STR
var STR = [];
STR.push(['STR']);
for(var key in json.STR)
{
STR[0].push(json.STR[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(53, 1, STR.length, 4);
askRange.setValues(STR);
//STRAT
var STRAT = [];
STRAT.push(['STRAT']);
for(var key in json.STRAT)
{
STRAT[0].push(json.STRAT[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(54, 1, STRAT.length, 4);
askRange.setValues(STRAT);
//SYS
var SYS = [];
SYS.push(['SYS']);
for(var key in json.SYS)
{
SYS[0].push(json.SYS[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(55, 1, SYS.length, 4);
askRange.setValues(SYS);
//USDT
var USDT = [];
USDT.push(['USDT']);
for(var key in json.USDT)
{
USDT[0].push(json.USDT[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(56, 1, USDT.length, 4);
askRange.setValues(USDT);
//VIA
var VIA = [];
VIA.push(['VIA']);
for(var key in json.VIA)
{
VIA[0].push(json.VIA[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(57, 1, VIA.length, 4);
askRange.setValues(VIA);
//VRC
var VRC = [];
VRC.push(['VRC']);
for(var key in json.VRC)
{
VRC[0].push(json.VRC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(58, 1, VRC.length, 4);
askRange.setValues(VRC);
//VTC
var VTC = [];
VTC.push(['VTC']);
for(var key in json.VTC)
{
VTC[0].push(json.VTC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(59, 1, VTC.length, 4);
askRange.setValues(VTC);
//XBC
var XBC = [];
XBC.push(['XBC']);
for(var key in json.XBC)
{
XBC[0].push(json.XBC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(60, 1, XBC.length, 4);
askRange.setValues(XBC);
//XCP
var XCP = [];
XCP.push(['XCP']);
for(var key in json.XCP)
{
XCP[0].push(json.XCP[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(61, 1, XCP.length, 4);
askRange.setValues(XCP);
//XEM
var XEM = [];
XEM.push(['XEM']);
for(var key in json.XEM)
{
XEM[0].push(json.XEM[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(62, 1, XEM.length, 4);
askRange.setValues(XEM);
//XMR
var XMR = [];
XMR.push(['XMR']);
for(var key in json.XMR)
{
XMR[0].push(json.XMR[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(63, 1, XMR.length, 4);
askRange.setValues(XMR);
//XPM
var XPM = [];
XPM.push(['XPM']);
for(var key in json.XPM)
{
XPM[0].push(json.XPM[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(64, 1, XPM.length, 4);
askRange.setValues(XPM);
//XRP
var XRP = [];
XRP.push(['XRP']);
for(var key in json.XRP)
{
XRP[0].push(json.XRP[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(65, 1, XRP.length, 4);
askRange.setValues(XRP);
//XVC
var XVC = [];
XVC.push(['XVC']);
for(var key in json.XVC)
{
XVC[0].push(json.XVC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(66, 1, XVC.length, 4);
askRange.setValues(XVC);
//ZEC
var ZEC = [];
ZEC.push(['ZEC']);
for(var key in json.ZEC)
{
ZEC[0].push(json.ZEC[key]);
}
// Put the coin data into the spreadsheet columns
askRange = data.getRange(67, 1, ZEC.length, 4);
askRange.setValues(ZEC);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment