@ -15,7 +15,11 @@ import {
PROPERTY_IS_READ_ONLY_MODE ,
PROPERTY_IS_USER_SIGNUP_ENABLED
} from '@ghostfolio/common/config' ;
import { isCurrency , getCurrencyFromSymbol } from '@ghostfolio/common/helper' ;
import {
getAssetProfileIdentifier ,
getCurrencyFromSymbol ,
isCurrency
} from '@ghostfolio/common/helper' ;
import {
AdminData ,
AdminMarketData ,
@ -261,6 +265,37 @@ export class AdminService {
this . prismaService . symbolProfile . count ( { where } )
] ) ;
const lastMarketPrices = await this . prismaService . marketData . findMany ( {
distinct : [ 'dataSource' , 'symbol' ] ,
orderBy : { date : 'desc' } ,
select : {
dataSource : true ,
marketPrice : true ,
symbol : true
} ,
where : {
dataSource : {
in : assetProfiles . map ( ( { dataSource } ) = > {
return dataSource ;
} )
} ,
symbol : {
in : assetProfiles . map ( ( { symbol } ) = > {
return symbol ;
} )
}
}
} ) ;
const lastMarketPriceMap = new Map < string , number > ( ) ;
for ( const { dataSource , marketPrice , symbol } of lastMarketPrices ) {
lastMarketPriceMap . set (
getAssetProfileIdentifier ( { dataSource , symbol } ) ,
marketPrice
) ;
}
let marketData : AdminMarketDataItem [ ] = await Promise . all (
assetProfiles . map (
async ( {
@ -281,6 +316,11 @@ export class AdminService {
const countriesCount = countries
? Object . keys ( countries ) . length
: 0 ;
const lastMarketPrice = lastMarketPriceMap . get (
getAssetProfileIdentifier ( { dataSource , symbol } )
) ;
const marketDataItemCount =
marketDataItems . find ( ( marketDataItem ) = > {
return (
@ -288,6 +328,7 @@ export class AdminService {
marketDataItem . symbol === symbol
) ;
} ) ? . _count ? ? 0 ;
const sectorsCount = sectors ? Object . keys ( sectors ) . length : 0 ;
return {
@ -298,6 +339,7 @@ export class AdminService {
countriesCount ,
dataSource ,
id ,
lastMarketPrice ,
name ,
symbol ,
marketDataItemCount ,
@ -511,15 +553,47 @@ export class AdminService {
}
private async getMarketDataForCurrencies ( ) : Promise < AdminMarketData > {
const marketDataItems = await this . prismaService . marketData . groupBy ( {
const currencyPairs = this . exchangeRateDataService . getCurrencyPairs ( ) ;
const [ lastMarketPrices , marketDataItems ] = await Promise . all ( [
this . prismaService . marketData . findMany ( {
distinct : [ 'dataSource' , 'symbol' ] ,
orderBy : { date : 'desc' } ,
select : {
dataSource : true ,
marketPrice : true ,
symbol : true
} ,
where : {
dataSource : {
in : currencyPairs . map ( ( { dataSource } ) = > {
return dataSource ;
} )
} ,
symbol : {
in : currencyPairs . map ( ( { symbol } ) = > {
return symbol ;
} )
}
}
} ) ,
this . prismaService . marketData . groupBy ( {
_count : true ,
by : [ 'dataSource' , 'symbol' ]
} ) ;
} )
] ) ;
const lastMarketPriceMap = new Map < string , number > ( ) ;
for ( const { dataSource , marketPrice , symbol } of lastMarketPrices ) {
lastMarketPriceMap . set (
getAssetProfileIdentifier ( { dataSource , symbol } ) ,
marketPrice
) ;
}
const marketDataPromise : Promise < AdminMarketDataItem > [ ] =
this . exchangeRateDataService
. getCurrencyPairs ( )
. map ( async ( { dataSource , symbol } ) = > {
const marketDataPromise : Promise < AdminMarketDataItem > [ ] = currencyPairs . map (
async ( { dataSource , symbol } ) = > {
let activitiesCount : EnhancedSymbolProfile [ 'activitiesCount' ] = 0 ;
let currency : EnhancedSymbolProfile [ 'currency' ] = '-' ;
let dateOfFirstActivity : EnhancedSymbolProfile [ 'dateOfFirstActivity' ] ;
@ -530,6 +604,10 @@ export class AdminService {
await this . orderService . getStatisticsByCurrency ( currency ) ) ;
}
const lastMarketPrice = lastMarketPriceMap . get (
getAssetProfileIdentifier ( { dataSource , symbol } )
) ;
const marketDataItemCount =
marketDataItems . find ( ( marketDataItem ) = > {
return (
@ -542,6 +620,7 @@ export class AdminService {
activitiesCount ,
currency ,
dataSource ,
lastMarketPrice ,
marketDataItemCount ,
symbol ,
assetClass : AssetClass.LIQUIDITY ,
@ -552,7 +631,8 @@ export class AdminService {
name : symbol ,
sectorsCount : 0
} ;
} ) ;
}
) ;
const marketData = await Promise . all ( marketDataPromise ) ;
return { marketData , count : marketData.length } ;