这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 2 deletions test/helpers/mock-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = new Map([
12.12345,
12345.12345,
null,
'Margin Funding Payment on wallet funding'
'Trading fees for 0.041154 BTG (BTGEUR) @ 28.818 on BFX (0.2%) on wallet exchange'
],
[
30012345,
Expand All @@ -95,7 +95,7 @@ module.exports = new Map([
12.12345,
12345.12345,
null,
'Margin Funding Payment on wallet funding'
'Used Margin Funding Charge on wallet margin'
]
]
],
Expand Down
91 changes: 91 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 @@ -483,6 +483,70 @@ module.exports = (
}
})

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

const paramsArr = getParamsArrToTestTimeframeGrouping({
start,
end,
isTradingFees: true,
isFundingFees: true
})

for (const params of paramsArr) {
const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getTotalFeesReport',
params,
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

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

const resItem = res.body.result[0]

assert.isObject(resItem)
assert.containsAllKeys(resItem, [
'mts',
'cumulative',
'USD'
])
}
})

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

const paramsArr = getParamsArrToTestTimeframeGrouping({ start, end })

for (const params of paramsArr) {
const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
auth,
method: 'getTotalFeesReport',
params,
id: 5
})
.expect('Content-Type', /json/)
.expect(400)

assert.isObject(res.body)
assert.isObject(res.body.error)
assert.propertyVal(res.body.error, 'code', 400)
assert.propertyVal(res.body.error, 'message', 'Args params is not valid')
assert.propertyVal(res.body, 'id', 5)
}
})

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

Expand Down Expand Up @@ -882,6 +946,33 @@ module.exports = (
await testMethodOfGettingCsv(procPromise, aggrPromise, res)
})

