Replace OrderType with Type (prisma) (#560)
This commit is contained in:
parent
7772684413
commit
e78755c280
@ -1,5 +1,4 @@
|
|||||||
import { OrderType } from '@ghostfolio/api/models/order-type';
|
import { DataSource, Type as TypeOfOrder } from '@prisma/client';
|
||||||
import { DataSource } from '@prisma/client';
|
|
||||||
import Big from 'big.js';
|
import Big from 'big.js';
|
||||||
|
|
||||||
export interface PortfolioOrder {
|
export interface PortfolioOrder {
|
||||||
@ -10,6 +9,6 @@ export interface PortfolioOrder {
|
|||||||
name: string;
|
name: string;
|
||||||
quantity: Big;
|
quantity: Big;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
type: OrderType;
|
type: TypeOfOrder;
|
||||||
unitPrice: Big;
|
unitPrice: Big;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { OrderType } from '@ghostfolio/api/models/order-type';
|
|
||||||
import { parseDate, resetHours } from '@ghostfolio/common/helper';
|
import { parseDate, resetHours } from '@ghostfolio/common/helper';
|
||||||
import { DataSource } from '@prisma/client';
|
import { DataSource } from '@prisma/client';
|
||||||
import Big from 'big.js';
|
import Big from 'big.js';
|
||||||
@ -155,7 +154,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('144.38'),
|
unitPrice: new Big('144.38'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -166,7 +165,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('147.99'),
|
unitPrice: new Big('147.99'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -177,7 +176,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('15'),
|
quantity: new Big('15'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Sell,
|
type: 'SELL',
|
||||||
unitPrice: new Big('151.41'),
|
unitPrice: new Big('151.41'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -248,7 +247,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('144.38'),
|
unitPrice: new Big('144.38'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -259,7 +258,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Something else',
|
name: 'Something else',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTX',
|
symbol: 'VTX',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('147.99'),
|
unitPrice: new Big('147.99'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -270,7 +269,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('5'),
|
quantity: new Big('5'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Sell,
|
type: 'SELL',
|
||||||
unitPrice: new Big('151.41'),
|
unitPrice: new Big('151.41'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -360,7 +359,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('20'),
|
quantity: new Big('20'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('197.15'),
|
unitPrice: new Big('197.15'),
|
||||||
fee: new Big(0)
|
fee: new Big(0)
|
||||||
}
|
}
|
||||||
@ -462,7 +461,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Amazon.com, Inc.',
|
name: 'Amazon.com, Inc.',
|
||||||
quantity: new Big('5'),
|
quantity: new Big('5'),
|
||||||
symbol: 'AMZN',
|
symbol: 'AMZN',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('2021.99'),
|
unitPrice: new Big('2021.99'),
|
||||||
fee: new Big(0)
|
fee: new Big(0)
|
||||||
}
|
}
|
||||||
@ -617,7 +616,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Amazon.com, Inc.',
|
name: 'Amazon.com, Inc.',
|
||||||
quantity: new Big('5'),
|
quantity: new Big('5'),
|
||||||
symbol: 'AMZN',
|
symbol: 'AMZN',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('2021.99'),
|
unitPrice: new Big('2021.99'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -628,7 +627,7 @@ describe('PortfolioCalculator', () => {
|
|||||||
name: 'Amazon.com, Inc.',
|
name: 'Amazon.com, Inc.',
|
||||||
quantity: new Big('5'),
|
quantity: new Big('5'),
|
||||||
symbol: 'AMZN',
|
symbol: 'AMZN',
|
||||||
type: OrderType.Sell,
|
type: 'SELL',
|
||||||
unitPrice: new Big('2412.23'),
|
unitPrice: new Big('2412.23'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2391,7 +2390,7 @@ const ordersMixedSymbols: PortfolioOrder[] = [
|
|||||||
name: 'Tesla, Inc.',
|
name: 'Tesla, Inc.',
|
||||||
quantity: new Big('50'),
|
quantity: new Big('50'),
|
||||||
symbol: 'TSLA',
|
symbol: 'TSLA',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('42.97'),
|
unitPrice: new Big('42.97'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2402,7 +2401,7 @@ const ordersMixedSymbols: PortfolioOrder[] = [
|
|||||||
name: 'Bitcoin USD',
|
name: 'Bitcoin USD',
|
||||||
quantity: new Big('0.5614682'),
|
quantity: new Big('0.5614682'),
|
||||||
symbol: 'BTCUSD',
|
symbol: 'BTCUSD',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('3562.089535970158'),
|
unitPrice: new Big('3562.089535970158'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2413,7 +2412,7 @@ const ordersMixedSymbols: PortfolioOrder[] = [
|
|||||||
name: 'Amazon.com, Inc.',
|
name: 'Amazon.com, Inc.',
|
||||||
quantity: new Big('5'),
|
quantity: new Big('5'),
|
||||||
symbol: 'AMZN',
|
symbol: 'AMZN',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('2021.99'),
|
unitPrice: new Big('2021.99'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2427,7 +2426,7 @@ const ordersVTI: PortfolioOrder[] = [
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('144.38'),
|
unitPrice: new Big('144.38'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2438,7 +2437,7 @@ const ordersVTI: PortfolioOrder[] = [
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('147.99'),
|
unitPrice: new Big('147.99'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2449,7 +2448,7 @@ const ordersVTI: PortfolioOrder[] = [
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('15'),
|
quantity: new Big('15'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Sell,
|
type: 'SELL',
|
||||||
unitPrice: new Big('151.41'),
|
unitPrice: new Big('151.41'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2460,7 +2459,7 @@ const ordersVTI: PortfolioOrder[] = [
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('177.69'),
|
unitPrice: new Big('177.69'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
@ -2471,7 +2470,7 @@ const ordersVTI: PortfolioOrder[] = [
|
|||||||
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
name: 'Vanguard Total Stock Market Index Fund ETF Shares',
|
||||||
quantity: new Big('10'),
|
quantity: new Big('10'),
|
||||||
symbol: 'VTI',
|
symbol: 'VTI',
|
||||||
type: OrderType.Buy,
|
type: 'BUY',
|
||||||
unitPrice: new Big('203.15'),
|
unitPrice: new Big('203.15'),
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
dataSource: DataSource.YAHOO,
|
dataSource: DataSource.YAHOO,
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { TimelineInfoInterface } from '@ghostfolio/api/app/portfolio/interfaces/timeline-info.interface';
|
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 { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces';
|
||||||
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
|
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
|
||||||
import { TimelinePosition } from '@ghostfolio/common/interfaces';
|
import { TimelinePosition } from '@ghostfolio/common/interfaces';
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { Type as TypeOfOrder } from '@prisma/client';
|
||||||
import Big from 'big.js';
|
import Big from 'big.js';
|
||||||
import {
|
import {
|
||||||
addDays,
|
addDays,
|
||||||
@ -660,14 +660,14 @@ export class PortfolioCalculator {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFactor(type: OrderType) {
|
private getFactor(type: TypeOfOrder) {
|
||||||
let factor: number;
|
let factor: number;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case OrderType.Buy:
|
case 'BUY':
|
||||||
factor = 1;
|
factor = 1;
|
||||||
break;
|
break;
|
||||||
case OrderType.Sell:
|
case 'SELL':
|
||||||
factor = -1;
|
factor = -1;
|
||||||
break;
|
break;
|
||||||
default:
|
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 { TimelineSpecification } from '@ghostfolio/api/app/portfolio/interfaces/timeline-specification.interface';
|
||||||
import { TransactionPoint } from '@ghostfolio/api/app/portfolio/interfaces/transaction-point.interface';
|
import { TransactionPoint } from '@ghostfolio/api/app/portfolio/interfaces/transaction-point.interface';
|
||||||
import { PortfolioCalculator } from '@ghostfolio/api/app/portfolio/portfolio-calculator';
|
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 { AccountClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/current-investment';
|
||||||
import { AccountClusterRiskInitialInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/initial-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';
|
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 { MarketState } from '@ghostfolio/api/services/interfaces/interfaces';
|
||||||
import { EnhancedSymbolProfile } from '@ghostfolio/api/services/interfaces/symbol-profile.interface';
|
import { EnhancedSymbolProfile } from '@ghostfolio/api/services/interfaces/symbol-profile.interface';
|
||||||
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service';
|
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service';
|
||||||
import {
|
import { UNKNOWN_KEY, baseCurrency } from '@ghostfolio/common/config';
|
||||||
UNKNOWN_KEY,
|
|
||||||
baseCurrency,
|
|
||||||
ghostfolioCashSymbol
|
|
||||||
} from '@ghostfolio/common/config';
|
|
||||||
import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper';
|
import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper';
|
||||||
import {
|
import {
|
||||||
Accounts,
|
Accounts,
|
||||||
@ -413,7 +408,7 @@ export class PortfolioService {
|
|||||||
name: order.SymbolProfile?.name,
|
name: order.SymbolProfile?.name,
|
||||||
quantity: new Big(order.quantity),
|
quantity: new Big(order.quantity),
|
||||||
symbol: order.symbol,
|
symbol: order.symbol,
|
||||||
type: <OrderType>order.type,
|
type: order.type,
|
||||||
unitPrice: new Big(order.unitPrice)
|
unitPrice: new Big(order.unitPrice)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -850,8 +845,8 @@ export class PortfolioService {
|
|||||||
const fees = this.getFees(orders);
|
const fees = this.getFees(orders);
|
||||||
const firstOrderDate = orders[0]?.date;
|
const firstOrderDate = orders[0]?.date;
|
||||||
|
|
||||||
const totalBuy = this.getTotalByType(orders, currency, TypeOfOrder.BUY);
|
const totalBuy = this.getTotalByType(orders, currency, 'BUY');
|
||||||
const totalSell = this.getTotalByType(orders, currency, TypeOfOrder.SELL);
|
const totalSell = this.getTotalByType(orders, currency, 'SELL');
|
||||||
|
|
||||||
const committedFunds = new Big(totalBuy).sub(totalSell);
|
const committedFunds = new Big(totalBuy).sub(totalSell);
|
||||||
|
|
||||||
@ -990,7 +985,7 @@ export class PortfolioService {
|
|||||||
name: order.SymbolProfile?.name,
|
name: order.SymbolProfile?.name,
|
||||||
quantity: new Big(order.quantity),
|
quantity: new Big(order.quantity),
|
||||||
symbol: order.symbol,
|
symbol: order.symbol,
|
||||||
type: <OrderType>order.type,
|
type: order.type,
|
||||||
unitPrice: new Big(
|
unitPrice: new Big(
|
||||||
this.exchangeRateDataService.toCurrency(
|
this.exchangeRateDataService.toCurrency(
|
||||||
order.unitPrice,
|
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 { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
import { IOrder } from '../services/interfaces/interfaces';
|
import { IOrder } from '../services/interfaces/interfaces';
|
||||||
import { OrderType } from './order-type';
|
|
||||||
|
|
||||||
export class Order {
|
export class Order {
|
||||||
private account: Account;
|
private account: Account;
|
||||||
@ -15,7 +14,7 @@ export class Order {
|
|||||||
private symbol: string;
|
private symbol: string;
|
||||||
private symbolProfile: SymbolProfile;
|
private symbolProfile: SymbolProfile;
|
||||||
private total: number;
|
private total: number;
|
||||||
private type: OrderType;
|
private type: TypeOfOrder;
|
||||||
private unitPrice: number;
|
private unitPrice: number;
|
||||||
|
|
||||||
public constructor(data: IOrder) {
|
public constructor(data: IOrder) {
|
||||||
|
@ -3,11 +3,10 @@ import {
|
|||||||
AssetClass,
|
AssetClass,
|
||||||
AssetSubClass,
|
AssetSubClass,
|
||||||
DataSource,
|
DataSource,
|
||||||
SymbolProfile
|
SymbolProfile,
|
||||||
|
Type as TypeOfOrder
|
||||||
} from '@prisma/client';
|
} from '@prisma/client';
|
||||||
|
|
||||||
import { OrderType } from '../../models/order-type';
|
|
||||||
|
|
||||||
export const MarketState = {
|
export const MarketState = {
|
||||||
closed: 'closed',
|
closed: 'closed',
|
||||||
delayed: 'delayed',
|
delayed: 'delayed',
|
||||||
@ -24,7 +23,7 @@ export interface IOrder {
|
|||||||
quantity: number;
|
quantity: number;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
symbolProfile: SymbolProfile;
|
symbolProfile: SymbolProfile;
|
||||||
type: OrderType;
|
type: TypeOfOrder;
|
||||||
unitPrice: number;
|
unitPrice: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user