diff --git a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts index bff51aabe..3893efd44 100644 --- a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts @@ -25,17 +25,17 @@ export class AccountClusterRiskCurrentInvestment extends Rule { }; } = {}; - for (const account of Object.keys(this.accounts)) { - accounts[account] = { - name: account, - investment: this.accounts[account].current + for (const [accountId, account] of Object.entries(this.accounts)) { + accounts[accountId] = { + name: account.name, + investment: account.current }; } let maxItem; let totalInvestment = 0; - Object.values(accounts).forEach((account) => { + for (const account of Object.values(accounts)) { if (!maxItem) { maxItem = account; } @@ -47,7 +47,7 @@ export class AccountClusterRiskCurrentInvestment extends Rule { if (account.investment > maxItem?.investment) { maxItem = account; } - }); + } const maxInvestmentRatio = maxItem.investment / totalInvestment; diff --git a/apps/api/src/models/rules/account-cluster-risk/initial-investment.ts b/apps/api/src/models/rules/account-cluster-risk/initial-investment.ts index 13da575dd..0eed098cc 100644 --- a/apps/api/src/models/rules/account-cluster-risk/initial-investment.ts +++ b/apps/api/src/models/rules/account-cluster-risk/initial-investment.ts @@ -19,35 +19,35 @@ export class AccountClusterRiskInitialInvestment extends Rule { } public evaluate(ruleSettings?: Settings) { - const platforms: { + const accounts: { [symbol: string]: Pick & { investment: number; }; } = {}; - for (const account of Object.keys(this.accounts)) { - platforms[account] = { - name: account, - investment: this.accounts[account].original + for (const [accountId, account] of Object.entries(this.accounts)) { + accounts[accountId] = { + name: account.name, + investment: account.original }; } let maxItem; let totalInvestment = 0; - Object.values(platforms).forEach((platform) => { + for (const account of Object.values(accounts)) { if (!maxItem) { - maxItem = platform; + maxItem = account; } // Calculate total investment - totalInvestment += platform.investment; + totalInvestment += account.investment; // Find maximum - if (platform.investment > maxItem?.investment) { - maxItem = platform; + if (account.investment > maxItem?.investment) { + maxItem = account; } - }); + } const maxInvestmentRatio = maxItem.investment / totalInvestment;