|
|
@ -18,6 +18,7 @@ import { REQUEST } from '@nestjs/core';
|
|
|
|
import { DataSource } from '@prisma/client';
|
|
|
|
import { DataSource } from '@prisma/client';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
add,
|
|
|
|
add,
|
|
|
|
|
|
|
|
addMonths,
|
|
|
|
endOfToday,
|
|
|
|
endOfToday,
|
|
|
|
format,
|
|
|
|
format,
|
|
|
|
getDate,
|
|
|
|
getDate,
|
|
|
@ -227,19 +228,18 @@ export class PortfolioService {
|
|
|
|
impersonationUserId || this.request.user.id
|
|
|
|
impersonationUserId || this.request.user.id
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const positions = portfolio.getPositions(new Date())[aSymbol];
|
|
|
|
const position = portfolio.getPositions(new Date())[aSymbol];
|
|
|
|
|
|
|
|
|
|
|
|
if (positions) {
|
|
|
|
if (position) {
|
|
|
|
let {
|
|
|
|
const {
|
|
|
|
averagePrice,
|
|
|
|
averagePrice,
|
|
|
|
currency,
|
|
|
|
currency,
|
|
|
|
firstBuyDate,
|
|
|
|
firstBuyDate,
|
|
|
|
investment,
|
|
|
|
investment,
|
|
|
|
marketPrice,
|
|
|
|
|
|
|
|
quantity,
|
|
|
|
quantity,
|
|
|
|
transactionCount
|
|
|
|
transactionCount
|
|
|
|
} = portfolio.getPositions(new Date())[aSymbol];
|
|
|
|
} = position;
|
|
|
|
|
|
|
|
let marketPrice = position.marketPrice;
|
|
|
|
const orders = portfolio.getOrders(aSymbol);
|
|
|
|
const orders = portfolio.getOrders(aSymbol);
|
|
|
|
|
|
|
|
|
|
|
|
const historicalData = await this.dataProviderService.getHistorical(
|
|
|
|
const historicalData = await this.dataProviderService.getHistorical(
|
|
|
@ -267,13 +267,14 @@ export class PortfolioService {
|
|
|
|
isSameDay(currentDate, parseISO(orders[0]?.getDate())) ||
|
|
|
|
isSameDay(currentDate, parseISO(orders[0]?.getDate())) ||
|
|
|
|
isAfter(currentDate, parseISO(orders[0]?.getDate()))
|
|
|
|
isAfter(currentDate, parseISO(orders[0]?.getDate()))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// Get snapshot of first day of month
|
|
|
|
// Get snapshot of first day of next month
|
|
|
|
const snapshot = portfolio.get(setDate(currentDate, 1))[0]
|
|
|
|
const snapshot = portfolio.get(
|
|
|
|
.positions[aSymbol];
|
|
|
|
addMonths(setDate(currentDate, 1), 1)
|
|
|
|
|
|
|
|
)?.[0]?.positions[aSymbol];
|
|
|
|
orders.shift();
|
|
|
|
orders.shift();
|
|
|
|
|
|
|
|
|
|
|
|
if (snapshot?.averagePrice) {
|
|
|
|
if (snapshot?.averagePrice) {
|
|
|
|
currentAveragePrice = snapshot?.averagePrice;
|
|
|
|
currentAveragePrice = snapshot.averagePrice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|