diff --git a/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts b/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts index 5fd3baf8d..2466e81af 100644 --- a/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts +++ b/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts @@ -1,5 +1,4 @@ -import { OrderType } from '@ghostfolio/api/models/order-type'; -import { DataSource } from '@prisma/client'; +import { DataSource, Type as TypeOfOrder } from '@prisma/client'; import Big from 'big.js'; export interface PortfolioOrder { @@ -10,6 +9,6 @@ export interface PortfolioOrder { name: string; quantity: Big; symbol: string; - type: OrderType; + type: TypeOfOrder; unitPrice: Big; } diff --git a/apps/api/src/app/portfolio/portfolio-calculator.spec.ts b/apps/api/src/app/portfolio/portfolio-calculator.spec.ts index 1e3d6b576..ce8320b16 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.spec.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.spec.ts @@ -1,4 +1,3 @@ -import { OrderType } from '@ghostfolio/api/models/order-type'; import { parseDate, resetHours } from '@ghostfolio/common/helper'; import { DataSource } from '@prisma/client'; import Big from 'big.js'; @@ -155,7 +154,7 @@ describe('PortfolioCalculator', () => { name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('144.38'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -166,7 +165,7 @@ describe('PortfolioCalculator', () => { name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('147.99'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -177,7 +176,7 @@ describe('PortfolioCalculator', () => { name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('15'), symbol: 'VTI', - type: OrderType.Sell, + type: 'SELL', unitPrice: new Big('151.41'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -248,7 +247,7 @@ describe('PortfolioCalculator', () => { name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('144.38'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -259,7 +258,7 @@ describe('PortfolioCalculator', () => { name: 'Something else', quantity: new Big('10'), symbol: 'VTX', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('147.99'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -270,7 +269,7 @@ describe('PortfolioCalculator', () => { name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('5'), symbol: 'VTI', - type: OrderType.Sell, + type: 'SELL', unitPrice: new Big('151.41'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -360,7 +359,7 @@ describe('PortfolioCalculator', () => { name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('20'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('197.15'), fee: new Big(0) } @@ -462,7 +461,7 @@ describe('PortfolioCalculator', () => { name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('2021.99'), fee: new Big(0) } @@ -617,7 +616,7 @@ describe('PortfolioCalculator', () => { name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('2021.99'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -628,7 +627,7 @@ describe('PortfolioCalculator', () => { name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', - type: OrderType.Sell, + type: 'SELL', unitPrice: new Big('2412.23'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2391,7 +2390,7 @@ const ordersMixedSymbols: PortfolioOrder[] = [ name: 'Tesla, Inc.', quantity: new Big('50'), symbol: 'TSLA', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('42.97'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2402,7 +2401,7 @@ const ordersMixedSymbols: PortfolioOrder[] = [ name: 'Bitcoin USD', quantity: new Big('0.5614682'), symbol: 'BTCUSD', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('3562.089535970158'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2413,7 +2412,7 @@ const ordersMixedSymbols: PortfolioOrder[] = [ name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('2021.99'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2427,7 +2426,7 @@ const ordersVTI: PortfolioOrder[] = [ name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('144.38'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2438,7 +2437,7 @@ const ordersVTI: PortfolioOrder[] = [ name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('147.99'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2449,7 +2448,7 @@ const ordersVTI: PortfolioOrder[] = [ name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('15'), symbol: 'VTI', - type: OrderType.Sell, + type: 'SELL', unitPrice: new Big('151.41'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2460,7 +2459,7 @@ const ordersVTI: PortfolioOrder[] = [ name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('177.69'), currency: 'USD', dataSource: DataSource.YAHOO, @@ -2471,7 +2470,7 @@ const ordersVTI: PortfolioOrder[] = [ name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', - type: OrderType.Buy, + type: 'BUY', unitPrice: new Big('203.15'), currency: 'USD', dataSource: DataSource.YAHOO, diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index 0a41bcb02..d16ef4b53 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -1,9 +1,9 @@ import { TimelineInfoInterface } from '@ghostfolio/api/app/portfolio/interfaces/timeline-info.interface'; -import { OrderType } from '@ghostfolio/api/models/order-type'; import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper'; import { TimelinePosition } from '@ghostfolio/common/interfaces'; import { Logger } from '@nestjs/common'; +import { Type as TypeOfOrder } from '@prisma/client'; import Big from 'big.js'; import { addDays, @@ -660,14 +660,14 @@ export class PortfolioCalculator { }; } - private getFactor(type: OrderType) { + private getFactor(type: TypeOfOrder) { let factor: number; switch (type) { - case OrderType.Buy: + case 'BUY': factor = 1; break; - case OrderType.Sell: + case 'SELL': factor = -1; break; default: diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index b4312ed3e..fea7c1bb1 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -6,7 +6,6 @@ import { PortfolioOrder } from '@ghostfolio/api/app/portfolio/interfaces/portfol import { TimelineSpecification } from '@ghostfolio/api/app/portfolio/interfaces/timeline-specification.interface'; import { TransactionPoint } from '@ghostfolio/api/app/portfolio/interfaces/transaction-point.interface'; import { PortfolioCalculator } from '@ghostfolio/api/app/portfolio/portfolio-calculator'; -import { OrderType } from '@ghostfolio/api/models/order-type'; import { AccountClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/current-investment'; import { AccountClusterRiskInitialInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/initial-investment'; import { AccountClusterRiskSingleAccount } from '@ghostfolio/api/models/rules/account-cluster-risk/single-account'; @@ -21,11 +20,7 @@ import { ImpersonationService } from '@ghostfolio/api/services/impersonation.ser import { MarketState } from '@ghostfolio/api/services/interfaces/interfaces'; import { EnhancedSymbolProfile } from '@ghostfolio/api/services/interfaces/symbol-profile.interface'; import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service'; -import { - UNKNOWN_KEY, - baseCurrency, - ghostfolioCashSymbol -} from '@ghostfolio/common/config'; +import { UNKNOWN_KEY, baseCurrency } from '@ghostfolio/common/config'; import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper'; import { Accounts, @@ -413,7 +408,7 @@ export class PortfolioService { name: order.SymbolProfile?.name, quantity: new Big(order.quantity), symbol: order.symbol, - type: order.type, + type: order.type, unitPrice: new Big(order.unitPrice) })); @@ -850,8 +845,8 @@ export class PortfolioService { const fees = this.getFees(orders); const firstOrderDate = orders[0]?.date; - const totalBuy = this.getTotalByType(orders, currency, TypeOfOrder.BUY); - const totalSell = this.getTotalByType(orders, currency, TypeOfOrder.SELL); + const totalBuy = this.getTotalByType(orders, currency, 'BUY'); + const totalSell = this.getTotalByType(orders, currency, 'SELL'); const committedFunds = new Big(totalBuy).sub(totalSell); @@ -990,7 +985,7 @@ export class PortfolioService { name: order.SymbolProfile?.name, quantity: new Big(order.quantity), symbol: order.symbol, - type: order.type, + type: order.type, unitPrice: new Big( this.exchangeRateDataService.toCurrency( order.unitPrice, diff --git a/apps/api/src/models/order-type.ts b/apps/api/src/models/order-type.ts deleted file mode 100644 index 4d7a425c3..000000000 --- a/apps/api/src/models/order-type.ts +++ /dev/null @@ -1,8 +0,0 @@ -export enum OrderType { - CorporateAction = 'CORPORATE_ACTION', - Bonus = 'BONUS', - Buy = 'BUY', - Dividend = 'DIVIDEND', - Sell = 'SELL', - Split = 'SPLIT' -} diff --git a/apps/api/src/models/order.ts b/apps/api/src/models/order.ts index 48928bc66..8882ebe37 100644 --- a/apps/api/src/models/order.ts +++ b/apps/api/src/models/order.ts @@ -1,8 +1,7 @@ -import { Account, SymbolProfile } from '@prisma/client'; +import { Account, SymbolProfile, Type as TypeOfOrder } from '@prisma/client'; import { v4 as uuidv4 } from 'uuid'; import { IOrder } from '../services/interfaces/interfaces'; -import { OrderType } from './order-type'; export class Order { private account: Account; @@ -15,7 +14,7 @@ export class Order { private symbol: string; private symbolProfile: SymbolProfile; private total: number; - private type: OrderType; + private type: TypeOfOrder; private unitPrice: number; public constructor(data: IOrder) { diff --git a/apps/api/src/services/interfaces/interfaces.ts b/apps/api/src/services/interfaces/interfaces.ts index d4913a83b..c7d3a08f7 100644 --- a/apps/api/src/services/interfaces/interfaces.ts +++ b/apps/api/src/services/interfaces/interfaces.ts @@ -3,11 +3,10 @@ import { AssetClass, AssetSubClass, DataSource, - SymbolProfile + SymbolProfile, + Type as TypeOfOrder } from '@prisma/client'; -import { OrderType } from '../../models/order-type'; - export const MarketState = { closed: 'closed', delayed: 'delayed', @@ -24,7 +23,7 @@ export interface IOrder { quantity: number; symbol: string; symbolProfile: SymbolProfile; - type: OrderType; + type: TypeOfOrder; unitPrice: number; }