it('it should be successfully performed by the getTotalFeesReportCsv 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: 'getTotalFeesReportCsv',
params: {
end,
start,
timeframe: 'day',
email,
isTradingFees: true
},
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

await testMethodOfGettingCsv(procPromise, aggrPromise, res)
})

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

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 @@ -73,6 +73,7 @@ const FullSnapshotReport = require('../sync/full.snapshot.report')
const Trades = require('../sync/trades')
const TradedVolume = require('../sync/traded.volume')
const FeesReport = require('../sync/fees.report')
const TotalFeesReport = require('../sync/total.fees.report')
const PerformingLoan = require('../sync/performing.loan')
const SubAccountApiData = require('../sync/sub.account.api.data')
const PositionsAudit = require('../sync/positions.audit')
Expand Down Expand Up @@ -133,6 +134,7 @@ module.exports = ({
['_fullTaxReport', TYPES.FullTaxReport],
['_tradedVolume', TYPES.TradedVolume],
['_feesReport', TYPES.FeesReport],
['_totalFeesReport', TYPES.TotalFeesReport],
['_performingLoan', TYPES.PerformingLoan],
['_subAccountApiData', TYPES.SubAccountApiData],
['_positionsAudit', TYPES.PositionsAudit],
Expand Down Expand Up @@ -309,6 +311,8 @@ module.exports = ({
.to(TradedVolume)
bind(TYPES.FeesReport)
.to(FeesReport)
bind(TYPES.TotalFeesReport)
.to(TotalFeesReport)
bind(TYPES.PerformingLoan)
.to(PerformingLoan)
bind(TYPES.SubAccountApiData)
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 @@ -62,5 +62,6 @@ module.exports = {
WinLossVSAccountBalance: Symbol.for('WinLossVSAccountBalance'),
DBBackupManager: Symbol.for('DBBackupManager'),
ProcessMessageManager: Symbol.for('ProcessMessageManager'),
ProcessMessageManagerFactory: Symbol.for('ProcessMessageManagerFactory')
ProcessMessageManagerFactory: Symbol.for('ProcessMessageManagerFactory'),
TotalFeesReport: Symbol.for('TotalFeesReport')
}
12 changes: 10 additions & 2 deletions workers/loc.api/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const {
BaseError,
AuthError,
ConflictError
ConflictError,
ArgsParamsError
} = require('bfx-report/workers/loc.api/errors')

class CollSyncPermissionError extends BaseError {
Expand Down Expand Up @@ -180,6 +181,12 @@ class DbRestoringError extends BaseError {
}
}

class TotalFeesParamsFlagError extends ArgsParamsError {
constructor (message = 'ERR_TOTAL_FEES_REPORT_PARAMS_FLAGS_MUST_HAVE_AT_LEAST_ONCE_TRUE_VALUE') {
super(message)
}
}

module.exports = {
BaseError,
CollSyncPermissionError,
Expand Down Expand Up @@ -207,5 +214,6 @@ module.exports = {
DataConsistencyError,
DataConsistencyWhileSyncingError,
ProcessStateSendingError,
DbRestoringError
DbRestoringError,
TotalFeesParamsFlagError
}
38 changes: 38 additions & 0 deletions workers/loc.api/generate-csv/csv.job.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,44 @@ class CsvJobData extends BaseCsvJobData {
return jobData
}

async getTotalFeesReportCsvJobData (
args,
uId,
uInfo
) {
checkParams(args, 'paramsSchemaForTotalFeesReportCsv')

const {
userId,
userInfo
} = await checkJobAndGetUserData(
this.rService,
uId,
uInfo
)

const csvArgs = getCsvArgs(args)

const jobData = {
userInfo,
userId,
name: 'getTotalFeesReport',
fileNamesMap: [['getTotalFeesReport', 'total-fees-report']],
args: csvArgs,
propNameForPagination: null,
columnsCsv: {
USD: 'USD',
cumulative: 'CUMULATIVE USD',
mts: 'DATE'
},
formatSettings: {
mts: 'date'
}
}

return jobData
}

async getPerformingLoanCsvJobData (
args,
uId,
Expand Down
41 changes: 41 additions & 0 deletions workers/loc.api/helpers/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,36 @@ const paramsSchemaForFeesReportApi = {
}
}

const paramsSchemaForTotalFeesReportApi = {
type: 'object',
properties: {
timeframe: {
type: 'string',
enum: [
'day',
'week',
'month',
'year'
]
},
start: {
type: 'integer'
},
end: {
type: 'integer'
},
symbol: {
type: ['string', 'array']
},
isTradingFees: {
type: 'boolean'
},
isFundingFees: {
type: 'boolean'
}
}
}

const paramsSchemaForPerformingLoanApi = {
type: 'object',
properties: {
Expand Down Expand Up @@ -412,6 +442,15 @@ const paramsSchemaForFeesReportCsv = {
}
}

const paramsSchemaForTotalFeesReportCsv = {
type: 'object',
properties: {
...cloneDeep(paramsSchemaForTotalFeesReportApi.properties),
timezone,
dateFormat
}
}

const paramsSchemaForPerformingLoanCsv = {
type: 'object',
properties: {
Expand Down Expand Up @@ -444,6 +483,7 @@ module.exports = {
paramsSchemaForFullTaxReportApi,
paramsSchemaForTradedVolumeApi,
paramsSchemaForFeesReportApi,
paramsSchemaForTotalFeesReportApi,
paramsSchemaForPerformingLoanApi,
paramsSchemaForCandlesApi,
paramsSchemaForBalanceHistoryCsv,
Expand All @@ -454,6 +494,7 @@ module.exports = {
paramsSchemaForFullTaxReportCsv,
paramsSchemaForTradedVolumeCsv,
paramsSchemaForFeesReportCsv,
paramsSchemaForTotalFeesReportCsv,
paramsSchemaForPerformingLoanCsv,
paramsSchemaForCandlesCsv
}
26 changes: 26 additions & 0 deletions workers/loc.api/service.report.framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,9 @@ class FrameworkReportService extends ReportService {
}, 'getTradedVolume', args, cb)
}

/**
* @deprecated
*/
getFeesReport (space, args, cb) {
return this._privResponder(async () => {
await this._dataConsistencyChecker
Expand All @@ -1277,6 +1280,17 @@ class FrameworkReportService extends ReportService {
}, 'getFeesReport', args, cb)
}

getTotalFeesReport (space, args, cb) {
return this._privResponder(async () => {
await this._dataConsistencyChecker
.check(this._CHECKER_NAMES.TOTAL_FEES_REPORT, args)

checkParams(args, 'paramsSchemaForTotalFeesReportApi')

return this._totalFeesReport.getTotalFeesReport(args)
}, 'getTotalFeesReport', args, cb)
}

getPerformingLoan (space, args, cb) {
return this._privResponder(async () => {
await this._dataConsistencyChecker
Expand Down Expand Up @@ -1366,6 +1380,9 @@ class FrameworkReportService extends ReportService {
}, 'getTradedVolumeCsv', args, cb)
}

/**
* @deprecated
*/
getFeesReportCsv (space, args, cb) {
return this._responder(() => {
return this._generateCsv(
Expand All @@ -1375,6 +1392,15 @@ class FrameworkReportService extends ReportService {
}, 'getFeesReportCsv', args, cb)
}

getTotalFeesReportCsv (space, args, cb) {
return this._responder(() => {
return this._generateCsv(
'getTotalFeesReportCsvJobData',
args
)
}, 'getTotalFeesReportCsv', args, cb)
}

getPerformingLoanCsv (space, args, cb) {
return this._responder(() => {
return this._generateCsv(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

const AbstractMigration = require('./abstract.migration')

class MigrationV30 extends AbstractMigration {
/**
* @override
*/
up () {
const sqlArr = [
`UPDATE ledgers SET _category = 228
WHERE description LIKE '%margin funding fee%' COLLATE NOCASE`
]

this.addSql(sqlArr)
}

/**
* @override
*/
down () {
const sqlArr = [
`UPDATE ledgers SET _category = null
WHERE description LIKE '%margin funding fee%' COLLATE NOCASE`
]

this.addSql(sqlArr)
}
}

module.exports = MigrationV30
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = {
FULL_TAX_REPORT: 'getFullTaxReport',
TRADED_VOLUME: 'getTradedVolume',
FEES_REPORT: 'getFeesReport',
TOTAL_FEES_REPORT: 'getTotalFeesReport',
PERFORMING_LOAN: 'getPerformingLoan'
}
Loading