Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transaction tax report #373

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
fda5cec
Add TransactionTaxReport service type
ZIMkaRU Mar 18, 2024
a262335
Add TransactionTaxReport service
ZIMkaRU Mar 18, 2024
013a0c3
Add TransactionTaxReport service into di
ZIMkaRU Mar 18, 2024
65d331d
Add data consistency checker for TransactionTaxReport
ZIMkaRU Mar 18, 2024
415e184
Add params schema for TransactionTaxReport
ZIMkaRU Mar 18, 2024
084a43b
Add getTransactionTaxReport entrypoint to main service
ZIMkaRU Mar 18, 2024
b99c94e
Add report file job data for TransactionTaxReport
ZIMkaRU Mar 18, 2024
cf609b0
Add getTransactionTaxReportFile entrypoint to main service
ZIMkaRU Mar 18, 2024
84b3f84
Add ability to get trades for trx tax report
ZIMkaRU Mar 19, 2024
095cf3c
Implement transaction tax report calc
ZIMkaRU Mar 21, 2024
219a03e
Consider trades in tax reports that were not closed in prev period
ZIMkaRU Mar 25, 2024
86dee5f
Add CurrencyConversionError class
ZIMkaRU Mar 25, 2024
fd317bf
Use CurrencyConversionError class
ZIMkaRU Mar 25, 2024
b1205ef
Add CurrencyPairSeparationError class
ZIMkaRU Mar 25, 2024
4e84ad1
Use CurrencyPairSeparationError class
ZIMkaRU Mar 25, 2024
a5d2408
Speed up back iteration
ZIMkaRU Mar 26, 2024
e11ab8b
Optimize trx tax report calc performance
ZIMkaRU Mar 26, 2024
1bb8ec9
Increase request timeouts for dev mode
ZIMkaRU Mar 26, 2024
7ad37ec
Prevent event loop locking for trx tax report
ZIMkaRU Mar 26, 2024
921c0bf
Use sale trx to declare into tax report
ZIMkaRU Apr 1, 2024
aaa1bce
Improve lookup buy trx with unrealized profit
ZIMkaRU Apr 2, 2024
3e91d51
Rework trx tax report to consider deposit-withdrawal
ZIMkaRU Apr 3, 2024
3a41322
Implement currency conversion for trx tax report
ZIMkaRU Apr 4, 2024
f20ba5f
Speed up currency conversion for trx tax report
ZIMkaRU Apr 5, 2024
ec92940
Add TrxTaxReportGenerationTimeoutError error class
ZIMkaRU Apr 5, 2024
40c6e8b
Use TrxTaxReportGenerationTimeoutError error class
ZIMkaRU Apr 5, 2024
13c8eba
Add ability to send ws event when trx tax report generated
ZIMkaRU Apr 8, 2024
7ed653c
Add ability to make trx tax report in background
ZIMkaRU Apr 8, 2024
2d03cbb
Add endpoint to make trx tax report in background
ZIMkaRU Apr 8, 2024
912d8e1
Improve data consistency checker for trx tax report
ZIMkaRU Apr 8, 2024
3a679d2
Move trades lookup fn into separate helper
ZIMkaRU Apr 8, 2024
ffc268c
Move get-trx-map-by-ccy fn into separate helper
ZIMkaRU Apr 8, 2024
14c902d
Move get-pub-trade-chunk-payloads fn into separate helper
ZIMkaRU Apr 8, 2024
fab0d2a
Fix amount column name for trx tax report file
ZIMkaRU Apr 8, 2024
bc41c2a
Fix asset column name for trx tax report file
ZIMkaRU Apr 8, 2024
9624094
Add helper to check params and set default
ZIMkaRU Apr 9, 2024
8f56d96
Add fifo strategy for trx tax report
ZIMkaRU Apr 9, 2024
1c80fb5
Add support tax strategy prop as enum field
ZIMkaRU Apr 9, 2024
304131d
Fix lookup trades logic
ZIMkaRU Apr 10, 2024
522a478
Fix movements consideration into trx tax report
ZIMkaRU Apr 10, 2024
714dcfc
Add mock trades for unit test coverage
ZIMkaRU Apr 15, 2024
2e954ed
Add mocked-trades getter for unit test coverage
ZIMkaRU Apr 15, 2024
b14117a
Add main test structure for trx tax lookUpTrades helper
ZIMkaRU Apr 15, 2024
53ea82b
Add test case checker for buy trades with unrealized profit
ZIMkaRU Apr 16, 2024
22cfede
Add test coverage for lifo lookup buy trx with unrealized profit
ZIMkaRU Apr 16, 2024
bec571f
Fix lookup buy trx with unrealized profit
ZIMkaRU Apr 16, 2024
909ee7d
Add test coverage for fifo lookup buy trx with unrealized profit
ZIMkaRU Apr 16, 2024
96932b5
Add test case checker for sale trades with realized profit
ZIMkaRU Apr 16, 2024
ac01fbe
Improve test case checker for sale trades with realized profit
ZIMkaRU Apr 17, 2024
f56ce5d
Add test coverage for lifo lookup sale trx with realized profit
ZIMkaRU Apr 17, 2024
93cfd68
Add test coverage for fifo lookup sale trx with realized profit
ZIMkaRU Apr 17, 2024
982f9d6
Add test coverage for lifo lookup sale trx with realized profit with …
ZIMkaRU Apr 17, 2024
ed64143
Add test coverage for fifo lookup sale trx with realized profit with …
ZIMkaRU Apr 17, 2024
bdb1ef9
Fix price prop naming for trx tax report
ZIMkaRU Apr 18, 2024
b18a152
Move remap trades logic into separate helper
ZIMkaRU Apr 18, 2024
bda5d2d
Move remap movements logic into separate helper
ZIMkaRU Apr 18, 2024
881c392
Improve currency conversion precision for tax
ZIMkaRU Apr 18, 2024
ee011ed
Move convertCurrencyBySymbol logic into separate helper
ZIMkaRU Apr 18, 2024
4f044d1
Enhance trade mock data for trx tax report
ZIMkaRU Apr 19, 2024
e6dd3de
Fix getTrades test case to consider new mock data
ZIMkaRU Apr 19, 2024
f71d156
Add test case for getTransactionTaxReport method with lifo strategy
ZIMkaRU Apr 19, 2024
3c34b09
Add test case for getTransactionTaxReport method with fifo strategy
ZIMkaRU Apr 19, 2024
c731dc4
Add test case for getTransactionTaxReportFile method
ZIMkaRU Apr 19, 2024
ebee507
Add mock movements
ZIMkaRU Apr 22, 2024
99b6fae
Add helper to get mocked movements
ZIMkaRU Apr 22, 2024
14009c6
Rework remap helper naming
ZIMkaRU Apr 22, 2024
3a750ad
Add test cases checker for remapped movements
ZIMkaRU Apr 22, 2024
1384e46
Add test coverage for remap-movements helper
ZIMkaRU Apr 22, 2024
f412333
Enhance mock movement data
ZIMkaRU Apr 22, 2024
e360af8
Add test cases checker for remapped trades
ZIMkaRU Apr 22, 2024
b01feb8
Add test coverage for remap-trades helper
ZIMkaRU Apr 22, 2024
9361032
Add test cases checker for trx map by currency
ZIMkaRU Apr 23, 2024
3aaaff4
Add test coverage for get-trx-map-by-ccy helper
ZIMkaRU Apr 23, 2024
42049ac
Add test cases checker for pub trade chunk payloads
ZIMkaRU Apr 23, 2024
d47ee8c
Add test coverage for get-pub-trade-chunk-payloads helper
ZIMkaRU Apr 23, 2024
8711009
Add helper to get mocked trx map by ccy
ZIMkaRU Apr 24, 2024
3e0257b
Add test cases checker for converted currency by symbol
ZIMkaRU Apr 24, 2024
1289603
Add test coverage for convert-currency-by-symbol helper
ZIMkaRU Apr 24, 2024
3a9d74e
Fix currency converter by symbol for forex ccy
ZIMkaRU Apr 24, 2024
d5910e5
Fix getting pub trade chunk
ZIMkaRU Apr 25, 2024
6e86a07
Move pub trade chunk getter into separate module
ZIMkaRU Apr 25, 2024
6250ec5
Use pub trade chunk getter for ccy conversion
ZIMkaRU Apr 25, 2024
28fa005
Add helper to get mocked pub trades
ZIMkaRU Apr 25, 2024
579707b
Add test coverage for get-pub-trade-chunk helper
ZIMkaRU Apr 25, 2024
43e2756
Fix pushing large array into array for trx tax report
ZIMkaRU May 6, 2024
8165e03
Improve error classes for trx tax report
ZIMkaRU May 7, 2024
bffc8c1
Improve error logging for trx tax report
ZIMkaRU May 7, 2024
15019ae
Fix converting symbols like tETHF0:USTF0 for trx tax report
ZIMkaRU May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/config/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"app": {
"port": 31339,
"host": "127.0.0.1"
"host": "127.0.0.1",
"httpRpcTimeout": 600000,
"wsRpcTimeout": 3600000
},
"grenacheClient": {
"query": "rest:report:api",
Expand Down
112 changes: 108 additions & 4 deletions test/helpers/mock-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ module.exports = new Map([
'trades',
[
[
12345,
100012345,
'tBTCUSD',
_ms,
12345,
Expand All @@ -143,7 +143,33 @@ module.exports = new Map([
'USD'
],
[
10012346,
110012345,
'tETHUSD',
_ms,
12345,
0.12345,
12345,
null,
null,
false,
-3.0001,
'USD'
],
[
120012345,
'tETHUSD',
_ms,
12345,
-0.011,
12355,
null,
null,
false,
-3.0001,
'USD'
],
[
130012345,
'tBTCEUR',
_ms,
12345,
Expand All @@ -156,7 +182,20 @@ module.exports = new Map([
'BTC'
],
[
20012347,
140012345,
'tBTCEUR',
_ms,
12345,
-0.011,
12355,
null,
null,
false,
-0.0001,
'BTC'
],
[
150012347,
'tBTCGBP',
_ms,
12345,
Expand All @@ -169,7 +208,20 @@ module.exports = new Map([
'BTC'
],
[
30012345,
160012347,
'tBTCGBP',
_ms,
12345,
-0.011,
12355,
null,
null,
false,
-0.0001,
'BTC'
],
[
170012345,
'tBTCJPY',
_ms,
12345,
Expand All @@ -180,6 +232,58 @@ module.exports = new Map([
false,
-0.0001,
'BTC'
],
[
180012345,
'tBTCJPY',
_ms,
12345,
-0.011,
12355,
null,
null,
false,
-0.0001,
'BTC'
],
[
190012345,
'tETHBTC',
_ms,
12345,
0.01,
12345,
null,
null,
false,
-0.0001,
'BTC'
],
[
200012345,
'tETHBTC',
_ms,
12345,
-0.01,
12355,
null,
null,
false,
-0.0001,
'BTC'
],
[
210012345,
'tBTCUSD',
_ms,
12345,
0.12345,
12345,
null,
null,
false,
-3.0001,
'USD'
]
]
],
Expand Down
103 changes: 103 additions & 0 deletions test/test-cases/additional-api-sync-mode-sqlite-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,82 @@ module.exports = (
}
})

it('it should be successfully performed by the getTransactionTaxReport method, LIFO strategy', async function () {
this.timeout(60000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getTransactionTaxReport',
params: {
end,
start: start + (45 * 24 * 60 * 60 * 1000),
strategy: 'LIFO'
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isArray(res.body.result)
assert.isAtLeast(res.body.result.length, 1)

res.body.result.forEach((item) => {
assert.isObject(item)
assert.containsAllKeys(item, [
'asset',
'amount',
'mtsAcquired',
'mtsSold',
'proceeds',
'cost',
'gainOrLoss'
])
})
})

it('it should be successfully performed by the getTransactionTaxReport method, FIFO strategy', async function () {
this.timeout(60000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getTransactionTaxReport',
params: {
end,
start: start + (45 * 24 * 60 * 60 * 1000),
strategy: 'FIFO'
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isArray(res.body.result)
assert.isAtLeast(res.body.result.length, 1)

res.body.result.forEach((item) => {
assert.isObject(item)
assert.containsAllKeys(item, [
'asset',
'amount',
'mtsAcquired',
'mtsSold',
'proceeds',
'cost',
'gainOrLoss'
])
})
})

it('it should be successfully performed by the getTradedVolume method', async function () {
this.timeout(60000)

Expand Down Expand Up @@ -1034,6 +1110,33 @@ module.exports = (
)
})

it('it should be successfully performed by the getTransactionTaxReportFile method', async function () {
this.timeout(60000)

const procPromise = queueToPromise(params.processorQueue)
const aggrPromise = queueToPromise(params.aggregatorQueue)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getTransactionTaxReportFile',
params: {
isPDFRequired,
end,
start,
strategy: 'LIFO',
email
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

await testMethodOfGettingReportFile(procPromise, aggrPromise, res)
})

it('it should be successfully performed by the getTradedVolumeFile method', async function () {
this.timeout(60000)

Expand Down
2 changes: 1 addition & 1 deletion test/test-cases/api-sync-mode-sqlite-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ module.exports = (
symbol: ['tBTCUSD', 'tETHUSD'],
start: 0,
end,
limit: 10
limit: 2
},
id: 5
})
Expand Down
4 changes: 4 additions & 0 deletions workers/loc.api/di/app.deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const {
fullTaxReportCsvWriter
} = require('../generate-report-file/csv-writer')
const FullTaxReport = require('../sync/full.tax.report')
const TransactionTaxReport = require('../sync/transaction.tax.report')
const WeightedAveragesReport = require('../sync/weighted.averages.report')
const SqliteDbMigrator = require(
'../sync/dao/db-migrations/sqlite.db.migrator'
Expand Down Expand Up @@ -151,6 +152,7 @@ module.exports = ({
['_positionsSnapshot', TYPES.PositionsSnapshot],
['_fullSnapshotReport', TYPES.FullSnapshotReport],
['_fullTaxReport', TYPES.FullTaxReport],
['_transactionTaxReport', TYPES.TransactionTaxReport],
['_tradedVolume', TYPES.TradedVolume],
['_totalFeesReport', TYPES.TotalFeesReport],
['_performingLoan', TYPES.PerformingLoan],
Expand Down Expand Up @@ -393,6 +395,8 @@ module.exports = ({
)
bind(TYPES.FullTaxReport)
.to(FullTaxReport)
bind(TYPES.TransactionTaxReport)
.to(TransactionTaxReport)
rebind(TYPES.WeightedAveragesReport)
.to(WeightedAveragesReport)
rebind(TYPES.ReportFileJobData)
Expand Down
3 changes: 2 additions & 1 deletion workers/loc.api/di/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ module.exports = {
SyncUserStepData: Symbol.for('SyncUserStepData'),
SyncUserStepDataFactory: Symbol.for('SyncUserStepDataFactory'),
HTTPRequest: Symbol.for('HTTPRequest'),
SummaryByAsset: Symbol.for('SummaryByAsset')
SummaryByAsset: Symbol.for('SummaryByAsset'),
TransactionTaxReport: Symbol.for('TransactionTaxReport')
}
23 changes: 22 additions & 1 deletion workers/loc.api/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ class AuthTokenTTLSettingError extends ArgsParamsError {
}
}

class CurrencyConversionError extends BaseError {
constructor (data, message = 'ERR_CURRENCY_HAS_NOT_BEEN_CONVERTED_TO_USD') {
super({ data, message })
}
}

class CurrencyPairSeparationError extends BaseError {
constructor (data, message = 'ERR_CURRENCY_PAIR_HAS_NOT_BEEN_SEPARATED_CORRECTLY') {
super({ data, message })
}
}

class TrxTaxReportGenerationTimeoutError extends BaseError {
constructor (message = 'ERR_TRX_TAX_REPORT_GENERATION_TIMEOUT') {
super(message)
}
}

module.exports = {
BaseError,
CollSyncPermissionError,
Expand Down Expand Up @@ -284,5 +302,8 @@ module.exports = {
LastSyncedInfoGettingError,
SyncInfoUpdatingError,
AuthTokenGenerationError,
AuthTokenTTLSettingError
AuthTokenTTLSettingError,
CurrencyConversionError,
CurrencyPairSeparationError,
TrxTaxReportGenerationTimeoutError
}
Loading