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

Release Master #339

Merged
merged 21 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c616b1b
Add ability to sync candles once per day
ZIMkaRU Nov 15, 2023
0eb1a6c
Merge pull request #334 from ZIMkaRU/feature/add-ability-to-sync-cand…
ezewer Nov 20, 2023
3291c40
Add debug logger to currency converter
ZIMkaRU Nov 20, 2023
ad9eb77
Set session auth for checking new pub data
ZIMkaRU Nov 20, 2023
a951597
Add ability to reference specific user currencies when candles sync
ZIMkaRU Nov 20, 2023
5e84e98
Add ability to use SyncUserStepManager with candles considering user
ZIMkaRU Nov 22, 2023
cbc9342
Add ability to use DataChecker with candles considering user
ZIMkaRU Nov 22, 2023
1b99bc3
Add ability to use DataInserter with candles considering user
ZIMkaRU Nov 22, 2023
2b9e60b
Fix base end mts for candles sync
ZIMkaRU Nov 23, 2023
7f40fd2
Fix user filter for db sync info operations
ZIMkaRU Nov 23, 2023
e71eeb4
Fix check have-colls-been-synced for candles
ZIMkaRU Nov 23, 2023
f03efd6
Set candles limit 20 reqs/min
ZIMkaRU Nov 23, 2023
b182605
Add approximate candles sync time estimation
ZIMkaRU Nov 23, 2023
1761984
Fix bfx auth token refreshing
ZIMkaRU Nov 23, 2023
4825ea7
Merge pull request #336 from ZIMkaRU/bugfix/fix-bfx-auth-token-refres…
ezewer Nov 24, 2023
8160699
Merge pull request #335 from ZIMkaRU/feature/add-ability-to-reference…
ezewer Nov 24, 2023
6480170
Set 10 reqs per min for bfx api trades endpoint
ZIMkaRU Nov 24, 2023
0d42bfe
Merge pull request #337 from ZIMkaRU/feature/set-10-reqs-per-min-for-…
ezewer Nov 24, 2023
b291eea
Bump version up to 4.12.0
ZIMkaRU Nov 28, 2023
06de3cd
Update bfx-report-ui sub-module
ZIMkaRU Nov 28, 2023
e335541
Merge pull request #338 from ZIMkaRU/feature/release-version
ezewer Nov 28, 2023
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
2 changes: 1 addition & 1 deletion bfx-report-ui
Submodule bfx-report-ui updated 68 files
+4,472 −3,042 package-lock.json
+2 −2 package.json
+13 −1 public/locales/en/translations.json
+33 −33 public/locales/zh-TW/translations.json
+11 −9 src/components/AccountBalance/AccountBalance.js
+2 −2 src/components/AccountSummary/AccountSummary.feeTierVolume.js
+7 −8 src/components/AccountSummary/AccountSummary.js
+75 −0 src/components/AppSummary/AppSummary.byAsset.js
+208 −0 src/components/AppSummary/AppSummary.columns.js
+4 −0 src/components/AppSummary/AppSummary.container.js
+25 −84 src/components/AppSummary/AppSummary.fees.js
+35 −0 src/components/AppSummary/AppSummary.helpers.js
+39 −36 src/components/AppSummary/AppSummary.js
+9 −5 src/components/AppSummary/AppSummary.value.js
+152 −46 src/components/AppSummary/_AppSummary.scss
+1 −1 src/components/ErrorDialog/ErrorDialog.js
+5 −3 src/components/PublicTrades/PublicTrades.columns.js
+2 −3 src/components/SubAccounts/SubAccount/SubAccount.js
+3 −3 src/components/Trades/Trades.columns.js
+5 −1 src/state/accountBalance/saga.js
+2 −2 src/state/audit/reducer.js
+5 −1 src/state/auth/saga.js
+2 −2 src/state/base/saga.js
+1 −2 src/state/candles/saga.js
+2 −2 src/state/changeLogs/reducer.js
+2 −2 src/state/columns/selectors.js
+2 −2 src/state/derivatives/reducer.js
+2 −2 src/state/filters/reducer.js
+4 −5 src/state/filters/selectors.js
+2 −3 src/state/filters/utils.js
+2 −2 src/state/fundingCreditHistory/reducer.js
+2 −2 src/state/fundingLoanHistory/reducer.js
+2 −2 src/state/fundingOfferHistory/reducer.js
+2 −2 src/state/invoices/utils.js
+2 −2 src/state/ledgers/utils.js
+3 −3 src/state/logins/reducer.js
+2 −2 src/state/movements/reducer.js
+3 −3 src/state/orderTrades/reducer.js
+2 −2 src/state/orders/reducer.js
+2 −3 src/state/pagination/reducer.js
+2 −2 src/state/positions/reducer.js
+2 −2 src/state/publicFunding/reducer.js
+2 −2 src/state/publicTrades/reducer.js
+2 −0 src/state/reducers.js
+2 −2 src/state/routing/selectors.js
+3 −3 src/state/sagas.helper.js
+2 −0 src/state/sagas.js
+34 −0 src/state/summaryByAsset/actions.js
+6 −0 src/state/summaryByAsset/constants.js
+36 −0 src/state/summaryByAsset/reducer.js
+53 −0 src/state/summaryByAsset/saga.js
+15 −0 src/state/summaryByAsset/selectors.js
+8 −0 src/state/sync/actions.js
+2 −0 src/state/sync/constants.js
+7 −0 src/state/sync/reducer.js
+8 −8 src/state/sync/saga.js
+2 −0 src/state/sync/selectors.js
+2 −2 src/state/tickers/reducer.js
+2 −2 src/state/timeRange/reducer.js
+2 −2 src/state/trades/reducer.js
+2 −3 src/state/utils.js
+ src/styles/fonts/Roboto-Medium.woff2
+8 −0 src/styles/fonts/roboto.css
+4 −0 src/styles/index.scss
+1 −0 src/ui/Charts/Chart/Chart.js
+10 −2 src/ui/DataTable/DataTable.js
+1 −0 src/ui/SectionHeader/_SectionHeader.scss
+4 −5 src/utils/columns.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-reports-framework",
"version": "4.11.0",
"version": "4.12.0",
"description": "Bitfinex reports framework",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions workers/loc.api/bfx.api.router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class BfxApiRouter extends BaseBfxApiRouter {
['payInvoiceList', 90],
['accountTrades', 90],
['fundingTrades', 90],
['trades', 15],
['trades', 10],
['statusMessages', 90],
['candles', 30],
['candles', 20],
['orderTrades', 90],
['orderHistory', 90],
['activeOrders', 90],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = (ctx) => {
)

const paramsOrder = [
'syncedAt',
'symbol',
'timeframe',
'baseStart',
Expand Down
33 changes: 21 additions & 12 deletions workers/loc.api/sync/authenticator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,19 +1082,25 @@ class Authenticator {
} = user ?? {}
const tokenKey = this._getTokenKeyByEmailField(user)

const userSession = this.userSessions.get(token) ?? {}
const authTokenRefreshInterval = authToken
? this.setupAuthTokenRefreshInterval(user)
: null

this.userSessions.set(
token, {
...user,
authTokenFn: () => {
return this.userSessions.get(token)?.authToken
},
authTokenRefreshInterval,
authTokenInvalidateIntervals: new Map()
}
token,
Object.assign(
userSession,
user,
{
authTokenFn: () => {
return this.userSessions.get(token)?.authToken
},
authTokenRefreshInterval,
authTokenInvalidateIntervals: userSession
?.authTokenInvalidateIntervals ?? new Map()
}
)
)
this.userTokenMapByEmail.set(tokenKey, token)
}
Expand Down Expand Up @@ -1133,9 +1139,8 @@ class Authenticator {
? token
: this.userTokenMapByEmail.get(tokenKey)

this.userTokenMapByEmail.delete(tokenKey)

const session = this.userSessions.get(_token) ?? {}
this.userTokenMapByEmail.delete(this._getTokenKeyByEmailField(session))
const {
authTokenRefreshInterval,
authTokenInvalidateIntervals = new Map()
Expand Down Expand Up @@ -1272,8 +1277,12 @@ class Authenticator {
const { authTokenInvalidateIntervals } = userSession
let count = 0

if (authTokenInvalidateIntervals.has(authToken)) {
return
}

const authTokenInvalidateInterval = setInterval(async () => {
const session = this.userSessions.get(token)
const session = this.userSessions.get(token) ?? userSession

try {
count += 1
Expand All @@ -1288,7 +1297,7 @@ class Authenticator {
} catch (err) {
if (count >= 3) {
clearInterval(authTokenInvalidateInterval)
session.authTokenInvalidateIntervals?.delete(authToken)
session?.authTokenInvalidateIntervals?.delete(authToken)
}

this.logger.debug(err)
Expand Down
9 changes: 7 additions & 2 deletions workers/loc.api/sync/currency.converter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const depsTypes = (TYPES) => [
TYPES.SyncSchema,
TYPES.FOREX_SYMBS,
TYPES.ALLOWED_COLLS,
TYPES.SYNC_API_METHODS
TYPES.SYNC_API_METHODS,
TYPES.Logger
]
class CurrencyConverter {
constructor (
Expand All @@ -40,7 +41,8 @@ class CurrencyConverter {
syncSchema,
FOREX_SYMBS,
ALLOWED_COLLS,
SYNC_API_METHODS
SYNC_API_METHODS,
logger
) {
this.rService = rService
this.getDataFromApi = getDataFromApi
Expand All @@ -49,6 +51,7 @@ class CurrencyConverter {
this.FOREX_SYMBS = FOREX_SYMBS
this.ALLOWED_COLLS = ALLOWED_COLLS
this.SYNC_API_METHODS = SYNC_API_METHODS
this.logger = logger

this._COLL_NAMES = {
PUBLIC_TRADES: 'publicTrades',
Expand Down Expand Up @@ -114,6 +117,8 @@ class CurrencyConverter {
return this.currenciesSynonymous
}
} catch (err) {
this.logger.debug(err)

return this.currenciesSynonymous
}
}
Expand Down
120 changes: 85 additions & 35 deletions workers/loc.api/sync/data.inserter/data.checker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ class DataChecker {
return filterMethodCollMap(methodCollMap)
}

async checkNewPublicData () {
/*
* `authMap` can be empty
*/
async checkNewPublicData (authMap) {
const methodCollMap = this._getMethodCollMap()

if (this._isInterrupted) {
return filterMethodCollMap(methodCollMap, true)
}

await this._checkNewDataPublicArrObjType(methodCollMap)
await this._checkNewDataPublicArrObjType(authMap, methodCollMap)
await this._checkNewPublicUpdatableData(methodCollMap)

return filterMethodCollMap(methodCollMap, true)
Expand Down Expand Up @@ -179,7 +182,7 @@ class DataChecker {
schema.start.push(freshSyncUserStepData)
}

async _checkNewDataPublicArrObjType (methodCollMap) {
async _checkNewDataPublicArrObjType (authMap, methodCollMap) {
for (const [method, schema] of methodCollMap) {
if (this._isInterrupted) {
return
Expand All @@ -191,7 +194,21 @@ class DataChecker {
this._resetSyncSchemaProps(schema)

if (schema.name === this.ALLOWED_COLLS.CANDLES) {
await this._checkNewCandlesData(method, schema)
// If `authMap` is empty sync candles for all users
const _authMap = (
!(authMap instanceof Map) ||
authMap.size === 0
)
? new Map([['ALL', {}]])
: authMap

for (const authItem of _authMap) {
await this._checkNewCandlesData(
method,
schema,
authItem[1]
)
}
}
if (
schema.name === this.ALLOWED_COLLS.PUBLIC_TRADES ||
Expand Down Expand Up @@ -336,20 +353,29 @@ class DataChecker {
*/
async _checkNewCandlesData (
method,
schema
schema,
auth
) {
if (this._isInterrupted) {
return
}

const { _id: userId, subUser } = auth ?? {}
const { _id: subUserId } = subUser ?? {}
const usersFilter = Number.isInteger(userId)
? { $eq: { user_id: userId } }
: {}

const currMts = Date.now()
const firstLedgerMts = await this._getFirstLedgerMts()
const firstLedgerMts = await this._getFirstLedgerMts(usersFilter)

if (!Number.isInteger(firstLedgerMts)) {
return
}

const uniqueSymbsSet = await this._getUniqueSymbsFromLedgers()
const uniqueSymbsSet = await this._getUniqueSymbsFromLedgers(
usersFilter
)
const candlesPairsSet = new Set()

for (const symbol of uniqueSymbsSet) {
Expand Down Expand Up @@ -389,7 +415,9 @@ class DataChecker {
collName: method,
symbol,
timeframe: CANDLES_TIMEFRAME,
defaultStart: firstLedgerMts
defaultStart: firstLedgerMts,
userId,
subUserId
}
)

Expand All @@ -398,7 +426,6 @@ class DataChecker {
!syncUserStepData.isCurrStepReady
) {
schema.hasNewData = true
schema.start.push(syncUserStepData)
}

const wasStartPointChanged = this._wasStartPointChanged(
Expand All @@ -407,39 +434,42 @@ class DataChecker {
)
const shouldFreshSyncBeAdded = this._shouldFreshSyncBeAdded(
syncUserStepData,
currMts
currMts,
{ dayOfYear: 1 }
)

if (
!wasStartPointChanged &&
!shouldFreshSyncBeAdded
) {
continue
}

const freshSyncUserStepData = this.syncUserStepDataFactory({
...syncUserStepData.getParams(),
isBaseStepReady: true,
isCurrStepReady: true
})

if (wasStartPointChanged) {
freshSyncUserStepData.setParams({
syncUserStepData.setParams({
baseStart: firstLedgerMts,
baseEnd: syncUserStepData.baseStart,
isBaseStepReady: false
})

schema.hasNewData = true
}
if (shouldFreshSyncBeAdded) {
freshSyncUserStepData.setParams({
syncUserStepData.setParams({
currStart: lastElemMtsFromTables,
currEnd: currMts,
isCurrStepReady: false
})

schema.hasNewData = true
}

schema.hasNewData = true
schema.start.push(freshSyncUserStepData)
if (!schema.hasNewData) {
continue
}

// To keep flow: one candles request per currency
if (!syncUserStepData.isBaseStepReady) {
syncUserStepData.setParams({
baseEnd: syncUserStepData.currEnd ?? currMts,
isCurrStepReady: true
})
}

syncUserStepData.auth = auth
schema.start.push(syncUserStepData)
}
}

Expand Down Expand Up @@ -502,7 +532,8 @@ class DataChecker {
) {
const {
measure = 'minutes',
allowedTimeDiff = 60
allowedTimeDiff = 60,
dayOfYear
} = allowedDiff ?? {}

const baseEnd = (
Expand All @@ -517,15 +548,28 @@ class DataChecker {
)
? syncUserStepData.currEnd
: 0
const syncedAt = syncUserStepData.hasSyncedAt
? syncUserStepData.syncedAt
: 0

const momentBaseEnd = moment.utc(baseEnd)
const momentCurrEnd = moment.utc(currEnd)
const momentCurrMts = moment.utc(currMts)
const momentSyncedAt = moment.utc(syncedAt)

const momentMaxEnd = moment.max(momentBaseEnd, momentCurrEnd)
const momentDiff = momentCurrMts.diff(momentMaxEnd, measure)

return momentDiff > allowedTimeDiff
const yearsDiff = momentCurrMts.year() - momentSyncedAt.year()
const dayOfYearDiff = momentCurrMts.dayOfYear() - momentSyncedAt.dayOfYear()

return (
momentDiff > allowedTimeDiff &&
(
!Number.isFinite(dayOfYear) ||
yearsDiff >= 1 ||
dayOfYearDiff >= dayOfYear
)
)
}

_wasStartPointChanged (
Expand Down Expand Up @@ -553,8 +597,11 @@ class DataChecker {
return momentDiff > allowedTimeDiff
}

async _getFirstLedgerMts () {
const firstElemFilter = { $not: { currency: 'USD' } }
async _getFirstLedgerMts (usersFilter) {
const firstElemFilter = {
...usersFilter,
$not: { currency: 'USD' }
}
const firstElemOrder = [['mts', 1]]

const tempLedgersTableName = SyncTempTablesManager.getTempTableName(
Expand Down Expand Up @@ -600,9 +647,12 @@ class DataChecker {
return mts
}

async _getUniqueSymbsFromLedgers () {
async _getUniqueSymbsFromLedgers (usersFilter) {
const ledgerParams = {
filter: { $not: { currency: this.FOREX_SYMBS } },
filter: {
...usersFilter,
$not: { currency: this.FOREX_SYMBS }
},
isDistinct: true,
projection: ['currency']
}
Expand Down
Loading