/* 2020-01-09 - get the gains generated by my automated ETC trading. 2020-10-23 - fix problem because API requires windowing to handle more than 50 rows, implemented windowing. */ const key = 'SOOOJ7OhVCOpJE4DAWz8v5B25UpdYya9buF8DFAkHzmUab5E9i0PlEPh'; // API Key const secret = 'UytAbgU8ty3n5a+JhaoIlcfh8zM4OBGY6PCC+Cfg2NI4waVzM52BBp9qmmyczrTDQpeha8q3nHeE/p7wNWKiVA=='; // API Private Key const KrakenClient = require('kraken-api'); const kraken = new KrakenClient(key, secret); (async () => { try { let params={ ofs : 0 }; try { let allBalances=await kraken.api('Balance'); //console.log(JSON.stringify(allBalances)); let etcUsdQuote = await kraken.api('Ticker', { pair : 'XETCZUSD' }); //console.log(JSON.stringify(etcUsdQuote)); let allTransactions = await kraken.api('TradesHistory', params); let dailyResults = []; //console.log("Get Trade History ",JSON.stringify(allTransactions,null," ")); let allTradeIDs=Object.keys(allTransactions.result.trades); let sumUSD=0; let sumCommission=0; let numTrans=allTradeIDs.length; for (let i=0;i{ // console.log(date," -> ",dailyResults[date]); }); console.log("# trades : ", params.ofs-1); console.log("SUM USD : ", sumUSD); console.log("SUM fees : ", sumCommission); let netGain = sumUSD - sumCommission; console.log("Net Gain : ", netGain); let numCoinsHeld = Number(allBalances.result.XETC); console.log("# coins Held : ", numCoinsHeld); let sellPrice = Number(etcUsdQuote.result.XETCZUSD.b[0]); console.log("Current Price : ", sellPrice); let worthHeldCoins = numCoinsHeld * sellPrice; console.log("Worth held coins : ", worthHeldCoins); let netLiq = netGain + worthHeldCoins; console.log("Net Liquidation Gain : " , netLiq); } catch (ex) { console.error("Error getting trade history: ", ex.message); } } catch (ex) { console.error("Hit general Error-handler: ", ex.message, "\n", ex.stack); } })(); /* { "error": [], "result": { "trades": { "TUJ6CI-YOYLW-S6LDBQ": { "ordertxid": "OWBBBM-UQS7T-BH5RTY", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETCZUSD", "time": 1578609866.7625, "type": "sell", "ordertype": "market", "price": "5.11900000", "cost": "51.18999999", "fee": "0.13309399", "vol": "10.00000000", "margin": "0.00000000", "misc": "" }, "T7VTAJ-W5HBL-KVG2BQ": { "ordertxid": "OJKOCP-RFMVO-D5AD3W", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETCZUSD", "time": 1578604045.7998, "type": "buy", "ordertype": "market", "price": "5.01700000", "cost": "50.17000000", "fee": "0.13044200", "vol": "10.00000000", "margin": "0.00000000", "misc": "" }, "TEXK75-SRRBQ-5DUVIG": { "ordertxid": "ON4CNP-RDAWZ-A77OMH", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETCZUSD", "time": 1578600324.9445, "type": "sell", "ordertype": "market", "price": "5.11800000", "cost": "51.18000001", "fee": "0.13306799", "vol": "10.00000000", "margin": "0.00000000", "misc": "" }, "TAJGH2-677GW-PLUYFF": { "ordertxid": "OZFB5U-D4PX7-TA23BP", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETCZUSD", "time": 1578599314.3601, "type": "sell", "ordertype": "limit", "price": "5.08400000", "cost": "50.84000000", "fee": "0.13218400", "vol": "10.00000000", "margin": "0.00000000", "misc": "" }, "TRPXQ3-FSM2Q-6BC3P7": { "ordertxid": "OTJC4F-6MXXU-JHICN4", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETCZUSD", "time": 1578590114.8608, "type": "buy", "ordertype": "market", "price": "4.89700000", "cost": "48.97000000", "fee": "0.12732200", "vol": "10.00000000", "margin": "0.00000000", "misc": "" }, "TYIRWY-3JLW4-3GM4OO": { "ordertxid": "OZB455-X4YWN-X3A7J4", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETCZUSD", "time": 1578586116.836, "type": "buy", "ordertype": "limit", "price": "4.96600000", "cost": "44.69400000", "fee": "0.11620440", "vol": "9.00000000", "margin": "0.00000000", "misc": "" }, "TDZJSE-PCTDA-5H6GHW": { "ordertxid": "OUUCEQ-BQRXP-AWNWUX", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETCZUSD", "time": 1578560505.5051, "type": "buy", "ordertype": "market", "price": "5.01500000", "cost": "5.01500000", "fee": "0.01303900", "vol": "1.00000000", "margin": "0.00000000", "misc": "" }, "TTNMCG-CPYYR-DIMUQY": { "ordertxid": "O4SEFZ-GFJWL-JHQE6F", "postxid": "TKH2SE-M7IF5-CFI7LT", "pair": "XETHZUSD", "time": 1578499686.8045, "type": "buy", "ordertype": "limit", "price": "140.82000", "cost": "50.00000", "fee": "0.13000", "vol": "0.35506320", "margin": "0.00000", "misc": "" } }, "count": 8 } } */