@fintekkers/ledger-models 0.1.119 → 0.1.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmrc.example +4 -0
- package/catalog/fields.json +275 -0
- package/catalog/measures.json +259 -0
- package/node/fintekkers/models/portfolio/portfolio_pb.js +13 -19
- package/node/fintekkers/models/position/field_pb.js +1 -7
- package/node/fintekkers/models/position/measure_pb.d.ts +18 -0
- package/node/fintekkers/models/position/measure_pb.js +20 -8
- package/node/fintekkers/models/position/position_filter_pb.js +7 -13
- package/node/fintekkers/models/position/position_pb.d.ts +7 -0
- package/node/fintekkers/models/position/position_pb.js +64 -17
- package/node/fintekkers/models/position/position_status_pb.js +1 -7
- package/node/fintekkers/models/position/position_util_pb.js +11 -17
- package/node/fintekkers/models/price/price_pb.d.ts +4 -0
- package/node/fintekkers/models/price/price_pb.js +45 -19
- package/node/fintekkers/models/price/price_type_grpc_pb.js +1 -0
- package/node/fintekkers/models/price/price_type_pb.d.ts +15 -0
- package/node/fintekkers/models/price/price_type_pb.js +30 -0
- package/node/fintekkers/models/security/bond/auction_type_pb.js +1 -7
- package/node/fintekkers/models/security/bond/issuance_pb.js +17 -23
- package/node/fintekkers/models/security/coupon_frequency_pb.js +1 -7
- package/node/fintekkers/models/security/coupon_type_pb.js +1 -7
- package/node/fintekkers/models/security/identifier/identifier_pb.js +9 -15
- package/node/fintekkers/models/security/identifier/identifier_type_pb.d.ts +1 -0
- package/node/fintekkers/models/security/identifier/identifier_type_pb.js +2 -7
- package/node/fintekkers/models/security/index/index_type_grpc_pb.js +1 -0
- package/node/fintekkers/models/security/index/index_type_pb.d.ts +22 -0
- package/node/fintekkers/models/security/index/index_type_pb.js +37 -0
- package/node/fintekkers/models/security/index_composition_pb.d.ts +126 -0
- package/node/fintekkers/models/security/index_composition_pb.js +992 -0
- package/node/fintekkers/models/security/security_pb.d.ts +382 -0
- package/node/fintekkers/models/security/security_pb.js +3183 -57
- package/node/fintekkers/models/security/security_quantity_type_pb.js +1 -7
- package/node/fintekkers/models/security/security_type_pb.d.ts +3 -0
- package/node/fintekkers/models/security/security_type_pb.js +5 -8
- package/node/fintekkers/models/security/tenor_pb.js +9 -15
- package/node/fintekkers/models/security/tenor_type_pb.js +1 -7
- package/node/fintekkers/models/strategy/strategy_allocation_pb.js +13 -19
- package/node/fintekkers/models/strategy/strategy_pb.js +14 -20
- package/node/fintekkers/models/transaction/transaction_pb.js +24 -30
- package/node/fintekkers/models/transaction/transaction_type_pb.js +1 -7
- package/node/fintekkers/models/util/api/api_key_pb.js +10 -16
- package/node/fintekkers/models/util/currency_pb.d.ts +27 -0
- package/node/fintekkers/models/util/currency_pb.js +170 -0
- package/node/fintekkers/models/util/date_range_pb.js +8 -14
- package/node/fintekkers/models/util/decimal_value_pb.js +4 -10
- package/node/fintekkers/models/util/endpoint_pb.js +7 -13
- package/node/fintekkers/models/util/local_date_pb.js +5 -11
- package/node/fintekkers/models/util/local_timestamp_pb.js +5 -11
- package/node/fintekkers/models/util/lock/node_partition_pb.js +9 -15
- package/node/fintekkers/models/util/lock/node_state_pb.js +10 -16
- package/node/fintekkers/models/util/uuid_pb.js +3 -9
- package/node/fintekkers/models/valuation/cashflow_pb.d.ts +57 -0
- package/node/fintekkers/models/valuation/cashflow_pb.js +401 -0
- package/node/fintekkers/requests/index_composition/create_index_composition_request_pb.d.ts +79 -0
- package/node/fintekkers/requests/index_composition/create_index_composition_request_pb.js +599 -0
- package/node/fintekkers/requests/index_composition/get_index_composition_request_pb.d.ts +84 -0
- package/node/fintekkers/requests/index_composition/get_index_composition_request_pb.js +624 -0
- package/node/fintekkers/requests/portfolio/create_portfolio_request_pb.js +7 -13
- package/node/fintekkers/requests/portfolio/create_portfolio_response_pb.js +8 -14
- package/node/fintekkers/requests/portfolio/query_portfolio_request_pb.d.ts +3 -0
- package/node/fintekkers/requests/portfolio/query_portfolio_request_pb.js +39 -15
- package/node/fintekkers/requests/portfolio/query_portfolio_response_pb.js +8 -14
- package/node/fintekkers/requests/position/query_position_request_pb.js +15 -27
- package/node/fintekkers/requests/position/query_position_response_pb.js +10 -16
- package/node/fintekkers/requests/price/create_price_request_pb.js +7 -13
- package/node/fintekkers/requests/price/create_price_response_pb.js +8 -14
- package/node/fintekkers/requests/price/query_price_request_pb.js +12 -18
- package/node/fintekkers/requests/price/query_price_response_pb.js +8 -14
- package/node/fintekkers/requests/security/create_security_request_pb.js +7 -13
- package/node/fintekkers/requests/security/create_security_response_pb.js +9 -15
- package/node/fintekkers/requests/security/get_field_values_request_pb.js +7 -13
- package/node/fintekkers/requests/security/get_field_values_response_pb.js +7 -13
- package/node/fintekkers/requests/security/get_fields_response_pb.js +8 -17
- package/node/fintekkers/requests/security/query_security_request_pb.d.ts +3 -0
- package/node/fintekkers/requests/security/query_security_request_pb.js +39 -15
- package/node/fintekkers/requests/security/query_security_response_pb.js +9 -15
- package/node/fintekkers/requests/transaction/create_transaction_request_pb.js +7 -13
- package/node/fintekkers/requests/transaction/create_transaction_response_pb.js +8 -14
- package/node/fintekkers/requests/transaction/query_transaction_request_pb.js +10 -16
- package/node/fintekkers/requests/transaction/query_transaction_response_pb.js +9 -15
- package/node/fintekkers/requests/util/delete_request_pb.d.ts +135 -0
- package/node/fintekkers/requests/util/delete_request_pb.js +1051 -0
- package/node/fintekkers/requests/util/errors/error_pb.js +7 -13
- package/node/fintekkers/requests/util/errors/message_pb.js +6 -12
- package/node/fintekkers/requests/util/errors/summary_pb.js +4 -10
- package/node/fintekkers/requests/util/lock/lock_request_pb.js +8 -14
- package/node/fintekkers/requests/util/lock/lock_response_pb.js +9 -15
- package/node/fintekkers/requests/util/operation_pb.js +1 -7
- package/node/fintekkers/requests/valuation/curve_request_pb.d.ts +85 -0
- package/node/fintekkers/requests/valuation/curve_request_pb.js +646 -0
- package/node/fintekkers/requests/valuation/curve_response_pb.d.ts +105 -0
- package/node/fintekkers/requests/valuation/curve_response_pb.js +806 -0
- package/node/fintekkers/requests/valuation/product_inputs.test.ts +172 -0
- package/node/fintekkers/requests/valuation/product_inputs_pb.d.ts +137 -0
- package/node/fintekkers/requests/valuation/product_inputs_pb.js +987 -0
- package/node/fintekkers/requests/valuation/valuation_request_pb.d.ts +19 -0
- package/node/fintekkers/requests/valuation/valuation_request_pb.js +168 -22
- package/node/fintekkers/requests/valuation/valuation_response_pb.d.ts +13 -0
- package/node/fintekkers/requests/valuation/valuation_response_pb.js +118 -16
- package/node/fintekkers/services/index-composition-service/index_composition_service_grpc_pb.d.ts +60 -0
- package/node/fintekkers/services/index-composition-service/index_composition_service_grpc_pb.js +87 -0
- package/node/fintekkers/services/index-composition-service/index_composition_service_pb.d.ts +9 -0
- package/node/fintekkers/services/index-composition-service/index_composition_service_pb.js +21 -0
- package/node/fintekkers/services/lock-service/lock_service_grpc_pb.js +22 -22
- package/node/fintekkers/services/lock-service/lock_service_pb.js +15 -21
- package/node/fintekkers/services/portfolio-service/portfolio_service_grpc_pb.d.ts +18 -0
- package/node/fintekkers/services/portfolio-service/portfolio_service_grpc_pb.js +39 -5
- package/node/fintekkers/services/portfolio-service/portfolio_service_pb.d.ts +1 -0
- package/node/fintekkers/services/portfolio-service/portfolio_service_pb.js +3 -7
- package/node/fintekkers/services/position-service/position_service_grpc_pb.d.ts +37 -0
- package/node/fintekkers/services/position-service/position_service_grpc_pb.js +64 -6
- package/node/fintekkers/services/position-service/position_service_pb.d.ts +3 -0
- package/node/fintekkers/services/position-service/position_service_pb.js +7 -7
- package/node/fintekkers/services/price-service/price_service_grpc_pb.js +5 -5
- package/node/fintekkers/services/price-service/price_service_pb.js +1 -7
- package/node/fintekkers/services/security-service/security_service_grpc_pb.d.ts +18 -0
- package/node/fintekkers/services/security-service/security_service_grpc_pb.js +43 -9
- package/node/fintekkers/services/security-service/security_service_pb.d.ts +1 -0
- package/node/fintekkers/services/security-service/security_service_pb.js +3 -7
- package/node/fintekkers/services/transaction-service/transaction_service_grpc_pb.d.ts +55 -0
- package/node/fintekkers/services/transaction-service/transaction_service_grpc_pb.js +97 -5
- package/node/fintekkers/services/transaction-service/transaction_service_pb.d.ts +4 -0
- package/node/fintekkers/services/transaction-service/transaction_service_pb.js +9 -7
- package/node/fintekkers/services/valuation-service/valuation_service_grpc_pb.d.ts +19 -0
- package/node/fintekkers/services/valuation-service/valuation_service_grpc_pb.js +37 -2
- package/node/fintekkers/services/valuation-service/valuation_service_pb.d.ts +2 -0
- package/node/fintekkers/services/valuation-service/valuation_service_pb.js +5 -7
- package/node/wrappers/models/portfolio/portfolio.js.map +1 -1
- package/node/wrappers/models/portfolio/portfolio.test.d.ts +2 -0
- package/node/wrappers/models/portfolio/portfolio.test.js +29 -0
- package/node/wrappers/models/portfolio/portfolio.test.js.map +1 -0
- package/node/wrappers/models/portfolio/portfolio.test.ts +28 -0
- package/node/wrappers/models/position/position.js +25 -13
- package/node/wrappers/models/position/position.js.map +1 -1
- package/node/wrappers/models/position/position.test.js +20 -0
- package/node/wrappers/models/position/position.test.js.map +1 -1
- package/node/wrappers/models/position/position.test.ts +23 -0
- package/node/wrappers/models/position/position.ts +27 -13
- package/node/wrappers/models/position/positionfilter.js +1 -1
- package/node/wrappers/models/position/positionfilter.js.map +1 -1
- package/node/wrappers/models/position/positionfilter.test.js.map +1 -1
- package/node/wrappers/models/price/Price.cash.test.d.ts +1 -0
- package/node/wrappers/models/price/Price.cash.test.js +42 -0
- package/node/wrappers/models/price/Price.cash.test.js.map +1 -0
- package/node/wrappers/models/price/Price.cash.test.ts +43 -0
- package/node/wrappers/models/price/Price.d.ts +38 -0
- package/node/wrappers/models/price/Price.js +111 -0
- package/node/wrappers/models/price/Price.js.map +1 -0
- package/node/wrappers/models/price/Price.test.d.ts +1 -0
- package/node/wrappers/models/price/Price.test.js +55 -0
- package/node/wrappers/models/price/Price.test.js.map +1 -0
- package/node/wrappers/models/price/Price.test.ts +63 -0
- package/node/wrappers/models/price/Price.ts +123 -0
- package/node/wrappers/models/security/BondSecurity.d.ts +17 -2
- package/node/wrappers/models/security/BondSecurity.js +59 -11
- package/node/wrappers/models/security/BondSecurity.js.map +1 -1
- package/node/wrappers/models/security/BondSecurity.priceScale.test.d.ts +1 -0
- package/node/wrappers/models/security/BondSecurity.priceScale.test.js +36 -0
- package/node/wrappers/models/security/BondSecurity.priceScale.test.js.map +1 -0
- package/node/wrappers/models/security/BondSecurity.priceScale.test.ts +36 -0
- package/node/wrappers/models/security/BondSecurity.test.js +34 -1
- package/node/wrappers/models/security/BondSecurity.test.js.map +1 -1
- package/node/wrappers/models/security/BondSecurity.test.ts +42 -1
- package/node/wrappers/models/security/BondSecurity.ts +63 -11
- package/node/wrappers/models/security/security-roundtrip.test.d.ts +1 -0
- package/node/wrappers/models/security/security-roundtrip.test.js +173 -0
- package/node/wrappers/models/security/security-roundtrip.test.js.map +1 -0
- package/node/wrappers/models/security/security-roundtrip.test.ts +192 -0
- package/node/wrappers/models/security/security.d.ts +8 -0
- package/node/wrappers/models/security/security.js +24 -2
- package/node/wrappers/models/security/security.js.map +1 -1
- package/node/wrappers/models/security/security.ts +26 -2
- package/node/wrappers/models/security/term.js +31 -6
- package/node/wrappers/models/security/term.js.map +1 -1
- package/node/wrappers/models/security/term.test.js +21 -2
- package/node/wrappers/models/security/term.test.js.map +1 -1
- package/node/wrappers/models/security/term.test.ts +28 -2
- package/node/wrappers/models/security/term.ts +34 -6
- package/node/wrappers/models/transaction/transaction.d.ts +59 -1
- package/node/wrappers/models/transaction/transaction.derived.test.d.ts +1 -0
- package/node/wrappers/models/transaction/transaction.derived.test.js +199 -0
- package/node/wrappers/models/transaction/transaction.derived.test.js.map +1 -0
- package/node/wrappers/models/transaction/transaction.derived.test.ts +251 -0
- package/node/wrappers/models/transaction/transaction.js +350 -2
- package/node/wrappers/models/transaction/transaction.js.map +1 -1
- package/node/wrappers/models/transaction/transaction.ts +416 -2
- package/node/wrappers/models/transaction/transaction_constructor.test.d.ts +1 -0
- package/node/wrappers/models/transaction/transaction_constructor.test.js +100 -0
- package/node/wrappers/models/transaction/transaction_constructor.test.js.map +1 -0
- package/node/wrappers/models/transaction/transaction_constructor.test.ts +111 -0
- package/node/wrappers/models/transaction/transaction_type.js.map +1 -1
- package/node/wrappers/models/utils/datetime.d.ts +6 -0
- package/node/wrappers/models/utils/datetime.js +14 -6
- package/node/wrappers/models/utils/datetime.js.map +1 -1
- package/node/wrappers/models/utils/datetime.ts +15 -6
- package/node/wrappers/models/utils/protoEnum.js.map +1 -1
- package/node/wrappers/models/utils/requestcontext.d.ts +17 -3
- package/node/wrappers/models/utils/requestcontext.js +39 -7
- package/node/wrappers/models/utils/requestcontext.js.map +1 -1
- package/node/wrappers/models/utils/requestcontext.test.d.ts +1 -0
- package/node/wrappers/models/utils/requestcontext.test.js +108 -0
- package/node/wrappers/models/utils/requestcontext.test.js.map +1 -0
- package/node/wrappers/models/utils/requestcontext.test.ts +85 -0
- package/node/wrappers/models/utils/requestcontext.ts +49 -9
- package/node/wrappers/models/utils/serialization.d.ts +2 -1
- package/node/wrappers/models/utils/serialization.js +4 -0
- package/node/wrappers/models/utils/serialization.js.map +1 -1
- package/node/wrappers/models/utils/serialization.test.js +15 -0
- package/node/wrappers/models/utils/serialization.test.js.map +1 -1
- package/node/wrappers/models/utils/serialization.test.ts +19 -1
- package/node/wrappers/models/utils/serialization.ts +5 -4
- package/node/wrappers/models/utils/serialization.util.js.map +1 -1
- package/node/wrappers/models/utils/uuid.js +9 -1
- package/node/wrappers/models/utils/uuid.js.map +1 -1
- package/node/wrappers/models/utils/uuid.test.js +22 -4
- package/node/wrappers/models/utils/uuid.test.js.map +1 -1
- package/node/wrappers/models/utils/uuid.test.ts +26 -5
- package/node/wrappers/models/utils/uuid.ts +7 -1
- package/node/wrappers/services/apikey.test.d.ts +7 -0
- package/node/wrappers/services/apikey.test.js +56 -0
- package/node/wrappers/services/apikey.test.js.map +1 -0
- package/node/wrappers/services/apikey.test.ts +65 -0
- package/node/wrappers/services/portfolio-service/PortfolioService.d.ts +1 -1
- package/node/wrappers/services/portfolio-service/PortfolioService.js +8 -2
- package/node/wrappers/services/portfolio-service/PortfolioService.js.map +1 -1
- package/node/wrappers/services/portfolio-service/PortfolioService.ts +7 -2
- package/node/wrappers/services/position-service/PositionService.d.ts +1 -1
- package/node/wrappers/services/position-service/PositionService.js +8 -2
- package/node/wrappers/services/position-service/PositionService.js.map +1 -1
- package/node/wrappers/services/position-service/PositionService.ts +7 -2
- package/node/wrappers/services/position-service/position.test.js.map +1 -1
- package/node/wrappers/services/price-service/PriceService.d.ts +29 -0
- package/node/wrappers/services/price-service/PriceService.js +151 -0
- package/node/wrappers/services/price-service/PriceService.js.map +1 -0
- package/node/wrappers/services/price-service/PriceService.ts +127 -0
- package/node/wrappers/services/price-service/price-wrapper.test.d.ts +1 -0
- package/node/wrappers/services/price-service/price-wrapper.test.js +132 -0
- package/node/wrappers/services/price-service/price-wrapper.test.js.map +1 -0
- package/node/wrappers/services/price-service/price-wrapper.test.ts +120 -0
- package/node/wrappers/services/price-service/price.test.d.ts +1 -0
- package/node/wrappers/services/price-service/price.test.js +198 -0
- package/node/wrappers/services/price-service/price.test.js.map +1 -0
- package/node/wrappers/services/price-service/price.test.ts +205 -0
- package/node/wrappers/services/security-service/SecurityService.d.ts +1 -1
- package/node/wrappers/services/security-service/SecurityService.js +8 -2
- package/node/wrappers/services/security-service/SecurityService.js.map +1 -1
- package/node/wrappers/services/security-service/SecurityService.searchByUuid.test.d.ts +1 -0
- package/node/wrappers/services/security-service/SecurityService.searchByUuid.test.js +38 -0
- package/node/wrappers/services/security-service/SecurityService.searchByUuid.test.js.map +1 -0
- package/node/wrappers/services/security-service/SecurityService.searchByUuid.test.ts +32 -0
- package/node/wrappers/services/security-service/SecurityService.ts +7 -2
- package/node/wrappers/services/security-service/security.maturityLadder.test.js.map +1 -1
- package/node/wrappers/services/transaction-service/TransactionService.d.ts +1 -1
- package/node/wrappers/services/transaction-service/TransactionService.js +8 -2
- package/node/wrappers/services/transaction-service/TransactionService.js.map +1 -1
- package/node/wrappers/services/transaction-service/TransactionService.ts +7 -2
- package/node/wrappers/services/transaction-service/transaction.search.test.js.map +1 -1
- package/node/wrappers/services/transaction-service/transaction.test.js.map +1 -1
- package/package.json +3 -2
- package/.env +0 -3
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
//Models
|
|
2
2
|
import { PriceProto } from "../../../fintekkers/models/price/price_pb";
|
|
3
3
|
import { TransactionType } from "./transaction_type";
|
|
4
|
+
import { TransactionTypeProto } from "../../../fintekkers/models/transaction/transaction_type_pb";
|
|
4
5
|
import { StrategyAllocationProto } from "../../../fintekkers/models/strategy/strategy_allocation_pb";
|
|
5
6
|
import { TransactionProto } from "../../../fintekkers/models/transaction/transaction_pb";
|
|
6
7
|
import { FieldProto } from "../../../fintekkers/models/position/field_pb";
|
|
7
8
|
import { PositionStatusProto } from "../../../fintekkers/models/position/position_status_pb";
|
|
9
|
+
import { DecimalValueProto } from "../../../fintekkers/models/util/decimal_value_pb";
|
|
8
10
|
|
|
9
11
|
import Security from "../security/security";
|
|
10
12
|
import Portfolio from "../portfolio/portfolio";
|
|
13
|
+
import Price from "../price/Price";
|
|
14
|
+
import { SecurityTypeProto } from "../../../fintekkers/models/security/security_type_pb";
|
|
11
15
|
|
|
12
16
|
//Model Utils
|
|
13
17
|
import { ZonedDateTime } from "../utils/datetime";
|
|
@@ -15,11 +19,69 @@ import { UUID } from "../utils/uuid";
|
|
|
15
19
|
import { LocalDate } from "../utils/date";
|
|
16
20
|
import { Decimal } from "decimal.js";
|
|
17
21
|
|
|
22
|
+
interface TransactionConstructorParams {
|
|
23
|
+
tradeDate: Date;
|
|
24
|
+
settlementDate: Date;
|
|
25
|
+
asOfDate: Date;
|
|
26
|
+
price: Decimal;
|
|
27
|
+
security: Security;
|
|
28
|
+
transactionType: TransactionType;
|
|
29
|
+
portfolio: Portfolio;
|
|
30
|
+
quantity: Decimal;
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
class Transaction {
|
|
19
34
|
proto: TransactionProto;
|
|
20
35
|
|
|
21
|
-
constructor(
|
|
22
|
-
|
|
36
|
+
constructor(protoOrParams: TransactionProto | TransactionConstructorParams) {
|
|
37
|
+
if (protoOrParams instanceof TransactionProto) {
|
|
38
|
+
this.proto = protoOrParams;
|
|
39
|
+
} else {
|
|
40
|
+
this.proto = this.buildProtoFromParams(protoOrParams);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Builds a complete TransactionProto from constructor parameters
|
|
46
|
+
*/
|
|
47
|
+
private buildProtoFromParams(params: TransactionConstructorParams): TransactionProto {
|
|
48
|
+
const transactionProto = new TransactionProto();
|
|
49
|
+
transactionProto.setObjectClass('Transaction');
|
|
50
|
+
transactionProto.setVersion('0.0.1');
|
|
51
|
+
transactionProto.setUuid(UUID.random().toUUIDProto());
|
|
52
|
+
|
|
53
|
+
// Convert asOfDate to ZonedDateTime and set on transaction
|
|
54
|
+
const asOfZonedDateTime = ZonedDateTime.from(params.asOfDate);
|
|
55
|
+
transactionProto.setAsOf(asOfZonedDateTime.toProto());
|
|
56
|
+
|
|
57
|
+
// Convert tradeDate and settlementDate to LocalDateProto
|
|
58
|
+
transactionProto.setTradeDate(LocalDate.from(params.tradeDate).toProto());
|
|
59
|
+
transactionProto.setSettlementDate(LocalDate.from(params.settlementDate).toProto());
|
|
60
|
+
|
|
61
|
+
// Create Price using Price.create() factory method
|
|
62
|
+
const price = Price.create(params.price, params.security, asOfZonedDateTime);
|
|
63
|
+
transactionProto.setPrice(price.proto);
|
|
64
|
+
|
|
65
|
+
// Set security, transaction type, and portfolio from their protos
|
|
66
|
+
transactionProto.setSecurity(params.security.proto);
|
|
67
|
+
transactionProto.setTransactionType(params.transactionType.proto);
|
|
68
|
+
transactionProto.setPortfolio(params.portfolio.proto);
|
|
69
|
+
|
|
70
|
+
// Convert quantity to DecimalValueProto
|
|
71
|
+
const quantityDecimal = new DecimalValueProto();
|
|
72
|
+
quantityDecimal.setArbitraryPrecisionValue(params.quantity.toString());
|
|
73
|
+
transactionProto.setQuantity(quantityDecimal);
|
|
74
|
+
|
|
75
|
+
// Create and set an empty StrategyAllocationProto
|
|
76
|
+
const strategyAllocationProto = new StrategyAllocationProto();
|
|
77
|
+
strategyAllocationProto.setObjectClass('StrategyAllocation');
|
|
78
|
+
strategyAllocationProto.setVersion('0.0.1');
|
|
79
|
+
transactionProto.setStrategyAllocation(strategyAllocationProto);
|
|
80
|
+
|
|
81
|
+
// Set default position status
|
|
82
|
+
transactionProto.setPositionStatus(PositionStatusProto.EXECUTED);
|
|
83
|
+
|
|
84
|
+
return transactionProto;
|
|
23
85
|
}
|
|
24
86
|
|
|
25
87
|
toString(): string {
|
|
@@ -150,6 +212,36 @@ class Transaction {
|
|
|
150
212
|
return this.proto.getChildtransactionsList();
|
|
151
213
|
}
|
|
152
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Adds a child transaction to this transaction's proto
|
|
217
|
+
* @param child - The child transaction to add
|
|
218
|
+
*/
|
|
219
|
+
addChildTransaction(child: Transaction): void {
|
|
220
|
+
this.proto.addChildtransactions(child.proto);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Checks if this transaction's security is cash
|
|
225
|
+
* @returns true if the security is cash, false otherwise
|
|
226
|
+
*/
|
|
227
|
+
isCashSecurity(): boolean {
|
|
228
|
+
return this.getSecurity().proto.getSecurityType() === SecurityTypeProto.CASH_SECURITY;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Searches child transactions for a cash transaction
|
|
233
|
+
* @returns The cash transaction if found, null otherwise
|
|
234
|
+
*/
|
|
235
|
+
getCashTransaction(): Transaction | null {
|
|
236
|
+
const children = this.getChildrenTransactions();
|
|
237
|
+
for (const childProto of children) {
|
|
238
|
+
const child = new Transaction(childProto);
|
|
239
|
+
if (child.isCashSecurity()) {
|
|
240
|
+
return child;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
153
245
|
|
|
154
246
|
equals(other: Transaction): boolean {
|
|
155
247
|
if (other instanceof Transaction) {
|
|
@@ -158,6 +250,328 @@ class Transaction {
|
|
|
158
250
|
return false;
|
|
159
251
|
}
|
|
160
252
|
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Creates a cash transaction associated with a parent transaction.
|
|
256
|
+
* The cash transaction represents the cash impact of the parent transaction.
|
|
257
|
+
* @param cashSecurity - The cash security (e.g., USD)
|
|
258
|
+
* @param parentTransaction - The parent transaction for which to create the cash transaction
|
|
259
|
+
* @returns The created cash transaction
|
|
260
|
+
*/
|
|
261
|
+
static createCashTransaction(cashSecurity: Security, parentTransaction: Transaction): Transaction {
|
|
262
|
+
// Determine transaction type based on parent
|
|
263
|
+
let cashTransactionType: TransactionType;
|
|
264
|
+
const parentType = parentTransaction.getTransactionType().proto;
|
|
265
|
+
|
|
266
|
+
if (parentType === TransactionTypeProto.BUY || parentType === TransactionTypeProto.MATURATION_OFFSET) {
|
|
267
|
+
cashTransactionType = new TransactionType(TransactionTypeProto.WITHDRAWAL);
|
|
268
|
+
} else if (parentType === TransactionTypeProto.SELL || parentType === TransactionTypeProto.MATURATION) {
|
|
269
|
+
cashTransactionType = new TransactionType(TransactionTypeProto.DEPOSIT);
|
|
270
|
+
} else {
|
|
271
|
+
throw new Error(`Cannot create cash transaction for transaction type: ${TransactionTypeProto[parentType]}`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Calculate book amount
|
|
275
|
+
let bookAmount: Decimal;
|
|
276
|
+
const securityType = parentTransaction.getSecurity().proto.getSecurityType();
|
|
277
|
+
|
|
278
|
+
if (securityType === SecurityTypeProto.BOND_SECURITY ||
|
|
279
|
+
securityType === SecurityTypeProto.TIPS ||
|
|
280
|
+
securityType === SecurityTypeProto.FRN) {
|
|
281
|
+
// For bond securities
|
|
282
|
+
if (parentType === TransactionTypeProto.MATURATION || parentType === TransactionTypeProto.MATURATION_OFFSET) {
|
|
283
|
+
// For maturation transactions, use quantity directly
|
|
284
|
+
bookAmount = parentTransaction.getQuantity();
|
|
285
|
+
} else {
|
|
286
|
+
// For other bond transactions, calculate: (quantity / faceValue) * (price * priceScaleFactor)
|
|
287
|
+
// Lazy import to avoid circular dependency
|
|
288
|
+
const BondSecurity = require('../security/BondSecurity').default;
|
|
289
|
+
const bondSecurity = new BondSecurity(parentTransaction.getSecurity().proto);
|
|
290
|
+
|
|
291
|
+
const priceScaleFactor = bondSecurity.getPriceScaleFactor();
|
|
292
|
+
const faceValueProto = bondSecurity.getFaceValue();
|
|
293
|
+
const faceValue = new Decimal(faceValueProto.getArbitraryPrecisionValue());
|
|
294
|
+
|
|
295
|
+
const priceProto = parentTransaction.getPrice();
|
|
296
|
+
const priceValue = new Decimal(priceProto.getPrice()?.getArbitraryPrecisionValue() || '0');
|
|
297
|
+
const scaledPrice = priceValue.mul(priceScaleFactor);
|
|
298
|
+
|
|
299
|
+
const quantity = parentTransaction.getQuantity();
|
|
300
|
+
const numberBondUnits = quantity.div(faceValue);
|
|
301
|
+
|
|
302
|
+
bookAmount = numberBondUnits.mul(scaledPrice);
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
// For other securities: quantity * price
|
|
306
|
+
const priceProto = parentTransaction.getPrice();
|
|
307
|
+
const priceValue = new Decimal(priceProto.getPrice()?.getArbitraryPrecisionValue() || '0');
|
|
308
|
+
bookAmount = parentTransaction.getQuantity().mul(priceValue);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Get asOf ZonedDateTime
|
|
312
|
+
const asOf = parentTransaction.getAsOf();
|
|
313
|
+
|
|
314
|
+
// Create cash transaction using parameter-based constructor
|
|
315
|
+
const cashTransaction = new Transaction({
|
|
316
|
+
tradeDate: parentTransaction.getTradeDate().toDate(),
|
|
317
|
+
settlementDate: parentTransaction.getSettlementDate().toDate(),
|
|
318
|
+
asOfDate: asOf.toDateTime().toJSDate(),
|
|
319
|
+
price: new Decimal('1.0'), // Cash price is always 1.0
|
|
320
|
+
security: cashSecurity,
|
|
321
|
+
transactionType: cashTransactionType,
|
|
322
|
+
portfolio: parentTransaction.getPortfolio(),
|
|
323
|
+
quantity: bookAmount
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// Set additional fields from parent
|
|
327
|
+
cashTransaction.proto.setPositionStatus(parentTransaction.getPositionStatus());
|
|
328
|
+
cashTransaction.proto.setStrategyAllocation(parentTransaction.getStrategyAllocation());
|
|
329
|
+
cashTransaction.proto.setTradeName(parentTransaction.getTradeName());
|
|
330
|
+
|
|
331
|
+
// Add as child to parent
|
|
332
|
+
parentTransaction.addChildTransaction(cashTransaction);
|
|
333
|
+
|
|
334
|
+
return cashTransaction;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Creates a maturation transaction for a bond.
|
|
339
|
+
* @param transaction - The parent transaction (must be for a bond security)
|
|
340
|
+
* @param transactionType - The transaction type (MATURATION or MATURATION_OFFSET)
|
|
341
|
+
* @param cashSecurity - The cash security to use for the cash impact
|
|
342
|
+
*/
|
|
343
|
+
static addMaturationTransaction(transaction: Transaction, transactionType: TransactionType, cashSecurity: Security): void {
|
|
344
|
+
// Lazy import to avoid circular dependency
|
|
345
|
+
const BondSecurity = require('../security/BondSecurity').default;
|
|
346
|
+
|
|
347
|
+
// Cast security to BondSecurity
|
|
348
|
+
const bondSecurity = new BondSecurity(transaction.getSecurity().proto);
|
|
349
|
+
|
|
350
|
+
// Get maturity date
|
|
351
|
+
const maturityDate = bondSecurity.getMaturityDate();
|
|
352
|
+
|
|
353
|
+
// Calculate settlement date: maturity date + 2 days
|
|
354
|
+
const maturityDateObj = maturityDate.toDate();
|
|
355
|
+
maturityDateObj.setDate(maturityDateObj.getDate() + 2);
|
|
356
|
+
const settlementDate = LocalDate.from(maturityDateObj);
|
|
357
|
+
|
|
358
|
+
// Get price as Decimal
|
|
359
|
+
const priceProto = transaction.getPrice();
|
|
360
|
+
const priceValue = new Decimal(priceProto.getPrice()?.getArbitraryPrecisionValue() || '0');
|
|
361
|
+
|
|
362
|
+
// Get asOf ZonedDateTime
|
|
363
|
+
const asOf = transaction.getAsOf();
|
|
364
|
+
|
|
365
|
+
// Create maturation transaction
|
|
366
|
+
const maturation = new Transaction({
|
|
367
|
+
tradeDate: maturityDate.toDate(),
|
|
368
|
+
settlementDate: settlementDate.toDate(),
|
|
369
|
+
asOfDate: asOf.toDateTime().toJSDate(),
|
|
370
|
+
price: priceValue,
|
|
371
|
+
security: transaction.getSecurity(),
|
|
372
|
+
transactionType: transactionType,
|
|
373
|
+
portfolio: transaction.getPortfolio(),
|
|
374
|
+
quantity: transaction.getQuantity()
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// Set additional fields from parent
|
|
378
|
+
maturation.proto.setPositionStatus(transaction.getPositionStatus());
|
|
379
|
+
maturation.proto.setStrategyAllocation(transaction.getStrategyAllocation());
|
|
380
|
+
maturation.proto.setTradeName(transaction.getTradeName());
|
|
381
|
+
|
|
382
|
+
// Add as child transaction
|
|
383
|
+
transaction.addChildTransaction(maturation);
|
|
384
|
+
|
|
385
|
+
// Add cash impact to the maturation transaction
|
|
386
|
+
Transaction.addCashImpact(maturation, cashSecurity);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Generates additional transactions associated with this transaction.
|
|
391
|
+
* For instance, a Buy transaction on a bond will also create the maturation transaction.
|
|
392
|
+
* @param transaction - The parent transaction
|
|
393
|
+
* @param cashSecurity - The cash security to use for cash impacts
|
|
394
|
+
*/
|
|
395
|
+
static addDerivedTransactions(transaction: Transaction, cashSecurity: Security): void {
|
|
396
|
+
const securityType = transaction.getSecurity().proto.getSecurityType();
|
|
397
|
+
const isBond = securityType === SecurityTypeProto.BOND_SECURITY ||
|
|
398
|
+
securityType === SecurityTypeProto.FRN ||
|
|
399
|
+
securityType === SecurityTypeProto.TIPS;
|
|
400
|
+
|
|
401
|
+
const transactionType = transaction.getTransactionType().proto;
|
|
402
|
+
const isABuyTransaction = transactionType === TransactionTypeProto.BUY;
|
|
403
|
+
const isASellTransaction = transactionType === TransactionTypeProto.SELL;
|
|
404
|
+
const isaMaturationTransaction = transactionType !== TransactionTypeProto.MATURATION &&
|
|
405
|
+
transactionType !== TransactionTypeProto.MATURATION_OFFSET;
|
|
406
|
+
|
|
407
|
+
if (isBond && isASellTransaction && isaMaturationTransaction) {
|
|
408
|
+
Transaction.addMaturationTransaction(transaction, new TransactionType(TransactionTypeProto.MATURATION_OFFSET), cashSecurity);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (isBond && isABuyTransaction && isaMaturationTransaction) {
|
|
412
|
+
Transaction.addMaturationTransaction(transaction, new TransactionType(TransactionTypeProto.MATURATION), cashSecurity);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Adds a cash impact transaction to this transaction.
|
|
418
|
+
* If the transaction's security is not cash, creates a cash transaction.
|
|
419
|
+
* @param transaction - The transaction to add cash impact to
|
|
420
|
+
* @param cashSecurity - The cash security (e.g., USD) to use for the cash transaction
|
|
421
|
+
*/
|
|
422
|
+
static addCashImpact(transaction: Transaction, cashSecurity: Security): void {
|
|
423
|
+
// Check if cash transaction already exists
|
|
424
|
+
if (transaction.getCashTransaction() != null) {
|
|
425
|
+
throw new Error("This transaction already has a cash impact");
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// If security is not cash, create cash transaction
|
|
429
|
+
if (!transaction.isCashSecurity()) {
|
|
430
|
+
Transaction.createCashTransaction(cashSecurity, transaction);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
161
433
|
}
|
|
162
434
|
|
|
163
435
|
export default Transaction;
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
// private static Transaction createCashTransaction(CashSecurity cashSecurity, Transaction parentTransaction) {
|
|
439
|
+
// TransactionType transactionType = null;
|
|
440
|
+
// switch(parentTransaction.getTransactionType()) {
|
|
441
|
+
// case BUY:
|
|
442
|
+
// case MATURATION_OFFSET:
|
|
443
|
+
// transactionType = TransactionType.WITHDRAWAL;
|
|
444
|
+
// break;
|
|
445
|
+
// case SELL:
|
|
446
|
+
// case MATURATION:
|
|
447
|
+
// transactionType = TransactionType.DEPOSIT;
|
|
448
|
+
// break;
|
|
449
|
+
// default:
|
|
450
|
+
// throw new RuntimeException("SHOULDN'T GET HERE");
|
|
451
|
+
// }
|
|
452
|
+
|
|
453
|
+
// BigDecimal bookAmount = null;
|
|
454
|
+
|
|
455
|
+
// switch(parentTransaction.getSecurity().getSecurityType()) {
|
|
456
|
+
// case BOND_SECURITY:
|
|
457
|
+
// if(TransactionType.MATURATION.equals(parentTransaction.getTransactionType())
|
|
458
|
+
// || TransactionType.MATURATION_OFFSET.equals(parentTransaction.getTransactionType())) {
|
|
459
|
+
// bookAmount = parentTransaction.getQuantity();
|
|
460
|
+
// } else {
|
|
461
|
+
// //E.g. if you bought 50 bonds with face value of $1000 @ $99.
|
|
462
|
+
// // The face amount is $50k
|
|
463
|
+
// // The book amount is: $49.5k (i.e. 50 * (99 * scaled price))
|
|
464
|
+
// BigDecimal priceScaleFactor = ((BondSecurity) parentTransaction.getSecurity()).getPriceScaleFactor();
|
|
465
|
+
// BigDecimal faceValue = ((BondSecurity) parentTransaction.getSecurity()).getFaceValue();
|
|
466
|
+
// BigDecimal scaledPrice = parentTransaction.getPrice().getPrice().multiply(priceScaleFactor);
|
|
467
|
+
// BigDecimal numberBondUnits = parentTransaction.getQuantity().divide(faceValue);
|
|
468
|
+
|
|
469
|
+
// bookAmount = numberBondUnits.multiply(scaledPrice);
|
|
470
|
+
// }
|
|
471
|
+
// break;
|
|
472
|
+
// default:
|
|
473
|
+
// bookAmount = parentTransaction.getQuantity().multiply(parentTransaction.getPrice().getPrice());
|
|
474
|
+
// }
|
|
475
|
+
|
|
476
|
+
// Transaction cashTransaction = new Transaction(
|
|
477
|
+
// UUID.randomUUID(), parentTransaction.getPortfolio(),
|
|
478
|
+
// Price.getCashPrice(),
|
|
479
|
+
// parentTransaction.getTradeDate(),
|
|
480
|
+
// parentTransaction.getSettlementDate(),
|
|
481
|
+
// bookAmount,
|
|
482
|
+
// cashSecurity,
|
|
483
|
+
// transactionType,
|
|
484
|
+
// null,
|
|
485
|
+
// parentTransaction.getAsOf(),
|
|
486
|
+
// parentTransaction,
|
|
487
|
+
// parentTransaction.getTradeName(),
|
|
488
|
+
// parentTransaction.getPositionStatus());
|
|
489
|
+
// cashTransaction.setPositionStatus(parentTransaction.getPositionStatus());
|
|
490
|
+
|
|
491
|
+
// //Cash transactions will have the originating transaction ID associated with it.
|
|
492
|
+
// parentTransaction.addChildTransaction(cashTransaction);
|
|
493
|
+
|
|
494
|
+
// return cashTransaction;
|
|
495
|
+
// }
|
|
496
|
+
|
|
497
|
+
// /**
|
|
498
|
+
// * Generates additional transactions associated with this transaction. For instance a Buy transaction on
|
|
499
|
+
// * a bond will also create the maturation transaction.
|
|
500
|
+
// *
|
|
501
|
+
// * @param transaction The parent transaction
|
|
502
|
+
// */
|
|
503
|
+
// public static void addDerivedTransactions(Transaction transaction) {
|
|
504
|
+
// //TODO: Best to co-locate this with the transaction instantiator where we calculate the cash impacts, right?!
|
|
505
|
+
// boolean isBond = SecurityTypeProto.BOND_SECURITY.equals(transaction.getSecurity().getSecurityType())
|
|
506
|
+
// || SecurityTypeProto.FRN.equals(transaction.getSecurity().getSecurityType())
|
|
507
|
+
// || SecurityTypeProto.TIPS.equals(transaction.getSecurity().getSecurityType());
|
|
508
|
+
// boolean isABuyTransaction = TransactionType.BUY.equals(transaction.getTransactionType());
|
|
509
|
+
// boolean isASellTransaction = TransactionType.SELL.equals(transaction.getTransactionType());
|
|
510
|
+
// boolean isaMaturationTransaction = !TransactionType.MATURATION.equals(transaction.getTransactionType())
|
|
511
|
+
// && !TransactionType.MATURATION_OFFSET.equals(transaction.getTransactionType());
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
// if(isBond && isASellTransaction && isaMaturationTransaction) {
|
|
515
|
+
// addMaturationTransaction(transaction, TransactionType.MATURATION_OFFSET);
|
|
516
|
+
// }
|
|
517
|
+
|
|
518
|
+
// if(isBond && isABuyTransaction && isaMaturationTransaction) {
|
|
519
|
+
// addMaturationTransaction(transaction, TransactionType.MATURATION);
|
|
520
|
+
// /*
|
|
521
|
+
// Example:
|
|
522
|
+
|
|
523
|
+
// (A) Parent transaction BUY bond. Child transaction MATURE bond
|
|
524
|
+
// (B) Parent transaction links to the children (and vice - versa)
|
|
525
|
+
// (C) All transactions indexed in the in-memory layer, so are searchable
|
|
526
|
+
// (D) We create tax lot modifiers at that point in time
|
|
527
|
+
|
|
528
|
+
// TODO: We need to create multi-level tax lots, i.e. the ability to have a form of tax lot that are proposed
|
|
529
|
+
// but not concrete. For example, if there is a SELL transaction then the mature transaction needs to be down
|
|
530
|
+
// sized.
|
|
531
|
+
|
|
532
|
+
// Buy 100 bond ($100), face value $10k, mature 2032.
|
|
533
|
+
// Mature bond of -100, 'trade date' of 2032
|
|
534
|
+
|
|
535
|
+
// Sell 20 bond ($100), face value -$2k, mature 2032
|
|
536
|
+
// Mature bond of -80, trade-date of 2032 needs to be created
|
|
537
|
+
|
|
538
|
+
// Do that via modifiers? I.e. there will be a mature of -100, and a mature of 20. Makese, sense right?
|
|
539
|
+
|
|
540
|
+
// When un-doing a transaction, we'll need to traverse the parent/child transactions and remove the associated
|
|
541
|
+
// tax lots.
|
|
542
|
+
|
|
543
|
+
// */
|
|
544
|
+
// }
|
|
545
|
+
// }
|
|
546
|
+
|
|
547
|
+
// private static void addMaturationTransaction(Transaction transaction, TransactionType transactionType) {
|
|
548
|
+
// BondSecurity bondSecurity = (BondSecurity) transaction.getSecurity();
|
|
549
|
+
|
|
550
|
+
// Transaction maturation = new Transaction(
|
|
551
|
+
// UUID.randomUUID(), transaction.getPortfolio(), transaction.getPrice(),
|
|
552
|
+
// bondSecurity.getMaturityDate(),
|
|
553
|
+
// bondSecurity.getMaturityDate().plusDays(2),
|
|
554
|
+
// transaction.getQuantity(), transaction.getSecurity(),
|
|
555
|
+
// transactionType, transaction.getStrategyAllocation(),
|
|
556
|
+
// transaction.getAsOf(),
|
|
557
|
+
// // bondSecurity.getMaturityDate().atStartOfDay(ZonedDateTime.now().getZone()),
|
|
558
|
+
// transaction, transaction.getTradeName(), transaction.getPositionStatus()
|
|
559
|
+
// );
|
|
560
|
+
|
|
561
|
+
// transaction.addChildTransaction(maturation);
|
|
562
|
+
|
|
563
|
+
// addCashImpact(maturation);
|
|
564
|
+
// }
|
|
565
|
+
|
|
566
|
+
// public static void addCashImpact(Transaction transaction) {
|
|
567
|
+
// if(transaction.getCashTransaction() != null){
|
|
568
|
+
// throw new RuntimeException("This transaction already has a cash impact");
|
|
569
|
+
// }
|
|
570
|
+
|
|
571
|
+
// //Probably need to create a higher level transaction concept?
|
|
572
|
+
// if(!transaction.getSecurity().isCash()) {
|
|
573
|
+
// Transaction cashTxn = Transaction.createCashTransaction(CashSecurity.USD, transaction);
|
|
574
|
+
// // assert transaction.getCashTransaction().equals(cashTxn);
|
|
575
|
+
// assert cashTxn.getParentTransaction().equals(transaction);
|
|
576
|
+
// }
|
|
577
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const assert = require("assert");
|
|
7
|
+
const transaction_1 = __importDefault(require("./transaction"));
|
|
8
|
+
const transaction_type_1 = require("./transaction_type");
|
|
9
|
+
const transaction_type_pb_1 = require("../../../fintekkers/models/transaction/transaction_type_pb");
|
|
10
|
+
const position_status_pb_1 = require("../../../fintekkers/models/position/position_status_pb");
|
|
11
|
+
const security_1 = __importDefault(require("../security/security"));
|
|
12
|
+
const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
13
|
+
const local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb");
|
|
14
|
+
const decimal_value_pb_1 = require("../../../fintekkers/models/util/decimal_value_pb");
|
|
15
|
+
const security_quantity_type_pb_1 = require("../../../fintekkers/models/security/security_quantity_type_pb");
|
|
16
|
+
const coupon_frequency_pb_1 = require("../../../fintekkers/models/security/coupon_frequency_pb");
|
|
17
|
+
const coupon_type_pb_1 = require("../../../fintekkers/models/security/coupon_type_pb");
|
|
18
|
+
const uuid_1 = require("../utils/uuid");
|
|
19
|
+
const decimal_js_1 = require("decimal.js");
|
|
20
|
+
const portfolio_test_1 = require("../portfolio/portfolio.test");
|
|
21
|
+
test('test Transaction constructor with parameters', () => {
|
|
22
|
+
testTransactionConstructor();
|
|
23
|
+
});
|
|
24
|
+
function testTransactionConstructor() {
|
|
25
|
+
var _a;
|
|
26
|
+
// Create test data
|
|
27
|
+
const tradeDate = new Date(2024, 0, 15);
|
|
28
|
+
const settlementDate = new Date(2024, 0, 17);
|
|
29
|
+
const asOfDate = new Date(2024, 0, 15, 10, 30, 0);
|
|
30
|
+
const price = new decimal_js_1.Decimal('100.50');
|
|
31
|
+
const quantity = new decimal_js_1.Decimal('1000.00');
|
|
32
|
+
const security = dummySecurity();
|
|
33
|
+
const portfolio = (0, portfolio_test_1.dummyPortfolio)();
|
|
34
|
+
const transactionType = dummyTransactionType();
|
|
35
|
+
// Create Transaction using parameter-based constructor
|
|
36
|
+
const transaction = new transaction_1.default({
|
|
37
|
+
tradeDate,
|
|
38
|
+
settlementDate,
|
|
39
|
+
asOfDate,
|
|
40
|
+
price,
|
|
41
|
+
security,
|
|
42
|
+
transactionType,
|
|
43
|
+
portfolio,
|
|
44
|
+
quantity
|
|
45
|
+
});
|
|
46
|
+
// Verify all getters return expected values
|
|
47
|
+
// getTradeDate() - should match input tradeDate
|
|
48
|
+
const tradeDateFromTransaction = transaction.getTradeDate().toDate();
|
|
49
|
+
assert(tradeDateFromTransaction.getFullYear() === tradeDate.getFullYear());
|
|
50
|
+
assert(tradeDateFromTransaction.getMonth() === tradeDate.getMonth());
|
|
51
|
+
assert(tradeDateFromTransaction.getDate() === tradeDate.getDate());
|
|
52
|
+
// getSettlementDate() - should match input settlementDate
|
|
53
|
+
const settlementDateFromTransaction = transaction.getSettlementDate().toDate();
|
|
54
|
+
assert(settlementDateFromTransaction.getFullYear() === settlementDate.getFullYear());
|
|
55
|
+
assert(settlementDateFromTransaction.getMonth() === settlementDate.getMonth());
|
|
56
|
+
assert(settlementDateFromTransaction.getDate() === settlementDate.getDate());
|
|
57
|
+
// getAsOf() - should match input asOfDate (converted to ZonedDateTime)
|
|
58
|
+
const asOfFromTransaction = transaction.getAsOf();
|
|
59
|
+
const asOfDateTime = asOfFromTransaction.toDateTime().toJSDate();
|
|
60
|
+
// Allow 1 second tolerance for timezone conversion
|
|
61
|
+
const timeDiff = Math.abs(asOfDateTime.getTime() - asOfDate.getTime());
|
|
62
|
+
assert(timeDiff < 1000, `AsOf time difference ${timeDiff}ms exceeds 1 second tolerance`);
|
|
63
|
+
// getPrice() - should return PriceProto with correct price value
|
|
64
|
+
const priceProto = transaction.getPrice();
|
|
65
|
+
const priceValue = (_a = priceProto.getPrice()) === null || _a === void 0 ? void 0 : _a.getArbitraryPrecisionValue();
|
|
66
|
+
assert(priceValue === '100.5', `Expected price '100.5', got '${priceValue}'`);
|
|
67
|
+
// getSecurity() - should return Security matching input security
|
|
68
|
+
assert(transaction.getSecurity().getID().toString() === security.getID().toString(), 'Security IDs should match');
|
|
69
|
+
// getTransactionType() - should return TransactionType matching input transactionType
|
|
70
|
+
assert(transaction.getTransactionType().toString() === 'BUY', `Expected 'BUY', got '${transaction.getTransactionType().toString()}'`);
|
|
71
|
+
assert(transaction.getTransactionType().proto === transaction_type_pb_1.TransactionTypeProto.BUY, 'TransactionType proto should be BUY');
|
|
72
|
+
// getPortfolio() - should return Portfolio matching input portfolio
|
|
73
|
+
assert(transaction.getPortfolio().getPortfolioName() === 'Test Portfolio', `Expected 'Test Portfolio', got '${transaction.getPortfolio().getPortfolioName()}'`);
|
|
74
|
+
assert(transaction.getPortfolio().getID().toString() === portfolio.getID().toString(), 'Portfolio IDs should match');
|
|
75
|
+
// getQuantity() - should return Decimal matching input quantity
|
|
76
|
+
assert(transaction.getQuantity().toString() === '1000', `Expected quantity '1000', got '${transaction.getQuantity().toString()}'`);
|
|
77
|
+
assert(transaction.getQuantity().equals(quantity), 'Quantities should be equal');
|
|
78
|
+
// getPositionStatus() - should return EXECUTED (default)
|
|
79
|
+
assert(transaction.getPositionStatus() === position_status_pb_1.PositionStatusProto.EXECUTED, `Expected EXECUTED, got ${transaction.getPositionStatus()}`);
|
|
80
|
+
}
|
|
81
|
+
function dummySecurity() {
|
|
82
|
+
return security_1.default.create(new security_pb_1.SecurityProto()
|
|
83
|
+
.setObjectClass('Security')
|
|
84
|
+
.setVersion('0.0.1')
|
|
85
|
+
.setUuid(uuid_1.UUID.random().toUUIDProto())
|
|
86
|
+
.setFaceValue(new decimal_value_pb_1.DecimalValueProto().setArbitraryPrecisionValue('1000.00'))
|
|
87
|
+
.setQuantityType(security_quantity_type_pb_1.SecurityQuantityTypeProto.ORIGINAL_FACE_VALUE)
|
|
88
|
+
.setAssetClass("Bond")
|
|
89
|
+
.setIssuerName("Test Issuer")
|
|
90
|
+
.setCouponRate(new decimal_value_pb_1.DecimalValueProto().setArbitraryPrecisionValue('0.05'))
|
|
91
|
+
.setCouponFrequency(coupon_frequency_pb_1.CouponFrequencyProto.SEMIANNUALLY)
|
|
92
|
+
.setCouponType(coupon_type_pb_1.CouponTypeProto.FIXED)
|
|
93
|
+
.setMaturityDate(new local_date_pb_1.LocalDateProto().setYear(2026).setMonth(1).setDay(1))
|
|
94
|
+
.setIssueDate(new local_date_pb_1.LocalDateProto().setYear(2021).setMonth(1).setDay(1))
|
|
95
|
+
.setDescription("Test security"));
|
|
96
|
+
}
|
|
97
|
+
function dummyTransactionType() {
|
|
98
|
+
return new transaction_type_1.TransactionType(transaction_type_pb_1.TransactionTypeProto.BUY);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=transaction_constructor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction_constructor.test.js","sourceRoot":"","sources":["transaction_constructor.test.ts"],"names":[],"mappings":";;;;;AAAA,iCAAkC;AAClC,gEAAwC;AACxC,yDAAqD;AACrD,oGAAkG;AAClG,+FAA6F;AAC7F,oEAA4C;AAE5C,iFAAgF;AAChF,iFAA+E;AAC/E,uFAAqF;AACrF,6GAA0G;AAC1G,iGAA+F;AAC/F,uFAAqF;AACrF,wCAAqC;AAErC,2CAAqC;AACrC,gEAA6D;AAE7D,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACtD,0BAA0B,EAAE,CAAC;AACjC,CAAC,CAAC,CAAC;AAEH,SAAS,0BAA0B;;IAC/B,mBAAmB;IACnB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACxC,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAClD,MAAM,KAAK,GAAG,IAAI,oBAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAI,oBAAO,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;IACjC,MAAM,SAAS,GAAG,IAAA,+BAAc,GAAE,CAAC;IACnC,MAAM,eAAe,GAAG,oBAAoB,EAAE,CAAC;IAE/C,uDAAuD;IACvD,MAAM,WAAW,GAAG,IAAI,qBAAW,CAAC;QAChC,SAAS;QACT,cAAc;QACd,QAAQ;QACR,KAAK;QAC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