You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

105 lines
2.0 KiB

import {
COMMENT_MAXIMUM_LENGTH,
SYMBOL_MAXIMUM_LENGTH
} from '@ghostfolio/common/config';
import { IsAfter1970Constraint } from '@ghostfolio/common/validator-constraints/is-after-1970';
import { IsCurrencyCode } from '@ghostfolio/common/validators/is-currency-code';
import {
AssetClass,
AssetSubClass,
DataSource,
Type
} from '@ghostfolio/prisma/enums';
import { Transform, TransformFnParams } from 'class-transformer';
import {
ArrayUnique,
IsArray,
IsBoolean,
IsEnum,
IsISO8601,
IsNotEmpty,
IsNumber,
IsOptional,
IsPositive,
IsString,
MaxLength,
Min,
Validate
} from 'class-validator';
import { isString } from 'lodash-es';
export class CreateOrderDto {
@IsOptional()
@IsString()
accountId?: string;
@IsEnum(AssetClass)
@IsOptional()
assetClass?: AssetClass;
@IsEnum(AssetSubClass)
@IsOptional()
assetSubClass?: AssetSubClass;
@IsOptional()
@IsString()
@MaxLength(COMMENT_MAXIMUM_LENGTH)
@Transform(({ value }: TransformFnParams) =>
isString(value) ? value.trim() : value
)
comment?: string | null;
@IsCurrencyCode()
currency: string;
@IsCurrencyCode()
@IsOptional()
customCurrency?: string;
@IsEnum(DataSource)
@IsOptional() // Optional for type FEE, INTEREST, and LIABILITY (default data source is resolved in the backend)
dataSource?: DataSource;
@IsISO8601()
@Validate(IsAfter1970Constraint)
date: string;
@IsNumber()
@IsOptional()
@IsPositive()
exchangeRate?: number | null;
@IsNumber()
@Min(0)
fee: number;
@IsNumber()
@Min(0)
quantity: number;
@IsNotEmpty()
@IsString()
@MaxLength(SYMBOL_MAXIMUM_LENGTH)
@Transform(({ value }: TransformFnParams) =>
isString(value) ? value.trim() : value
)
symbol: string;
@ArrayUnique()
@IsArray()
@IsOptional()
@IsString({ each: true })
tags?: string[];
@IsEnum(Type)
type: Type;
@IsNumber()
@Min(0)
unitPrice: number;
@IsBoolean()
@IsOptional()
updateAccountBalance?: boolean;
}