|
@ -369,9 +369,9 @@ export class PortfolioService { |
|
|
): Promise<PortfolioPositionDetail> { |
|
|
): Promise<PortfolioPositionDetail> { |
|
|
const userId = await this.getUserId(aImpersonationId, this.request.user.id); |
|
|
const userId = await this.getUserId(aImpersonationId, this.request.user.id); |
|
|
|
|
|
|
|
|
const orders = ( |
|
|
const orders = (await this.orderService.getOrders({ userId })).filter( |
|
|
await this.orderService.getOrders({ userId, types: ['BUY', 'SELL'] }) |
|
|
(order) => order.symbol === aSymbol |
|
|
).filter((order) => order.symbol === aSymbol); |
|
|
); |
|
|
|
|
|
|
|
|
if (orders.length <= 0) { |
|
|
if (orders.length <= 0) { |
|
|
return { |
|
|
return { |
|
@ -401,17 +401,21 @@ export class PortfolioService { |
|
|
const positionCurrency = orders[0].currency; |
|
|
const positionCurrency = orders[0].currency; |
|
|
const name = orders[0].SymbolProfile?.name ?? ''; |
|
|
const name = orders[0].SymbolProfile?.name ?? ''; |
|
|
|
|
|
|
|
|
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ |
|
|
const portfolioOrders: PortfolioOrder[] = orders |
|
|
currency: order.currency, |
|
|
.filter((order) => { |
|
|
dataSource: order.dataSource, |
|
|
return order.type === 'BUY' || order.type === 'SELL'; |
|
|
date: format(order.date, DATE_FORMAT), |
|
|
}) |
|
|
fee: new Big(order.fee), |
|
|
.map((order) => ({ |
|
|
name: order.SymbolProfile?.name, |
|
|
currency: order.currency, |
|
|
quantity: new Big(order.quantity), |
|
|
dataSource: order.dataSource, |
|
|
symbol: order.symbol, |
|
|
date: format(order.date, DATE_FORMAT), |
|
|
type: order.type, |
|
|
fee: new Big(order.fee), |
|
|
unitPrice: new Big(order.unitPrice) |
|
|
name: order.SymbolProfile?.name, |
|
|
})); |
|
|
quantity: new Big(order.quantity), |
|
|
|
|
|
symbol: order.symbol, |
|
|
|
|
|
type: order.type, |
|
|
|
|
|
unitPrice: new Big(order.unitPrice) |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
const portfolioCalculator = new PortfolioCalculator( |
|
|
const portfolioCalculator = new PortfolioCalculator( |
|
|
this.currentRateService, |
|
|
this.currentRateService, |
|
|