So I have an idea to do that,
When the command place a BUY/SELL order succesfully, we will assign amount, date, total, rate to variables, let say a,b,c,d. Then we set other condition to write those variables back to the sheet "output". It means we dont setValue for "output" directly from other cell, the script did it. How do you think?
**Try the last time to help me on those probs to know how far we can do. And if we cant do any thing more, just tell me I will try other way to use this code. Anyway, I had a quite good result. THanks
cellB1 =getOrderNumber()
cellB2 =getTradeID()
cellB3 =getType()
cellB4 =getDate()
cellB5 =getAmount()
cellB6 =getRate()
cellB7 =getTotal()
Also, you'd have no way to know how many ResultingTrades there were... there could be multiple resulting from one buy/sell order... (ie. you want to buy 10 coins, but there is only lots of 1coin,3coin,3coin,2coin,4coin for sale... you would end up with at least 3 and possibly 5 trades to fulfil your order for 10 coins)... so you would need to multiple blocks of cells, each making function calls to get the individual values for each "resultingTrade"... there is also the possibility that there are NO resultingTrades if you put in an order that is not immediately fulfilled... so you'd probably need to wrap them all in IF() statements:
CellA2=getNumberResultingTrades()
CellB2=if($A$2>0,getTradeID(0),"")
CellC2=if($A$2>1,getTradeID(1),"")
CellD2=if($A$2>2,getTradeID(2),"")
...
Cellx2=if($A$2>x,getTradeID(x),"")
etc
function getNumberResultTrades() {
return buyData["resultingTrades"].length;
}
function getTradeID(num) {
return buyData["resultingTrades"][num]["tradeId"];
}
function poloniex(....) {
...
var dataAll = JSON.parse(response.getContentText());
buyData = dataAll;
...
}
return buyData["resultingTrades"][num]["type"];
}
getTradeDate(num) {
return buyData["resultingTrades"][num]["date"];
}
getTradeRate(num) {
return buyData["resultingTrades"][num]["rate"];
}
and do more =IF() statements:
CellB3=if($A$2>0,getTradeType(0),"")
CellC3=if($A$2>1,getTradeType(1),"")
CellD3=if($A$2>2,getTradeType(2),"")
...
Cellx3=if($A$2>x,getTradeType(x),"")
CellB4=if($A$2>0,getTradeDate(0),"")
CellC4=if($A$2>1,getTradeDate(1),"")
CellD4=if($A$2>2,getTradeDate(2),"")
...
Cellx4=if($A$2>x,getTradeDate(x),"")
etc
Another option could be to just return the API responses as strings, and use SPLIT() functions... but I'm not sure if the keys in the JSON objects are always in the same order... so that may cause issues as well...