Browse Source

Fix the asset class parsing

pull/4559/head
Thomas Kaul 4 months ago
parent
commit
8d3d26f0e2
  1. 5
      apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts
  2. 41
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

5
apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts

@ -11,6 +11,7 @@ import {
IDataProviderHistoricalResponse, IDataProviderHistoricalResponse,
IDataProviderResponse IDataProviderResponse
} from '@ghostfolio/api/services/interfaces/interfaces'; } from '@ghostfolio/api/services/interfaces/interfaces';
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config';
import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { DATE_FORMAT } from '@ghostfolio/common/helper';
import { import {
DataProviderInfo, DataProviderInfo,
@ -72,7 +73,9 @@ export class AlphaVantageService implements DataProviderInterface {
const historicalData: { const historicalData: {
[symbol: string]: IAlphaVantageHistoricalResponse[]; [symbol: string]: IAlphaVantageHistoricalResponse[];
} = await this.alphaVantage.crypto.daily( } = await this.alphaVantage.crypto.daily(
symbol.substring(0, symbol.length - 3).toLowerCase(), symbol
.substring(0, symbol.length - DEFAULT_CURRENCY.length)
.toLowerCase(),
'usd' 'usd'
); );

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

@ -12,8 +12,11 @@ import {
IDataProviderHistoricalResponse, IDataProviderHistoricalResponse,
IDataProviderResponse IDataProviderResponse
} from '@ghostfolio/api/services/interfaces/interfaces'; } from '@ghostfolio/api/services/interfaces/interfaces';
import { REPLACE_NAME_PARTS } from '@ghostfolio/common/config'; import {
import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper'; DEFAULT_CURRENCY,
REPLACE_NAME_PARTS
} from '@ghostfolio/common/config';
import { DATE_FORMAT, isCurrency, parseDate } from '@ghostfolio/common/helper';
import { import {
DataProviderInfo, DataProviderInfo,
LookupItem, LookupItem,
@ -67,7 +70,15 @@ export class FinancialModelingPrepService implements DataProviderInterface {
}; };
try { try {
if (this.cryptocurrencyService.isCryptocurrency(symbol)) { if (
isCurrency(symbol.substring(0, symbol.length - DEFAULT_CURRENCY.length))
) {
response.assetClass = AssetClass.LIQUIDITY;
response.assetSubClass = AssetSubClass.CASH;
response.currency = symbol.substring(
symbol.length - DEFAULT_CURRENCY.length
);
} else if (this.cryptocurrencyService.isCryptocurrency(symbol)) {
const [quote] = await fetch( const [quote] = await fetch(
`${this.URL}/quote/${symbol}?apikey=${this.apiKey}`, `${this.URL}/quote/${symbol}?apikey=${this.apiKey}`,
{ {
@ -77,7 +88,9 @@ export class FinancialModelingPrepService implements DataProviderInterface {
response.assetClass = AssetClass.LIQUIDITY; response.assetClass = AssetClass.LIQUIDITY;
response.assetSubClass = AssetSubClass.CRYPTOCURRENCY; response.assetSubClass = AssetSubClass.CRYPTOCURRENCY;
response.currency = symbol.substring(symbol.length - 3); response.currency = symbol.substring(
symbol.length - DEFAULT_CURRENCY.length
);
response.name = quote.name; response.name = quote.name;
} else { } else {
const [assetProfile] = await fetch( const [assetProfile] = await fetch(
@ -472,15 +485,17 @@ export class FinancialModelingPrepService implements DataProviderInterface {
let assetClass: AssetClass; let assetClass: AssetClass;
let assetSubClass: AssetSubClass; let assetSubClass: AssetSubClass;
if (profile.isEtf) { if (profile) {
assetClass = AssetClass.EQUITY; if (profile.isEtf) {
assetSubClass = AssetSubClass.ETF; assetClass = AssetClass.EQUITY;
} else if (profile.isFund) { assetSubClass = AssetSubClass.ETF;
assetClass = AssetClass.EQUITY; } else if (profile.isFund) {
assetSubClass = AssetSubClass.MUTUALFUND; assetClass = AssetClass.EQUITY;
} else { assetSubClass = AssetSubClass.MUTUALFUND;
assetClass = AssetClass.EQUITY; } else {
assetSubClass = AssetSubClass.STOCK; assetClass = AssetClass.EQUITY;
assetSubClass = AssetSubClass.STOCK;
}
} }
return { assetClass, assetSubClass }; return { assetClass, assetSubClass };

Loading…
Cancel
Save