Replace OrderType with Type (prisma) (#560)

pull/561/head
Thomas Kaul 3 years ago committed by GitHub
parent 7772684413
commit e78755c280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;
}

@ -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,

@ -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:

@ -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: <OrderType>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: <OrderType>order.type,
type: order.type,
unitPrice: new Big(
this.exchangeRateDataService.toCurrency(
order.unitPrice,

@ -1,8 +0,0 @@
export enum OrderType {
CorporateAction = 'CORPORATE_ACTION',
Bonus = 'BONUS',
Buy = 'BUY',
Dividend = 'DIVIDEND',
Sell = 'SELL',
Split = 'SPLIT'
}

@ -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) {

@ -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;
}

Loading…
Cancel
Save