Browse Source

Merge branch 'main' into feature/improve-currency-validation-in-get-asset-profiles-functionality-of-data-provider-service

pull/5747/head
Thomas Kaul 3 weeks ago
committed by GitHub
parent
commit
c89067f369
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 7
      apps/api/src/services/data-provider/data-provider.service.ts
  3. 42
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts
  4. 10
      libs/common/src/lib/helper.ts
  5. 7
      package-lock.json
  6. 1
      package.json

1
CHANGELOG.md

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Disabled the zoom functionality in the _Progressive Web App_ (PWA) - Disabled the zoom functionality in the _Progressive Web App_ (PWA)
- Improved the currency validation in the get asset profiles functionality of the data provider service - Improved the currency validation in the get asset profiles functionality of the data provider service
- Improved the currency validation in the search functionality of the data provider service
- Optimized the get quotes functionality by utilizing the asset profile resolutions in the _Financial Modeling Prep_ service - Optimized the get quotes functionality by utilizing the asset profile resolutions in the _Financial Modeling Prep_ service
- Extracted the footer to a component - Extracted the footer to a component

7
apps/api/src/services/data-provider/data-provider.service.ts

@ -653,8 +653,11 @@ export class DataProviderService implements OnModuleInit {
const filteredItems = lookupItems const filteredItems = lookupItems
.filter(({ currency }) => { .filter(({ currency }) => {
// Only allow symbols with supported currency if (includeIndices) {
return currency ? true : false; return true;
}
return currency ? isCurrency(currency) : false;
}) })
.map((lookupItem) => { .map((lookupItem) => {
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {

42
apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

@ -377,26 +377,42 @@ export class FinancialModelingPrepService implements DataProviderInterface {
{ {
signal: AbortSignal.timeout(requestTimeout) signal: AbortSignal.timeout(requestTimeout)
} }
).then((res) => res.json()) ).then(
(res) => res.json() as unknown as { price: number; symbol: string }[]
)
]); ]);
if (assetProfileResolutions.length === symbols.length) { for (const { currency, symbolTarget } of assetProfileResolutions) {
for (const { currency, symbolTarget } of assetProfileResolutions) { currencyBySymbolMap[symbolTarget] = { currency };
currencyBySymbolMap[symbolTarget] = { currency }; }
const resolvedSymbols = assetProfileResolutions.map(
({ symbolTarget }) => {
return symbolTarget;
} }
} else { );
const symbolsToFetch = quotes
.map(({ symbol }) => {
return symbol;
})
.filter((symbol) => {
return !resolvedSymbols.includes(symbol);
});
if (symbolsToFetch.length > 0) {
await Promise.all( await Promise.all(
quotes.map(({ symbol }) => { symbolsToFetch.map(async (symbol) => {
return this.getAssetProfile({ const assetProfile = await this.getAssetProfile({
requestTimeout, requestTimeout,
symbol symbol
}).then((assetProfile) => {
if (assetProfile?.currency) {
currencyBySymbolMap[symbol] = {
currency: assetProfile.currency
};
}
}); });
if (assetProfile?.currency) {
currencyBySymbolMap[symbol] = {
currency: assetProfile.currency
};
}
}) })
); );
} }

10
libs/common/src/lib/helper.ts

@ -1,7 +1,7 @@
import * as currencies from '@dinero.js/currencies';
import { NumberParser } from '@internationalized/number'; import { NumberParser } from '@internationalized/number';
import { Type as ActivityType, DataSource, MarketData } from '@prisma/client'; import { Type as ActivityType, DataSource, MarketData } from '@prisma/client';
import { Big } from 'big.js'; import { Big } from 'big.js';
import { isISO4217CurrencyCode } from 'class-validator';
import { import {
getDate, getDate,
getMonth, getMonth,
@ -340,8 +340,12 @@ export function interpolate(template: string, context: any) {
}); });
} }
export function isCurrency(aCurrency = '') { export function isCurrency(aCurrency: string) {
return currencies[aCurrency] || isDerivedCurrency(aCurrency); if (!aCurrency) {
return false;
}
return isISO4217CurrencyCode(aCurrency) || isDerivedCurrency(aCurrency);
} }
export function isDerivedCurrency(aCurrency: string) { export function isDerivedCurrency(aCurrency: string) {

7
package-lock.json

@ -28,7 +28,6 @@
"@dfinity/candid": "0.15.7", "@dfinity/candid": "0.15.7",
"@dfinity/identity": "0.15.7", "@dfinity/identity": "0.15.7",
"@dfinity/principal": "0.15.7", "@dfinity/principal": "0.15.7",
"@dinero.js/currencies": "2.0.0-alpha.8",
"@internationalized/number": "3.6.3", "@internationalized/number": "3.6.3",
"@ionic/angular": "8.7.3", "@ionic/angular": "8.7.3",
"@keyv/redis": "4.4.0", "@keyv/redis": "4.4.0",
@ -5018,12 +5017,6 @@
"ts-node": "^10.8.2" "ts-node": "^10.8.2"
} }
}, },
"node_modules/@dinero.js/currencies": {
"version": "2.0.0-alpha.8",
"resolved": "https://registry.npmjs.org/@dinero.js/currencies/-/currencies-2.0.0-alpha.8.tgz",
"integrity": "sha512-zApiqtuuPwjiM9LJA5/kNcT48VSHRiz2/mktkXjIpfxrJKzthXybUAgEenExIH6dYhLDgVmsLQZtZFOsdYl0Ag==",
"license": "MIT"
},
"node_modules/@discoveryjs/json-ext": { "node_modules/@discoveryjs/json-ext": {
"version": "0.6.3", "version": "0.6.3",
"resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.6.3.tgz", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.6.3.tgz",

1
package.json

@ -74,7 +74,6 @@
"@dfinity/candid": "0.15.7", "@dfinity/candid": "0.15.7",
"@dfinity/identity": "0.15.7", "@dfinity/identity": "0.15.7",
"@dfinity/principal": "0.15.7", "@dfinity/principal": "0.15.7",
"@dinero.js/currencies": "2.0.0-alpha.8",
"@internationalized/number": "3.6.3", "@internationalized/number": "3.6.3",
"@ionic/angular": "8.7.3", "@ionic/angular": "8.7.3",
"@keyv/redis": "4.4.0", "@keyv/redis": "4.4.0",

Loading…
Cancel
Save