|
@ -16,9 +16,9 @@ import { |
|
|
PROPERTY_IS_USER_SIGNUP_ENABLED |
|
|
PROPERTY_IS_USER_SIGNUP_ENABLED |
|
|
} from '@ghostfolio/common/config'; |
|
|
} from '@ghostfolio/common/config'; |
|
|
import { |
|
|
import { |
|
|
isCurrency, |
|
|
|
|
|
getAssetProfileIdentifier, |
|
|
getAssetProfileIdentifier, |
|
|
getCurrencyFromSymbol |
|
|
getCurrencyFromSymbol, |
|
|
|
|
|
isCurrency |
|
|
} from '@ghostfolio/common/helper'; |
|
|
} from '@ghostfolio/common/helper'; |
|
|
import { |
|
|
import { |
|
|
AdminData, |
|
|
AdminData, |
|
@ -266,22 +266,30 @@ export class AdminService { |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
const lastMarketPrices = await this.prismaService.marketData.findMany({ |
|
|
const lastMarketPrices = await this.prismaService.marketData.findMany({ |
|
|
|
|
|
distinct: ['dataSource', 'symbol'], |
|
|
|
|
|
orderBy: { date: 'desc' }, |
|
|
select: { |
|
|
select: { |
|
|
symbol: true, |
|
|
|
|
|
dataSource: true, |
|
|
dataSource: true, |
|
|
marketPrice: true |
|
|
marketPrice: true, |
|
|
|
|
|
symbol: true |
|
|
}, |
|
|
}, |
|
|
where: { |
|
|
where: { |
|
|
symbol: { in: assetProfiles.map(({ symbol }) => symbol) }, |
|
|
dataSource: { |
|
|
dataSource: { in: assetProfiles.map(({ dataSource }) => dataSource) } |
|
|
in: assetProfiles.map(({ dataSource }) => { |
|
|
}, |
|
|
return dataSource; |
|
|
orderBy: { date: 'desc' }, |
|
|
}) |
|
|
distinct: ['symbol', 'dataSource'] |
|
|
}, |
|
|
|
|
|
symbol: { |
|
|
|
|
|
in: assetProfiles.map(({ symbol }) => { |
|
|
|
|
|
return symbol; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const lastMarketPriceMap = new Map<string, number>(); |
|
|
const lastMarketPriceMap = new Map<string, number>(); |
|
|
|
|
|
|
|
|
for (const { symbol, dataSource, marketPrice } of lastMarketPrices) { |
|
|
for (const { dataSource, marketPrice, symbol } of lastMarketPrices) { |
|
|
lastMarketPriceMap.set( |
|
|
lastMarketPriceMap.set( |
|
|
getAssetProfileIdentifier({ dataSource, symbol }), |
|
|
getAssetProfileIdentifier({ dataSource, symbol }), |
|
|
marketPrice |
|
|
marketPrice |
|
@ -308,6 +316,9 @@ export class AdminService { |
|
|
const countriesCount = countries |
|
|
const countriesCount = countries |
|
|
? Object.keys(countries).length |
|
|
? Object.keys(countries).length |
|
|
: 0; |
|
|
: 0; |
|
|
|
|
|
const lastMarketPrice = lastMarketPriceMap.get( |
|
|
|
|
|
getAssetProfileIdentifier({ dataSource, symbol }) |
|
|
|
|
|
); |
|
|
const marketDataItemCount = |
|
|
const marketDataItemCount = |
|
|
marketDataItems.find((marketDataItem) => { |
|
|
marketDataItems.find((marketDataItem) => { |
|
|
return ( |
|
|
return ( |
|
@ -316,9 +327,6 @@ export class AdminService { |
|
|
); |
|
|
); |
|
|
})?._count ?? 0; |
|
|
})?._count ?? 0; |
|
|
const sectorsCount = sectors ? Object.keys(sectors).length : 0; |
|
|
const sectorsCount = sectors ? Object.keys(sectors).length : 0; |
|
|
const lastMarketPrice = lastMarketPriceMap.get( |
|
|
|
|
|
getAssetProfileIdentifier({ dataSource, symbol }) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
assetClass, |
|
|
assetClass, |
|
@ -544,28 +552,36 @@ export class AdminService { |
|
|
private async getMarketDataForCurrencies(): Promise<AdminMarketData> { |
|
|
private async getMarketDataForCurrencies(): Promise<AdminMarketData> { |
|
|
const currencyPairs = this.exchangeRateDataService.getCurrencyPairs(); |
|
|
const currencyPairs = this.exchangeRateDataService.getCurrencyPairs(); |
|
|
|
|
|
|
|
|
const [marketDataItems, lastMarketPrices] = await Promise.all([ |
|
|
const [lastMarketPrices, marketDataItems] = await Promise.all([ |
|
|
this.prismaService.marketData.groupBy({ |
|
|
|
|
|
_count: true, |
|
|
|
|
|
by: ['dataSource', 'symbol'] |
|
|
|
|
|
}), |
|
|
|
|
|
this.prismaService.marketData.findMany({ |
|
|
this.prismaService.marketData.findMany({ |
|
|
|
|
|
distinct: ['dataSource', 'symbol'], |
|
|
|
|
|
orderBy: { date: 'desc' }, |
|
|
select: { |
|
|
select: { |
|
|
symbol: true, |
|
|
|
|
|
dataSource: true, |
|
|
dataSource: true, |
|
|
marketPrice: true |
|
|
marketPrice: true, |
|
|
|
|
|
symbol: true |
|
|
}, |
|
|
}, |
|
|
where: { |
|
|
where: { |
|
|
symbol: { in: currencyPairs.map(({ symbol }) => symbol) }, |
|
|
dataSource: { |
|
|
dataSource: { in: currencyPairs.map(({ dataSource }) => dataSource) } |
|
|
in: currencyPairs.map(({ dataSource }) => { |
|
|
}, |
|
|
return dataSource; |
|
|
orderBy: { date: 'desc' }, |
|
|
}) |
|
|
distinct: ['symbol', 'dataSource'] |
|
|
}, |
|
|
|
|
|
symbol: { |
|
|
|
|
|
in: currencyPairs.map(({ symbol }) => { |
|
|
|
|
|
return symbol; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}), |
|
|
|
|
|
this.prismaService.marketData.groupBy({ |
|
|
|
|
|
_count: true, |
|
|
|
|
|
by: ['dataSource', 'symbol'] |
|
|
}) |
|
|
}) |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
const lastMarketPriceMap = new Map<string, number>(); |
|
|
const lastMarketPriceMap = new Map<string, number>(); |
|
|
for (const { symbol, dataSource, marketPrice } of lastMarketPrices) { |
|
|
for (const { dataSource, marketPrice, symbol } of lastMarketPrices) { |
|
|
lastMarketPriceMap.set( |
|
|
lastMarketPriceMap.set( |
|
|
getAssetProfileIdentifier({ dataSource, symbol }), |
|
|
getAssetProfileIdentifier({ dataSource, symbol }), |
|
|
marketPrice |
|
|
marketPrice |
|
@ -584,6 +600,10 @@ export class AdminService { |
|
|
await this.orderService.getStatisticsByCurrency(currency)); |
|
|
await this.orderService.getStatisticsByCurrency(currency)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const lastMarketPrice = lastMarketPriceMap.get( |
|
|
|
|
|
getAssetProfileIdentifier({ dataSource, symbol }) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
const marketDataItemCount = |
|
|
const marketDataItemCount = |
|
|
marketDataItems.find((marketDataItem) => { |
|
|
marketDataItems.find((marketDataItem) => { |
|
|
return ( |
|
|
return ( |
|
@ -591,14 +611,12 @@ export class AdminService { |
|
|
marketDataItem.symbol === symbol |
|
|
marketDataItem.symbol === symbol |
|
|
); |
|
|
); |
|
|
})?._count ?? 0; |
|
|
})?._count ?? 0; |
|
|
const lastMarketPrice = lastMarketPriceMap.get( |
|
|
|
|
|
getAssetProfileIdentifier({ dataSource, symbol }) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
activitiesCount, |
|
|
activitiesCount, |
|
|
currency, |
|
|
currency, |
|
|
dataSource, |
|
|
dataSource, |
|
|
|
|
|
lastMarketPrice, |
|
|
marketDataItemCount, |
|
|
marketDataItemCount, |
|
|
symbol, |
|
|
symbol, |
|
|
assetClass: AssetClass.LIQUIDITY, |
|
|
assetClass: AssetClass.LIQUIDITY, |
|
@ -606,7 +624,6 @@ export class AdminService { |
|
|
countriesCount: 0, |
|
|
countriesCount: 0, |
|
|
date: dateOfFirstActivity, |
|
|
date: dateOfFirstActivity, |
|
|
id: undefined, |
|
|
id: undefined, |
|
|
lastMarketPrice, |
|
|
|
|
|
name: symbol, |
|
|
name: symbol, |
|
|
sectorsCount: 0 |
|
|
sectorsCount: 0 |
|
|
}; |
|
|
}; |
|
|