update for 2024
This commit is contained in:
@@ -7,31 +7,31 @@ const coin = process.argv[2]
|
||||
|
||||
const pre2022 = csvToJson.fieldDelimiter(',').getJsonFromCsv(`./${coin}.csv`)
|
||||
|
||||
const utxos = []
|
||||
const lots = []
|
||||
|
||||
const handleBuy = (utxo) => {
|
||||
utxo.Remaining = new BN(utxo.ReceivedQuantity)
|
||||
utxos.push(utxo)
|
||||
const handleBuy = (lot) => {
|
||||
lot.Remaining = new BN(lot.ReceivedQuantity)
|
||||
lots.push(lot)
|
||||
}
|
||||
|
||||
const handleTrade = (trade) => {
|
||||
if (trade.ReceivedCurrency === coin) return handleBuy(trade)
|
||||
consumeUtxos(new BN(trade.SentQuantity))
|
||||
consumeLots(new BN(trade.SentQuantity))
|
||||
}
|
||||
|
||||
const consumeUtxos = (amount) => {
|
||||
for (let i = utxos.length - 1; i >= 0; i--) {
|
||||
const utxo = utxos[i]
|
||||
const consumeLots = (amount) => {
|
||||
for (let i = lots.length - 1; i >= 0; i--) {
|
||||
const lot = lots[i]
|
||||
|
||||
if (!utxo.Remaining) continue
|
||||
if (!lot.Remaining) continue
|
||||
|
||||
if (utxo.Remaining.gt(amount)) {
|
||||
utxo.Remaining = utxo.Remaining.minus(amount)
|
||||
if (lot.Remaining.gt(amount)) {
|
||||
lot.Remaining = lot.Remaining.minus(amount)
|
||||
return
|
||||
} else {
|
||||
amount = amount.minus(utxo.Remaining)
|
||||
utxo.Remaining = 0
|
||||
return consumeUtxos(amount)
|
||||
amount = amount.minus(lot.Remaining)
|
||||
lot.Remaining = 0
|
||||
return consumeLots(amount)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ pre2022.forEach(tx => {
|
||||
break
|
||||
case 'Sell':
|
||||
case 'Send':
|
||||
consumeUtxos(new BN(tx.SentQuantity))
|
||||
consumeLots(new BN(tx.SentQuantity))
|
||||
break
|
||||
case 'Trade':
|
||||
handleTrade(tx)
|
||||
@@ -55,23 +55,23 @@ pre2022.forEach(tx => {
|
||||
break
|
||||
}
|
||||
|
||||
if (tx.FeeCurrency === coin) consumeUtxos(new BN(tx.FeeAmount))
|
||||
if (tx.FeeCurrency === coin) consumeLots(new BN(tx.FeeAmount))
|
||||
})
|
||||
|
||||
const remaining = utxos
|
||||
.filter(utxo => !!utxo.Remaining)
|
||||
.map(utxo => {
|
||||
const remaining = lots
|
||||
.filter(lot => !!lot.Remaining)
|
||||
.map(lot => {
|
||||
return {
|
||||
Date: utxo.Date,
|
||||
Date: lot.Date,
|
||||
Asset: coin,
|
||||
Credit: utxo.Remaining.toFixed(8),
|
||||
Credit: lot.Remaining.toFixed(8),
|
||||
Debit: '',
|
||||
Price: new BN(utxo['ReceivedCostBasis(USD)']).div(utxo.ReceivedQuantity).toFixed(4),
|
||||
Original: utxo.ReceivedQuantity,
|
||||
Price: new BN(lot['ReceivedCostBasis(USD)']).div(lot.ReceivedQuantity).toFixed(4),
|
||||
Original: lot.ReceivedQuantity,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
converter.json2csv(remaining).then(csv =>
|
||||
fs.appendFileSync(`./${coin}-utxos.csv`, csv)
|
||||
fs.appendFileSync(`./${coin}-lots.csv`, csv)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user