From d09ae7abebb9dd07ac876db9e51175e61ae68c4f Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 28 Jun 2024 13:25:39 +0300 Subject: [PATCH 1/3] Improve PubTradeFindForTrxTaxError error log --- workers/loc.api/errors/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workers/loc.api/errors/index.js b/workers/loc.api/errors/index.js index fb7b6c50..a57ac54e 100644 --- a/workers/loc.api/errors/index.js +++ b/workers/loc.api/errors/index.js @@ -261,8 +261,8 @@ class CurrencyPairSeparationError extends BaseError { } class PubTradeFindForTrxTaxError extends BaseError { - constructor (message = 'ERR_NO_PUBLIC_TRADES_FOR_TRX_TAX') { - super(message) + constructor (data, message = 'ERR_NO_PUBLIC_TRADES_FOR_TRX_TAX') { + super({ data, message }) } } From 3665213303222aa0e61ec20c1fa849f1081a122f Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 28 Jun 2024 13:27:42 +0300 Subject: [PATCH 2/3] Fix pub-trade price lookup for trx tax report --- .../sync/transaction.tax.report/index.js | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/workers/loc.api/sync/transaction.tax.report/index.js b/workers/loc.api/sync/transaction.tax.report/index.js index 45638750..fbf40114 100644 --- a/workers/loc.api/sync/transaction.tax.report/index.js +++ b/workers/loc.api/sync/transaction.tax.report/index.js @@ -32,7 +32,8 @@ const depsTypes = (TYPES) => [ TYPES.GetDataFromApi, TYPES.WSEventEmitterFactory, TYPES.Logger, - TYPES.InterrupterFactory + TYPES.InterrupterFactory, + TYPES.CurrencyConverter ] class TransactionTaxReport { constructor ( @@ -46,7 +47,8 @@ class TransactionTaxReport { getDataFromApi, wsEventEmitterFactory, logger, - interrupterFactory + interrupterFactory, + currencyConverter ) { this.dao = dao this.authenticator = authenticator @@ -59,6 +61,7 @@ class TransactionTaxReport { this.wsEventEmitterFactory = wsEventEmitterFactory this.logger = logger this.interrupterFactory = interrupterFactory + this.currencyConverter = currencyConverter this.tradesModel = this.syncSchema.getModelsMap() .get(this.ALLOWED_COLLS.TRADES) @@ -258,6 +261,48 @@ class TransactionTaxReport { opts ) + if ( + !Array.isArray(pubTrades) || + pubTrades.length === 0 + ) { + const ccySynonymous = await this.currencyConverter + .getCurrenciesSynonymous() + const synonymous = ccySynonymous.get(symbol) + + if (!synonymous) { + throw new PubTradeFindForTrxTaxError({ + symbol, + pubTradeStart, + pubTradeEnd, + requiredMts: trx.mtsCreate + }) + } + + for (const [symbol, conversion] of synonymous) { + const res = await this.#getPublicTrades( + { symbol: `t${symbol}USD`, start }, + opts + ) + + if ( + !Array.isArray(res) || + res.length === 0 + ) { + continue + } + + pubTrades = res.map((item) => { + if (Number.isFinite(item?.price)) { + item.price = item.price * conversion + } + + return item + }) + + break + } + } + pubTradeStart = start ?? pubTrades[0]?.mts pubTradeEnd = pubTrades[pubTrades.length - 1]?.mts } @@ -270,7 +315,12 @@ class TransactionTaxReport { pubTradeStart > trx.mtsCreate || pubTradeEnd < trx.mtsCreate ) { - throw new PubTradeFindForTrxTaxError() + throw new PubTradeFindForTrxTaxError({ + symbol, + pubTradeStart, + pubTradeEnd, + requiredMts: trx.mtsCreate + }) } const pubTrade = findPublicTrade(pubTrades, trx.mtsCreate) From c1bde5b8b20f7152d76efdc200195f91a54cdca8 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 28 Jun 2024 13:29:03 +0300 Subject: [PATCH 3/3] Add pair separator if ccy length more than 3 --- workers/loc.api/sync/transaction.tax.report/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/workers/loc.api/sync/transaction.tax.report/index.js b/workers/loc.api/sync/transaction.tax.report/index.js index fbf40114..4a32d155 100644 --- a/workers/loc.api/sync/transaction.tax.report/index.js +++ b/workers/loc.api/sync/transaction.tax.report/index.js @@ -237,6 +237,9 @@ class TransactionTaxReport { } const trxPriceCalculatorIterator = getBackIterable(trxPriceCalculators) + const symbSeparator = symbol.length > 3 + ? ':' + : '' let pubTrades = [] let pubTradeStart = pubTrades[0]?.mts @@ -257,7 +260,7 @@ class TransactionTaxReport { const start = trx.mtsCreate - 1 pubTrades = await this.#getPublicTrades( - { symbol: `t${symbol}USD`, start }, + { symbol: `t${symbol}${symbSeparator}USD`, start }, opts ) @@ -279,8 +282,11 @@ class TransactionTaxReport { } for (const [symbol, conversion] of synonymous) { + const symbSeparator = symbol.length > 3 + ? ':' + : '' const res = await this.#getPublicTrades( - { symbol: `t${symbol}USD`, start }, + { symbol: `t${symbol}${symbSeparator}USD`, start }, opts )