parameterize so it can be used for all pairs.
This commit is contained in:
@@ -14,9 +14,15 @@ const kraken = new KrakenClient(key, secret);
|
||||
ofs : 0
|
||||
};
|
||||
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');
|
||||
//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));
|
||||
let allTransactions = await kraken.api('TradesHistory', params);
|
||||
|
||||
@@ -26,11 +32,13 @@ const kraken = new KrakenClient(key, secret);
|
||||
let sumUSD=0;
|
||||
let sumCommission=0;
|
||||
let numTrans=allTradeIDs.length;
|
||||
let numTrades=0;
|
||||
for (let i=0;i<numTrans;i++){
|
||||
params.ofs+=1;
|
||||
let theTrade=allTransactions.result.trades[allTradeIDs[i]];
|
||||
if (theTrade.pair==="XMRUSD") {
|
||||
console.log("XMR",JSON.stringify(theTrade));
|
||||
if (theTrade.pair===thePair) {
|
||||
numTrades++;
|
||||
console.log(JSON.stringify(theTrade));
|
||||
let multiplier=1;
|
||||
if (theTrade.type==="buy") {
|
||||
multiplier=-1;
|
||||
@@ -61,22 +69,28 @@ const kraken = new KrakenClient(key, secret);
|
||||
// console.log(date," -> ",dailyResults[date]);
|
||||
});
|
||||
|
||||
console.log("# trades : ", params.ofs-1);
|
||||
console.log("# trades : ", numTrades);
|
||||
console.log("SUM USD : ", sumUSD);
|
||||
console.log("SUM fees : ", sumCommission);
|
||||
let netGain = sumUSD - sumCommission;
|
||||
console.log("Net Gain : ", netGain);
|
||||
|
||||
let numCoinsHeld = Number(allBalances.result.XMR);
|
||||
console.log("# coins Held : ", numCoinsHeld);
|
||||
let sellPrice = Number(etcUsdQuote.result.XMRUSD.b[0]);
|
||||
// find the currency by looking for "startsWith" match in the symbol in the pair..
|
||||
let theCurrency=undefined;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user