parameterize so it can be used for all pairs.

This commit is contained in:
Joe Tretter
2020-12-02 08:05:45 -06:00
parent 21278b0073
commit eb6d72c4b0

View File

@@ -14,9 +14,15 @@ const kraken = new KrakenClient(key, secret);
ofs : 0 ofs : 0
}; };
try { try {
// get the pair to process from the first parameter and fall back if not provided.
let thePair=process.argv[2];
if (thePair===undefined) {
thePair="XXMRZUSD";
}
console.log("Processing pair: ", thePair);
let allBalances=await kraken.api('Balance'); let allBalances=await kraken.api('Balance');
//console.log(JSON.stringify(allBalances)); //console.log(JSON.stringify(allBalances));
let etcUsdQuote = await kraken.api('Ticker', { pair : 'XMRUSD' }); let etcUsdQuote = await kraken.api('Ticker', { pair : thePair });
//console.log(JSON.stringify(etcUsdQuote)); //console.log(JSON.stringify(etcUsdQuote));
let allTransactions = await kraken.api('TradesHistory', params); let allTransactions = await kraken.api('TradesHistory', params);
@@ -26,11 +32,13 @@ const kraken = new KrakenClient(key, secret);
let sumUSD=0; let sumUSD=0;
let sumCommission=0; let sumCommission=0;
let numTrans=allTradeIDs.length; let numTrans=allTradeIDs.length;
let numTrades=0;
for (let i=0;i<numTrans;i++){ for (let i=0;i<numTrans;i++){
params.ofs+=1; params.ofs+=1;
let theTrade=allTransactions.result.trades[allTradeIDs[i]]; let theTrade=allTransactions.result.trades[allTradeIDs[i]];
if (theTrade.pair==="XMRUSD") { if (theTrade.pair===thePair) {
console.log("XMR",JSON.stringify(theTrade)); numTrades++;
console.log(JSON.stringify(theTrade));
let multiplier=1; let multiplier=1;
if (theTrade.type==="buy") { if (theTrade.type==="buy") {
multiplier=-1; multiplier=-1;
@@ -61,22 +69,28 @@ const kraken = new KrakenClient(key, secret);
// console.log(date," -> ",dailyResults[date]); // console.log(date," -> ",dailyResults[date]);
}); });
console.log("# trades : ", params.ofs-1); console.log("# trades : ", numTrades);
console.log("SUM USD : ", sumUSD); console.log("SUM USD : ", sumUSD);
console.log("SUM fees : ", sumCommission); console.log("SUM fees : ", sumCommission);
let netGain = sumUSD - sumCommission; let netGain = sumUSD - sumCommission;
console.log("Net Gain : ", netGain); console.log("Net Gain : ", netGain);
let numCoinsHeld = Number(allBalances.result.XMR); // find the currency by looking for "startsWith" match in the symbol in the pair..
console.log("# coins Held : ", numCoinsHeld); let theCurrency=undefined;
let sellPrice = Number(etcUsdQuote.result.XMRUSD.b[0]); Object.keys(allBalances.result).forEach((currency)=>{
if (thePair.indexOf(currency)===0) {
theCurrency=currency;
}
});
let numCoinsHeld = Number(allBalances.result[theCurrency]);
console.log("# coins Held : ", numCoinsHeld, " [", theCurrency,"]");
let sellPrice = Number(etcUsdQuote.result[thePair].b[0]);
console.log("Current Price : ", sellPrice); console.log("Current Price : ", sellPrice);
let worthHeldCoins = numCoinsHeld * sellPrice; let worthHeldCoins = numCoinsHeld * sellPrice;
console.log("Worth held coins : ", worthHeldCoins); console.log("Worth held coins : ", worthHeldCoins);
let netLiq = netGain + worthHeldCoins; let netLiq = netGain + worthHeldCoins;
console.log("Net Liquidation Gain : " , netLiq); console.log("Net Liquidation Gain : " , netLiq);
} catch (ex) { } catch (ex) {
console.error("Error getting trade history: ", ex.message); console.error("Error getting trade history: ", ex.message);
} }