From 38e201703a85a7d9af0c97aa13c25315e8b98e7d Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 22 Apr 2022 13:37:19 +0300 Subject: [PATCH 1/5] Add forex symbols --- workers/loc.api/helpers/forex.symbs.js | 3 +++ workers/loc.api/helpers/index.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 workers/loc.api/helpers/forex.symbs.js diff --git a/workers/loc.api/helpers/forex.symbs.js b/workers/loc.api/helpers/forex.symbs.js new file mode 100644 index 00000000..0ae6fc67 --- /dev/null +++ b/workers/loc.api/helpers/forex.symbs.js @@ -0,0 +1,3 @@ +'use strict' + +module.exports = ['EUR', 'JPY', 'GBP', 'USD'] diff --git a/workers/loc.api/helpers/index.js b/workers/loc.api/helpers/index.js index b9f92a92..ea3898d8 100644 --- a/workers/loc.api/helpers/index.js +++ b/workers/loc.api/helpers/index.js @@ -52,6 +52,7 @@ const FILTER_MODELS_NAMES = require('./filter.models.names') const FILTER_CONDITIONS = require('./filter.conditions') const getDataFromApi = require('./get-data-from-api') const splitSymbolPairs = require('./split-symbol-pairs') +const FOREX_SYMBS = require('./forex.symbs') module.exports = { getREST, @@ -91,5 +92,6 @@ module.exports = { FILTER_CONDITIONS, getDataFromApi, parsePositionsAuditId, - splitSymbolPairs + splitSymbolPairs, + FOREX_SYMBS } From 14c3b5edb2dbca4b679158b598d6decec52fa08b Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 22 Apr 2022 13:38:30 +0300 Subject: [PATCH 2/5] Fix symbol pair splitting --- workers/loc.api/helpers/split-symbol-pairs.js | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/workers/loc.api/helpers/split-symbol-pairs.js b/workers/loc.api/helpers/split-symbol-pairs.js index 78653477..b28d7f4d 100644 --- a/workers/loc.api/helpers/split-symbol-pairs.js +++ b/workers/loc.api/helpers/split-symbol-pairs.js @@ -1,16 +1,58 @@ 'use strict' -module.exports = (symbol) => { - const str = ( - symbol[0] === 't' || - symbol[0] === 'f' +const FOREX_SYMBS = require('./forex.symbs') + +const detectingSymbs = [ + 'BTC', + ...FOREX_SYMBS +] + +/* It allows to cover pairs with str length 6 and without `t` and `f` prefixes + * for currency converter of bfx-reports-framework used to triangulation: + * `BTCUSD`, `BTCEOS` etc + */ +const isNotSymbContained = ( + currSymb, + symbs = detectingSymbs +) => { + return ( + Array.isArray(symbs) && + symbs.every((symb) => ( + !currSymb.startsWith(symb) && + !currSymb.endsWith(symb) + )) ) +} + +const _startsWithPrefix = (str) => ( + str.startsWith('t') || + str.startsWith('f') +) + +const _containsSeparator = (str) => ( + /.+[:].+/.test(str) +) + +module.exports = (symbol) => { + const hasPrefix = _startsWithPrefix(symbol) + const hasSeparator = _containsSeparator(symbol) + + if ( + !hasPrefix && + !hasSeparator && + symbol.length > 5 && + isNotSymbContained(symbol) + ) { + return [symbol] + } + + const str = hasPrefix ? symbol.slice(1) : symbol if ( str.length > 5 && - /.+[:].+/.test(str) + hasSeparator ) { return str.split(':') } From d0fe2109754630c17de8fa3eb94ec232c13d3daf Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 22 Apr 2022 13:39:42 +0300 Subject: [PATCH 3/5] Add test cases for symbol pair splitting --- .../__test__/split-symbol-pairs.spec.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js b/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js index 1f083cf0..e0b2aec9 100644 --- a/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js +++ b/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js @@ -38,6 +38,17 @@ describe('splitSymbolPairs helper', () => { assert.strictEqual(res[1], 'USD') }) + it('BTCEOS pair', function () { + this.timeout(1000) + + const res = splitSymbolPairs('BTCEOS') + + assert.isArray(res) + assert.lengthOf(res, 2) + assert.strictEqual(res[0], 'BTC') + assert.strictEqual(res[1], 'EOS') + }) + it('tXAUT:USD pair', function () { this.timeout(1000) @@ -103,4 +114,34 @@ describe('splitSymbolPairs helper', () => { assert.strictEqual(res[0], 'EUR') assert.strictEqual(res[1], 'USD') }) + + it('MATIC coin, without separator', function () { + this.timeout(1000) + + const res = splitSymbolPairs('MATIC') + + assert.isArray(res) + assert.lengthOf(res, 1) + assert.strictEqual(res[0], 'MATIC') + }) + + it('MATICM coin, without separator', function () { + this.timeout(1000) + + const res = splitSymbolPairs('MATICM') + + assert.isArray(res) + assert.lengthOf(res, 1) + assert.strictEqual(res[0], 'MATICM') + }) + + it('MATICMF0 coin, without separator', function () { + this.timeout(1000) + + const res = splitSymbolPairs('MATICMF0') + + assert.isArray(res) + assert.lengthOf(res, 1) + assert.strictEqual(res[0], 'MATICMF0') + }) }) From ae36c3c3ac6ed770470c5300653929392ff4db69 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 22 Apr 2022 13:49:19 +0300 Subject: [PATCH 4/5] Add forex symbols to dep injection --- workers/loc.api/di/app.deps.js | 4 +++- workers/loc.api/di/types.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/workers/loc.api/di/app.deps.js b/workers/loc.api/di/app.deps.js index 723cbdcf..e128ab08 100644 --- a/workers/loc.api/di/app.deps.js +++ b/workers/loc.api/di/app.deps.js @@ -13,7 +13,8 @@ const { getREST, grcBfxReq, prepareResponse, - prepareApiResponse + prepareApiResponse, + FOREX_SYMBS } = require('../helpers') const HasGrcService = require('../has.grc.service') const processor = require('../queue/processor') @@ -86,6 +87,7 @@ module.exports = ({ [TYPES.GetREST] ) ) + bind(TYPES.FOREX_SYMBS).toConstantValue(FOREX_SYMBS) bind(TYPES.Link).toConstantValue(link) bind(TYPES.HasGrcService) .to(HasGrcService) diff --git a/workers/loc.api/di/types.js b/workers/loc.api/di/types.js index 67d97f10..04fc2977 100644 --- a/workers/loc.api/di/types.js +++ b/workers/loc.api/di/types.js @@ -2,6 +2,7 @@ module.exports = { CONF: Symbol.for('CONF'), + FOREX_SYMBS: Symbol.for('FOREX_SYMBS'), RootPath: Symbol.for('RootPath'), Container: Symbol.for('Container'), LoggerFactory: Symbol.for('LoggerFactory'), From 2d528d688348d2508a7e4299f1c513ec5aa6cbbe Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 27 Apr 2022 13:26:51 +0300 Subject: [PATCH 5/5] Add test case for tMATIC:USD pair splitting --- .../helpers/__test__/split-symbol-pairs.spec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js b/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js index e0b2aec9..1e3f3af1 100644 --- a/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js +++ b/workers/loc.api/helpers/__test__/split-symbol-pairs.spec.js @@ -125,6 +125,17 @@ describe('splitSymbolPairs helper', () => { assert.strictEqual(res[0], 'MATIC') }) + it('tMATIC:USD pair, without separator', function () { + this.timeout(1000) + + const res = splitSymbolPairs('tMATIC:USD') + + assert.isArray(res) + assert.lengthOf(res, 2) + assert.strictEqual(res[0], 'MATIC') + assert.strictEqual(res[1], 'USD') + }) + it('MATICM coin, without separator', function () { this.timeout(1000)