Skip to content

Commit

Permalink
Implement main flow for lookup trx with required start-end
Browse files Browse the repository at this point in the history
  • Loading branch information
ZIMkaRU committed May 27, 2024
1 parent 7f12b5b commit b3bdb09
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions workers/loc.api/sync/transaction.tax.report/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict'

const { pushLargeArr } = require('../../helpers/utils')

const {
TRX_TAX_STRATEGIES,
remapTrades,
remapMovements
remapMovements,
lookUpTrades
} = require('./helpers')

const { decorateInjectable } = require('../../di/utils')
Expand Down Expand Up @@ -102,8 +105,39 @@ class TransactionTaxReport {
})
: { trxs: [] }

// TODO:
return []
const isBackIterativeSaleLookUp = isFIFO && !isLIFO
const isBackIterativeBuyLookUp = isFIFO && !isLIFO

const { buyTradesWithUnrealizedProfit } = await lookUpTrades(
trxsForPrevPeriod,
{
isBackIterativeSaleLookUp,
isBackIterativeBuyLookUp,
isBuyTradesWithUnrealizedProfitRequired: true,
isNotGainOrLossRequired: true
}
)

pushLargeArr(trxsForCurrPeriod, buyTradesWithUnrealizedProfit)
pushLargeArr(
trxsForConvToUsd,
buyTradesWithUnrealizedProfit
.filter((trx) => (
!Number.isFinite(trx?.firstSymbPriceUsd) ||
!Number.isFinite(trx?.lastSymbPriceUsd)
))
)
await this.#convertCurrencies(trxsForConvToUsd)

const { saleTradesWithRealizedProfit } = await lookUpTrades(
trxsForCurrPeriod,
{
isBackIterativeSaleLookUp,
isBackIterativeBuyLookUp
}
)

return saleTradesWithRealizedProfit
}

async #getTrxs (params) {
Expand Down Expand Up @@ -163,6 +197,9 @@ class TransactionTaxReport {
}
}

// TODO:
async #convertCurrencies (trxs, opts) {}

async #getTrades ({
user,
start,
Expand Down

0 comments on commit b3bdb09

Please sign in to comment.