@fintekkers/ledger-models 1.1.40 → 1.1.42
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/hierarchy.json +12 -2
- package/node/wrappers/models/errors.d.ts +16 -0
- package/node/wrappers/models/errors.js +21 -1
- package/node/wrappers/models/errors.js.map +1 -1
- package/node/wrappers/models/errors.ts +23 -0
- package/node/wrappers/models/price/Price.d.ts +4 -2
- package/node/wrappers/models/price/Price.js +7 -3
- package/node/wrappers/models/price/Price.js.map +1 -1
- package/node/wrappers/models/price/Price.ts +6 -3
- package/node/wrappers/models/security/default_price_types.d.ts +31 -0
- package/node/wrappers/models/security/default_price_types.js +132 -0
- package/node/wrappers/models/security/default_price_types.js.map +1 -0
- package/node/wrappers/models/security/default_price_types.test.d.ts +1 -0
- package/node/wrappers/models/security/default_price_types.test.js +98 -0
- package/node/wrappers/models/security/default_price_types.test.js.map +1 -0
- package/node/wrappers/models/security/default_price_types.test.ts +91 -0
- package/node/wrappers/models/security/default_price_types.ts +132 -0
- package/node/wrappers/models/transaction/transaction.d.ts +8 -0
- package/node/wrappers/models/transaction/transaction.js +9 -1
- package/node/wrappers/models/transaction/transaction.js.map +1 -1
- package/node/wrappers/models/transaction/transaction.ts +16 -1
- package/node/wrappers/models/transaction/transaction_constructor.test.js +112 -1
- package/node/wrappers/models/transaction/transaction_constructor.test.js.map +1 -1
- package/node/wrappers/models/transaction/transaction_constructor.test.ts +138 -2
- package/node/wrappers/models/transaction/transaction_price_defaults.test.js +2 -0
- package/node/wrappers/models/transaction/transaction_price_defaults.test.js.map +1 -1
- package/node/wrappers/models/transaction/transaction_price_defaults.test.ts +2 -0
- package/node/wrappers/util/object-types.test.js +2 -0
- package/node/wrappers/util/object-types.test.js.map +1 -1
- package/node/wrappers/util/object-types.test.ts +2 -0
- package/package.json +1 -1
package/hierarchy.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"schema_version": "1.
|
|
3
|
-
"_doc": "Single source of truth for the FinTekkers product hierarchy. See ../docs/product-hierarchy.md for narrative description, hierarchy-examples.md for worked examples, and registry-versioning.md for compatibility rules. Each leaf product_type carries (asset_class, instrument_type). Abstract nodes carry only hierarchy. status=active entries must have a matching ProductTypeProto enum value (CI-enforced). status=planned entries are aspirational and not yet wired into the proto enum. NOTE: M1 ships a 3-dimensional registry (productType + asset_class + instrument_type). The 4th dimension (index_type — single_name vs index) is intentionally deferred and will be added in a future milestone. Option strategy leaves (butterfly, vertical spread, calendar spread, condor, straddle, ...) are also intentionally absent — strategies are derived from the legs field on SecurityProto, not from a productType enum value. asset_classes is the one canonical asset-class vocabulary (codes and tree); an entry's optional aliases list names legacy values that resolve to it. instrument_types maps each instrument-type code to {label}, in display order; every code must have a matching INSTRUMENT_TYPE_<CODE> InstrumentTypeProto value (checked at load), and that enum value takes its label from here. enum_labels holds display labels (and identifier-type input placeholders) for proto enum values with no entry elsewhere, keyed by proto enum name then value name. See ../docs/adr/asset_class_vocabulary.md. valuation_input_types maps a product_type node, optionally narrowed by coupon_types, to its ProductInput input type and the market data it requires; unpriced lists nodes with no input type. The deepest matching node wins; see ../docs/adr/valuation_input_types.md.",
|
|
2
|
+
"schema_version": "1.5",
|
|
3
|
+
"_doc": "Single source of truth for the FinTekkers product hierarchy. See ../docs/product-hierarchy.md for narrative description, hierarchy-examples.md for worked examples, and registry-versioning.md for compatibility rules. Each leaf product_type carries (asset_class, instrument_type). Abstract nodes carry only hierarchy. status=active entries must have a matching ProductTypeProto enum value (CI-enforced). status=planned entries are aspirational and not yet wired into the proto enum. NOTE: M1 ships a 3-dimensional registry (productType + asset_class + instrument_type). The 4th dimension (index_type — single_name vs index) is intentionally deferred and will be added in a future milestone. Option strategy leaves (butterfly, vertical spread, calendar spread, condor, straddle, ...) are also intentionally absent — strategies are derived from the legs field on SecurityProto, not from a productType enum value. asset_classes is the one canonical asset-class vocabulary (codes and tree); an entry's optional aliases list names legacy values that resolve to it. instrument_types maps each instrument-type code to {label}, in display order; every code must have a matching INSTRUMENT_TYPE_<CODE> InstrumentTypeProto value (checked at load), and that enum value takes its label from here. enum_labels holds display labels (and identifier-type input placeholders) for proto enum values with no entry elsewhere, keyed by proto enum name then value name. See ../docs/adr/asset_class_vocabulary.md. valuation_input_types maps a product_type node, optionally narrowed by coupon_types, to its ProductInput input type and the market data it requires; unpriced lists nodes with no input type. The deepest matching node wins; see ../docs/adr/valuation_input_types.md. default_price_types maps a product_type node to the PriceTypeProto name a create-transaction wrapper puts on the trade price when the caller passes no price_type; the deepest node on the parent chain wins, and a product with no entry has no default (the wrapper raises). See ../docs/adr/default_price_types.md.",
|
|
4
4
|
|
|
5
5
|
"product_types": {
|
|
6
6
|
"BOND": { "parent": null, "abstract": true, "label": "Bond" },
|
|
@@ -173,5 +173,15 @@
|
|
|
173
173
|
"FX_SPOT", "INDEX", "CRYPTO", "COMMODITY_SPOT", "FUTURE", "OPTION", "SWAP", "FORWARD",
|
|
174
174
|
"FINANCING", "FUND_LP", "CMBS", "ABS", "CLO", "CONVERTIBLE_BOND", "COCO"
|
|
175
175
|
]
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
"default_price_types": {
|
|
179
|
+
"BOND": "PERCENTAGE",
|
|
180
|
+
"STOCK": "ABSOLUTE",
|
|
181
|
+
"CURRENCY": "ABSOLUTE",
|
|
182
|
+
"MONEY_MARKET_FUND": "ABSOLUTE",
|
|
183
|
+
"INDEX": "INDEX_LEVEL",
|
|
184
|
+
"T_BILL_13_WEEK_SERIES": "RATE",
|
|
185
|
+
"SOFR_SERIES": "RATE"
|
|
176
186
|
}
|
|
177
187
|
}
|
|
@@ -48,5 +48,21 @@ export declare class MissingMarketDataError extends ModelValidationError {
|
|
|
48
48
|
/** @deprecated Use inputType. Removed in a later release (LM-418). */
|
|
49
49
|
get arm(): string;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Typed input error: a trade price is being built with no price_type and the
|
|
53
|
+
* security's product_type has no entry (on its parent chain) in
|
|
54
|
+
* hierarchy.json default_price_types, e.g. FX_SPOT. Thrown by the Transaction
|
|
55
|
+
* params constructor before anything is built. Carries one violation on
|
|
56
|
+
* `price.price_type` whose object id is the security's UUID
|
|
57
|
+
* (docs/adr/default_price_types.md).
|
|
58
|
+
*/
|
|
59
|
+
export declare class NoDefaultPriceTypeError extends ModelValidationError {
|
|
60
|
+
readonly productType: string;
|
|
61
|
+
/**
|
|
62
|
+
* @param productType the ProductTypeProto name, e.g. `FX_SPOT`
|
|
63
|
+
* @param objectId the security's UUID, or undefined if it has none
|
|
64
|
+
*/
|
|
65
|
+
constructor(productType: string, objectId: UUID | undefined);
|
|
66
|
+
}
|
|
51
67
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
52
68
|
export declare function violation(field: string, objectId: UUID | undefined, message: string): FieldViolationProto;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.violation = exports.MissingMarketDataError = exports.UnmappedProductTypeError = exports.ModelValidationError = void 0;
|
|
3
|
+
exports.violation = exports.NoDefaultPriceTypeError = exports.MissingMarketDataError = exports.UnmappedProductTypeError = exports.ModelValidationError = void 0;
|
|
4
4
|
const field_violation_pb_1 = require("../../fintekkers/requests/util/errors/field_violation_pb");
|
|
5
5
|
const uuid_1 = require("./utils/uuid");
|
|
6
6
|
/**
|
|
@@ -74,6 +74,26 @@ class MissingMarketDataError extends ModelValidationError {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
exports.MissingMarketDataError = MissingMarketDataError;
|
|
77
|
+
/**
|
|
78
|
+
* Typed input error: a trade price is being built with no price_type and the
|
|
79
|
+
* security's product_type has no entry (on its parent chain) in
|
|
80
|
+
* hierarchy.json default_price_types, e.g. FX_SPOT. Thrown by the Transaction
|
|
81
|
+
* params constructor before anything is built. Carries one violation on
|
|
82
|
+
* `price.price_type` whose object id is the security's UUID
|
|
83
|
+
* (docs/adr/default_price_types.md).
|
|
84
|
+
*/
|
|
85
|
+
class NoDefaultPriceTypeError extends ModelValidationError {
|
|
86
|
+
/**
|
|
87
|
+
* @param productType the ProductTypeProto name, e.g. `FX_SPOT`
|
|
88
|
+
* @param objectId the security's UUID, or undefined if it has none
|
|
89
|
+
*/
|
|
90
|
+
constructor(productType, objectId) {
|
|
91
|
+
super([violation('price.price_type', objectId, `no default price_type for product_type ${productType} in hierarchy.json default_price_types; pass price_type`)]);
|
|
92
|
+
this.name = 'NoDefaultPriceTypeError';
|
|
93
|
+
this.productType = productType;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.NoDefaultPriceTypeError = NoDefaultPriceTypeError;
|
|
77
97
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
78
98
|
function violation(field, objectId, message) {
|
|
79
99
|
const v = new field_violation_pb_1.FieldViolationProto();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,iGAA+F;AAC/F,uCAAoC;AAEpC;;;;;GAKG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAG3C,yEAAyE;IACzE,YAAY,UAAiC;QACzC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;SACxE;QACD,KAAK,CAAC,UAAU;aACX,GAAG,CAAC,CAAC,CAAC,EAAE,WAAC,OAAA,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,UAAU,EAAE,QAAQ,MAAA,UAAU,CAAC,CAAC,CAAC,mCAAI,MAAM,GAAG,CAAA,EAAA,CAAC;aAC9E,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CA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C,WAAW,yDAAyD,CAAC,CAAC,CAAC,CAAC;QACtH,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;CACJ;AAbD,0DAaC;AAED,oFAAoF;AACpF,SAAgB,SAAS,CAAC,KAAa,EAAE,QAA0B,EAAE,OAAe;IAChF,MAAM,CAAC,GAAG,IAAI,wCAAmB,EAAE,CAAC;IACpC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACtB,IAAI,QAAQ;QAAE,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACpD,OAAO,CAAC,CAAC;AACb,CAAC;AAND,8BAMC;AAED,SAAS,UAAU,CAAC,CAAsB;;IACtC,MAAM,GAAG,GAAG,MAAA,CAAC,CAAC,WAAW,EAAE,0CAAE,eAAe,EAAE,CAAC;IAC/C,iFAAiF;IACjF,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACnF,CAAC"}
|
|
@@ -83,6 +83,29 @@ export class MissingMarketDataError extends ModelValidationError {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Typed input error: a trade price is being built with no price_type and the
|
|
88
|
+
* security's product_type has no entry (on its parent chain) in
|
|
89
|
+
* hierarchy.json default_price_types, e.g. FX_SPOT. Thrown by the Transaction
|
|
90
|
+
* params constructor before anything is built. Carries one violation on
|
|
91
|
+
* `price.price_type` whose object id is the security's UUID
|
|
92
|
+
* (docs/adr/default_price_types.md).
|
|
93
|
+
*/
|
|
94
|
+
export class NoDefaultPriceTypeError extends ModelValidationError {
|
|
95
|
+
readonly productType: string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param productType the ProductTypeProto name, e.g. `FX_SPOT`
|
|
99
|
+
* @param objectId the security's UUID, or undefined if it has none
|
|
100
|
+
*/
|
|
101
|
+
constructor(productType: string, objectId: UUID | undefined) {
|
|
102
|
+
super([violation('price.price_type', objectId,
|
|
103
|
+
`no default price_type for product_type ${productType} in hierarchy.json default_price_types; pass price_type`)]);
|
|
104
|
+
this.name = 'NoDefaultPriceTypeError';
|
|
105
|
+
this.productType = productType;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
86
109
|
/** Builds one violation. `objectId` may be undefined when the input had no UUID. */
|
|
87
110
|
export function violation(field: string, objectId: UUID | undefined, message: string): FieldViolationProto {
|
|
88
111
|
const v = new FieldViolationProto();
|
|
@@ -21,10 +21,12 @@ declare class Price {
|
|
|
21
21
|
/**
|
|
22
22
|
* Factory method to create a Price from a Decimal value, Security, and ZonedDateTime.
|
|
23
23
|
* LM-449: an inline trade price may have no security; it is then left unset.
|
|
24
|
+
* LM-461: price_type is set only when `priceType` is given; this does no
|
|
25
|
+
* default lookup (the Transaction params constructor resolves it first).
|
|
24
26
|
*/
|
|
25
|
-
static create(price: Decimal, security: Security | null | undefined, asOf: ZonedDateTime): Price;
|
|
27
|
+
static create(price: Decimal, security: Security | null | undefined, asOf: ZonedDateTime, priceType?: PriceTypeProto): Price;
|
|
26
28
|
/**
|
|
27
|
-
* Creates a cash price (always 1.0) for a cash security
|
|
29
|
+
* Creates a cash price (always 1.0, so ABSOLUTE) for a cash security
|
|
28
30
|
*/
|
|
29
31
|
static getCashPrice(cashSecurity: Security, asOf: ZonedDateTime): Price;
|
|
30
32
|
getID(): UUID;
|
|
@@ -68,8 +68,10 @@ class Price {
|
|
|
68
68
|
/**
|
|
69
69
|
* Factory method to create a Price from a Decimal value, Security, and ZonedDateTime.
|
|
70
70
|
* LM-449: an inline trade price may have no security; it is then left unset.
|
|
71
|
+
* LM-461: price_type is set only when `priceType` is given; this does no
|
|
72
|
+
* default lookup (the Transaction params constructor resolves it first).
|
|
71
73
|
*/
|
|
72
|
-
static create(price, security, asOf) {
|
|
74
|
+
static create(price, security, asOf, priceType) {
|
|
73
75
|
const decimalValueProto = (0, decimal_1.encodeDecimal)((0, decimal_1.fromDecimalJs)(price));
|
|
74
76
|
const priceProto = new price_pb_1.PriceProto();
|
|
75
77
|
priceProto.setPrice(decimalValueProto);
|
|
@@ -78,13 +80,15 @@ class Price {
|
|
|
78
80
|
priceProto.setUuid(uuid_1.UUID.random().toUUIDProto());
|
|
79
81
|
if (security)
|
|
80
82
|
priceProto.setSecurity(security.proto);
|
|
83
|
+
if (priceType !== undefined)
|
|
84
|
+
priceProto.setPriceType(priceType);
|
|
81
85
|
return new Price(priceProto);
|
|
82
86
|
}
|
|
83
87
|
/**
|
|
84
|
-
* Creates a cash price (always 1.0) for a cash security
|
|
88
|
+
* Creates a cash price (always 1.0, so ABSOLUTE) for a cash security
|
|
85
89
|
*/
|
|
86
90
|
static getCashPrice(cashSecurity, asOf) {
|
|
87
|
-
return Price.create(new decimal_js_1.Decimal('1.0'), cashSecurity, asOf);
|
|
91
|
+
return Price.create(new decimal_js_1.Decimal('1.0'), cashSecurity, asOf, price_type_pb_1.PriceTypeProto.ABSOLUTE);
|
|
88
92
|
}
|
|
89
93
|
getID() {
|
|
90
94
|
const uuid = this.proto.getUuid();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Price.js","sourceRoot":"","sources":["Price.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAAuE;AACvE,kFAAgF;AAEhF,iFAAgF;AAChF,oEAA4C;AAC5C,gDAAkD;AAClD,wCAAqC;AACrC,2CAAqC;AACrC,uEAAyD;AACzD,8CAA8J;AAC9J,mFAAiF;AACjF,0DAA0D;AAE1D,MAAM,KAAK;IAGP,YAAY,KAAiB;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB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"}
|
|
@@ -54,8 +54,10 @@ class Price {
|
|
|
54
54
|
/**
|
|
55
55
|
* Factory method to create a Price from a Decimal value, Security, and ZonedDateTime.
|
|
56
56
|
* LM-449: an inline trade price may have no security; it is then left unset.
|
|
57
|
+
* LM-461: price_type is set only when `priceType` is given; this does no
|
|
58
|
+
* default lookup (the Transaction params constructor resolves it first).
|
|
57
59
|
*/
|
|
58
|
-
static create(price: Decimal, security: Security | null | undefined, asOf: ZonedDateTime): Price {
|
|
60
|
+
static create(price: Decimal, security: Security | null | undefined, asOf: ZonedDateTime, priceType?: PriceTypeProto): Price {
|
|
59
61
|
const decimalValueProto = encodeDecimal(fromDecimalJs(price));
|
|
60
62
|
|
|
61
63
|
const priceProto = new PriceProto();
|
|
@@ -64,15 +66,16 @@ class Price {
|
|
|
64
66
|
priceProto.setAsOf(asOf.toProto());
|
|
65
67
|
priceProto.setUuid(UUID.random().toUUIDProto());
|
|
66
68
|
if (security) priceProto.setSecurity(security.proto);
|
|
69
|
+
if (priceType !== undefined) priceProto.setPriceType(priceType);
|
|
67
70
|
|
|
68
71
|
return new Price(priceProto);
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
/**
|
|
72
|
-
* Creates a cash price (always 1.0) for a cash security
|
|
75
|
+
* Creates a cash price (always 1.0, so ABSOLUTE) for a cash security
|
|
73
76
|
*/
|
|
74
77
|
static getCashPrice(cashSecurity: Security, asOf: ZonedDateTime): Price {
|
|
75
|
-
return Price.create(new Decimal('1.0'), cashSecurity, asOf);
|
|
78
|
+
return Price.create(new Decimal('1.0'), cashSecurity, asOf, PriceTypeProto.ABSOLUTE);
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
getID(): UUID {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PriceTypeProto } from '../../../fintekkers/models/price/price_type_pb';
|
|
2
|
+
import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
3
|
+
/** A parsed, checked default_price_types section: node -> PriceTypeProto value. */
|
|
4
|
+
export declare class DefaultPriceTypes {
|
|
5
|
+
/** node -> type, as written in the section. Read-only. */
|
|
6
|
+
readonly entries: ReadonlyMap<string, PriceTypeProto>;
|
|
7
|
+
constructor(entries: Map<string, PriceTypeProto>);
|
|
8
|
+
/** The deepest entry on productType's parent chain, or null. */
|
|
9
|
+
defaultFor(productType: string): PriceTypeProto | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parses and checks a default_price_types section against the shipped
|
|
13
|
+
* product_types tree and the PriceTypeProto names. Throws when the section is
|
|
14
|
+
* missing (undefined) or not an object, a key is not a product_types node, or
|
|
15
|
+
* a value is not a PriceTypeProto name or is UNKNOWN_PRICE_TYPE. Exported for tests.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseDefaultPriceTypes(section: unknown): DefaultPriceTypes;
|
|
18
|
+
/** The shipped default_price_types section, parsed and checked on first use. */
|
|
19
|
+
export declare function shippedDefaultPriceTypes(): DefaultPriceTypes;
|
|
20
|
+
/**
|
|
21
|
+
* The table default for the security's product_type, or null when it has
|
|
22
|
+
* none. A missing security reads as PRODUCT_TYPE_UNKNOWN.
|
|
23
|
+
*/
|
|
24
|
+
export declare function defaultPriceTypeFor(security: SecurityProto | null | undefined): PriceTypeProto | null;
|
|
25
|
+
/**
|
|
26
|
+
* The price_type to put on a trade price for this security. An explicit
|
|
27
|
+
* priceType other than UNKNOWN_PRICE_TYPE is returned unchanged; otherwise the
|
|
28
|
+
* table default. Throws NoDefaultPriceTypeError naming the product when there
|
|
29
|
+
* is neither.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveTradePriceType(security: SecurityProto | null | undefined, priceType?: PriceTypeProto | null): PriceTypeProto;
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
exports.resolveTradePriceType = exports.defaultPriceTypeFor = exports.shippedDefaultPriceTypes = exports.parseDefaultPriceTypes = exports.DefaultPriceTypes = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* The default price_type of a trade price, by product. Backed by the
|
|
9
|
+
* default_price_types section of ledger-models-protos/hierarchy.json; there is
|
|
10
|
+
* no mapping table in code. Same rule in Java / Rust / Python / JS-TS. See
|
|
11
|
+
* docs/adr/default_price_types.md.
|
|
12
|
+
*
|
|
13
|
+
* Resolution walks from the security's product_type up its parent chain; the
|
|
14
|
+
* first node with an entry decides, so SOFR_SERIES -> RATE beats INDEX ->
|
|
15
|
+
* INDEX_LEVEL. A product with no entry anywhere on its chain has no default.
|
|
16
|
+
*
|
|
17
|
+
* resolveTradePriceType is what the Transaction params constructor calls: an
|
|
18
|
+
* explicit priceType wins (UNKNOWN_PRICE_TYPE, proto3's unset value, counts as
|
|
19
|
+
* omitted), then the table default, else NoDefaultPriceTypeError. It never
|
|
20
|
+
* returns UNKNOWN_PRICE_TYPE. A broken section throws at load, like
|
|
21
|
+
* product_inputs.
|
|
22
|
+
*/
|
|
23
|
+
const hierarchy_json_1 = __importDefault(require("../../../../hierarchy.json"));
|
|
24
|
+
const price_type_pb_1 = require("../../../fintekkers/models/price/price_type_pb");
|
|
25
|
+
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
26
|
+
const errors_1 = require("../errors");
|
|
27
|
+
const uuid_1 = require("../utils/uuid");
|
|
28
|
+
const product_hierarchy_1 = require("./product_hierarchy");
|
|
29
|
+
const SECTION = 'default_price_types';
|
|
30
|
+
const UNKNOWN = 'UNKNOWN_PRICE_TYPE';
|
|
31
|
+
function hasOwn(o, key) {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(o, key);
|
|
33
|
+
}
|
|
34
|
+
function bad(detail) {
|
|
35
|
+
return new Error(`hierarchy.json ${SECTION}: ${detail}`);
|
|
36
|
+
}
|
|
37
|
+
/** A parsed, checked default_price_types section: node -> PriceTypeProto value. */
|
|
38
|
+
class DefaultPriceTypes {
|
|
39
|
+
constructor(entries) {
|
|
40
|
+
const frozen = new Map(entries);
|
|
41
|
+
const readOnly = () => { throw new TypeError('DefaultPriceTypes entries are read-only'); };
|
|
42
|
+
frozen.set = readOnly;
|
|
43
|
+
frozen.delete = readOnly;
|
|
44
|
+
frozen.clear = readOnly;
|
|
45
|
+
this.entries = frozen;
|
|
46
|
+
}
|
|
47
|
+
/** The deepest entry on productType's parent chain, or null. */
|
|
48
|
+
defaultFor(productType) {
|
|
49
|
+
for (let node = productType; node !== null; node = (0, product_hierarchy_1.parentOf)(node)) {
|
|
50
|
+
const type = this.entries.get(node);
|
|
51
|
+
if (type !== undefined)
|
|
52
|
+
return type;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.DefaultPriceTypes = DefaultPriceTypes;
|
|
58
|
+
/**
|
|
59
|
+
* Parses and checks a default_price_types section against the shipped
|
|
60
|
+
* product_types tree and the PriceTypeProto names. Throws when the section is
|
|
61
|
+
* missing (undefined) or not an object, a key is not a product_types node, or
|
|
62
|
+
* a value is not a PriceTypeProto name or is UNKNOWN_PRICE_TYPE. Exported for tests.
|
|
63
|
+
*/
|
|
64
|
+
function parseDefaultPriceTypes(section) {
|
|
65
|
+
if (section === undefined)
|
|
66
|
+
throw bad('section missing from hierarchy.json');
|
|
67
|
+
if (typeof section !== 'object' || section === null || Array.isArray(section)) {
|
|
68
|
+
throw bad('section must be an object');
|
|
69
|
+
}
|
|
70
|
+
const productTypes = new Set((0, product_hierarchy_1.allProductTypes)());
|
|
71
|
+
const entries = new Map();
|
|
72
|
+
for (const [node, name] of Object.entries(section)) {
|
|
73
|
+
if (!productTypes.has(node))
|
|
74
|
+
throw bad(`node '${node}' is not in product_types`);
|
|
75
|
+
if (typeof name !== 'string' || !hasOwn(price_type_pb_1.PriceTypeProto, name)) {
|
|
76
|
+
throw bad(`value ${JSON.stringify(name)} for node ${node} is not a PriceTypeProto name`);
|
|
77
|
+
}
|
|
78
|
+
if (name === UNKNOWN)
|
|
79
|
+
throw bad(`node ${node} must not default to ${UNKNOWN}`);
|
|
80
|
+
entries.set(node, price_type_pb_1.PriceTypeProto[name]);
|
|
81
|
+
}
|
|
82
|
+
return new DefaultPriceTypes(entries);
|
|
83
|
+
}
|
|
84
|
+
exports.parseDefaultPriceTypes = parseDefaultPriceTypes;
|
|
85
|
+
let shipped;
|
|
86
|
+
/** The shipped default_price_types section, parsed and checked on first use. */
|
|
87
|
+
function shippedDefaultPriceTypes() {
|
|
88
|
+
if (!shipped) {
|
|
89
|
+
const root = hierarchy_json_1.default;
|
|
90
|
+
shipped = parseDefaultPriceTypes(hasOwn(root, SECTION) ? root[SECTION] : undefined);
|
|
91
|
+
}
|
|
92
|
+
return shipped;
|
|
93
|
+
}
|
|
94
|
+
exports.shippedDefaultPriceTypes = shippedDefaultPriceTypes;
|
|
95
|
+
/**
|
|
96
|
+
* The table default for the security's product_type, or null when it has
|
|
97
|
+
* none. A missing security reads as PRODUCT_TYPE_UNKNOWN.
|
|
98
|
+
*/
|
|
99
|
+
function defaultPriceTypeFor(security) {
|
|
100
|
+
return shippedDefaultPriceTypes().defaultFor(productTypeOf(security));
|
|
101
|
+
}
|
|
102
|
+
exports.defaultPriceTypeFor = defaultPriceTypeFor;
|
|
103
|
+
/**
|
|
104
|
+
* The price_type to put on a trade price for this security. An explicit
|
|
105
|
+
* priceType other than UNKNOWN_PRICE_TYPE is returned unchanged; otherwise the
|
|
106
|
+
* table default. Throws NoDefaultPriceTypeError naming the product when there
|
|
107
|
+
* is neither.
|
|
108
|
+
*/
|
|
109
|
+
function resolveTradePriceType(security, priceType) {
|
|
110
|
+
if (priceType !== undefined && priceType !== null && priceType !== price_type_pb_1.PriceTypeProto.UNKNOWN_PRICE_TYPE) {
|
|
111
|
+
return priceType;
|
|
112
|
+
}
|
|
113
|
+
const resolved = defaultPriceTypeFor(security);
|
|
114
|
+
if (resolved === null)
|
|
115
|
+
throw new errors_1.NoDefaultPriceTypeError(productTypeOf(security), uuidOf(security));
|
|
116
|
+
return resolved;
|
|
117
|
+
}
|
|
118
|
+
exports.resolveTradePriceType = resolveTradePriceType;
|
|
119
|
+
function productTypeOf(security) {
|
|
120
|
+
const value = security ? security.getProductType() : product_type_pb_1.ProductTypeProto.PRODUCT_TYPE_UNKNOWN;
|
|
121
|
+
for (const [k, v] of Object.entries(product_type_pb_1.ProductTypeProto)) {
|
|
122
|
+
if (v === value)
|
|
123
|
+
return k;
|
|
124
|
+
}
|
|
125
|
+
return String(value);
|
|
126
|
+
}
|
|
127
|
+
function uuidOf(security) {
|
|
128
|
+
var _a;
|
|
129
|
+
const raw = (_a = security === null || security === void 0 ? void 0 : security.getUuid()) === null || _a === void 0 ? void 0 : _a.getRawUuid_asU8();
|
|
130
|
+
return raw && raw.length === 16 ? uuid_1.UUID.fromU8Array(raw) : undefined;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=default_price_types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default_price_types.js","sourceRoot":"","sources":["default_price_types.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,gFAAmD;AACnD,kFAAgF;AAChF,yFAAuF;AAEvF,sCAAoD;AACpD,wCAAqC;AACrC,2DAAgE;AAEhE,MAAM,OAAO,GAAG,qBAAqB,CAAC;AACtC,MAAM,OAAO,GAAG,oBAAoB,CAAC;AAErC,SAAS,MAAM,CAAC,CAAS,EAAE,GAAW;IACpC,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,GAAG,CAAC,MAAc;IACzB,OAAO,IAAI,KAAK,CAAC,kBAAkB,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,mFAAmF;AACnF,MAAa,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G,OAAO,SAAS,CAAC;KAClB;IACD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,QAAQ,KAAK,IAAI;QAAE,MAAM,IAAI,gCAAuB,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpG,OAAO,QAAQ,CAAC;AAClB,CAAC;AAVD,sDAUC;AAED,SAAS,aAAa,CAAC,QAA0C;IAC/D,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,kCAAgB,CAAC,oBAAoB,CAAC;IAC3F,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,kCAAgB,CAAC,EAAE;QACrD,IAAI,CAAC,KAAK,KAAK;YAAE,OAAO,CAAC,CAAC;KAC3B;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,MAAM,CAAC,QAA0C;;IACxD,MAAM,GAAG,GAAG,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,EAAE,0CAAE,eAAe,EAAE,CAAC;IACnD,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
/**
|
|
27
|
+
* LM-461: default trade-price type by product, from hierarchy.json
|
|
28
|
+
* default_price_types. Parity with Python test_default_price_types.py, Java
|
|
29
|
+
* DefaultPriceTypesTest and Rust default_price_types_test.rs.
|
|
30
|
+
*
|
|
31
|
+
* The shared cases live in ledger-models-protos/fixtures/default_price_types_cases.json;
|
|
32
|
+
* expected values come from that file only, never from the resolver under test.
|
|
33
|
+
*/
|
|
34
|
+
const fs = __importStar(require("fs"));
|
|
35
|
+
const path = __importStar(require("path"));
|
|
36
|
+
const default_price_types_1 = require("./default_price_types");
|
|
37
|
+
const errors_1 = require("../errors");
|
|
38
|
+
const price_type_pb_1 = require("../../../fintekkers/models/price/price_type_pb");
|
|
39
|
+
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
40
|
+
const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
41
|
+
const PROTOS = path.resolve(__dirname, '../../../../../ledger-models-protos');
|
|
42
|
+
const CASES = JSON.parse(fs.readFileSync(path.join(PROTOS, 'fixtures/default_price_types_cases.json'), 'utf-8')).cases;
|
|
43
|
+
function sourceSection() {
|
|
44
|
+
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).default_price_types;
|
|
45
|
+
}
|
|
46
|
+
const PRODUCT_TYPES = product_type_pb_1.ProductTypeProto;
|
|
47
|
+
const PRICE_TYPES = price_type_pb_1.PriceTypeProto;
|
|
48
|
+
// ---------- metric 3: every product resolves to the fixture, never UNKNOWN ----------
|
|
49
|
+
test('the fixture lists every ProductTypeProto enum value', () => {
|
|
50
|
+
expect(Object.keys(CASES).sort()).toEqual(Object.keys(product_type_pb_1.ProductTypeProto).sort());
|
|
51
|
+
});
|
|
52
|
+
test('the fixture covers deepest-node-wins', () => {
|
|
53
|
+
expect(CASES.SOFR_SERIES).toBe('RATE');
|
|
54
|
+
expect(CASES.T_BILL_13_WEEK_SERIES).toBe('RATE');
|
|
55
|
+
expect(CASES.CPI_SERIES).toBe('INDEX_LEVEL');
|
|
56
|
+
});
|
|
57
|
+
test.each(Object.entries(CASES))('%s resolves as the fixture says (%s)', (productType, expected) => {
|
|
58
|
+
const security = new security_pb_1.SecurityProto().setProductType(PRODUCT_TYPES[productType]);
|
|
59
|
+
if (expected === 'raises') {
|
|
60
|
+
expect((0, default_price_types_1.defaultPriceTypeFor)(security)).toBeNull();
|
|
61
|
+
expect(() => (0, default_price_types_1.resolveTradePriceType)(security)).toThrow(errors_1.NoDefaultPriceTypeError);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const resolved = (0, default_price_types_1.resolveTradePriceType)(security);
|
|
65
|
+
expect(resolved).toBe(PRICE_TYPES[expected]);
|
|
66
|
+
expect(resolved).not.toBe(price_type_pb_1.PriceTypeProto.UNKNOWN_PRICE_TYPE);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
test('each table key resolves to its own entry', () => {
|
|
70
|
+
const section = sourceSection();
|
|
71
|
+
expect(Object.keys(section).length).toBeGreaterThan(0);
|
|
72
|
+
for (const [node, name] of Object.entries(section)) {
|
|
73
|
+
expect((0, default_price_types_1.shippedDefaultPriceTypes)().defaultFor(node)).toBe(PRICE_TYPES[name]);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
test('the shipped entries are read-only', () => {
|
|
77
|
+
const entries = (0, default_price_types_1.shippedDefaultPriceTypes)().entries;
|
|
78
|
+
expect(() => entries.set('BOND', price_type_pb_1.PriceTypeProto.ABSOLUTE)).toThrow(TypeError);
|
|
79
|
+
expect((0, default_price_types_1.shippedDefaultPriceTypes)().defaultFor('BOND')).toBe(price_type_pb_1.PriceTypeProto.PERCENTAGE);
|
|
80
|
+
});
|
|
81
|
+
test('the source section parses to the shipped table', () => {
|
|
82
|
+
expect([...(0, default_price_types_1.parseDefaultPriceTypes)(sourceSection()).entries])
|
|
83
|
+
.toEqual([...(0, default_price_types_1.shippedDefaultPriceTypes)().entries]);
|
|
84
|
+
});
|
|
85
|
+
// ---------- guardrail 3: a broken section throws at load ----------
|
|
86
|
+
test.each([
|
|
87
|
+
['an unknown node', { NOT_A_NODE: 'PERCENTAGE' }, 'NOT_A_NODE'],
|
|
88
|
+
['an unknown type name', { BOND: 'PERCENT' }, 'PERCENT'],
|
|
89
|
+
['an UNKNOWN_PRICE_TYPE value', { BOND: 'UNKNOWN_PRICE_TYPE' }, 'UNKNOWN_PRICE_TYPE'],
|
|
90
|
+
['an inherited key as a type name', { BOND: 'toString' }, 'toString'],
|
|
91
|
+
['a non-string value', { BOND: 2 }, 'BOND'],
|
|
92
|
+
['a missing section', undefined, 'missing'],
|
|
93
|
+
['a section that is not an object', ['BOND', 'PERCENTAGE'], 'object'],
|
|
94
|
+
])('%s throws', (_name, section, match) => {
|
|
95
|
+
expect(() => (0, default_price_types_1.parseDefaultPriceTypes)(section)).toThrow(/default_price_types/);
|
|
96
|
+
expect(() => (0, default_price_types_1.parseDefaultPriceTypes)(section)).toThrow(match);
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=default_price_types.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default_price_types.test.js","sourceRoot":"","sources":["default_price_types.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;GAOG;AACH,uCAAyB;AACzB,2CAA6B;AAC7B,+DAK+B;AAC/B,sCAAoD;AACpD,kFAAgF;AAChF,yFAAuF;AACvF,iFAAgF;AAEhF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,qCAAqC,CAAC,CAAC;AAE9E,MAAM,KAAK,GAA2B,IAAI,CAAC,KAAK,CAC9C,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,yCAAyC,CAAC,EAAE,OAAO,CAAC,CACvF,CAAC,KAAK,CAAC;AAER,SAAS,aAAa;IACpB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC;AACvG,CAAC;AAED,MAAM,aAAa,GAAG,kCAA+D,CAAC;AACtF,MAAM,WAAW,GAAG,8BAA2D,CAAC;AAEhF,uFAAuF;AAEvF,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;IAC/D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAgB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE;IAChD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,CAAC,KAAK,CAAC,qBAAqB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C;IAC3C,CAAC,iCAAiC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,QAAQ,CAAC;CACtE,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;IACxC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,4CAAsB,EAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC7E,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,4CAAsB,EAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LM-461: default trade-price type by product, from hierarchy.json
|
|
3
|
+
* default_price_types. Parity with Python test_default_price_types.py, Java
|
|
4
|
+
* DefaultPriceTypesTest and Rust default_price_types_test.rs.
|
|
5
|
+
*
|
|
6
|
+
* The shared cases live in ledger-models-protos/fixtures/default_price_types_cases.json;
|
|
7
|
+
* expected values come from that file only, never from the resolver under test.
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import {
|
|
12
|
+
defaultPriceTypeFor,
|
|
13
|
+
parseDefaultPriceTypes,
|
|
14
|
+
resolveTradePriceType,
|
|
15
|
+
shippedDefaultPriceTypes,
|
|
16
|
+
} from './default_price_types';
|
|
17
|
+
import { NoDefaultPriceTypeError } from '../errors';
|
|
18
|
+
import { PriceTypeProto } from '../../../fintekkers/models/price/price_type_pb';
|
|
19
|
+
import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
|
|
20
|
+
import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
21
|
+
|
|
22
|
+
const PROTOS = path.resolve(__dirname, '../../../../../ledger-models-protos');
|
|
23
|
+
|
|
24
|
+
const CASES: Record<string, string> = JSON.parse(
|
|
25
|
+
fs.readFileSync(path.join(PROTOS, 'fixtures/default_price_types_cases.json'), 'utf-8'),
|
|
26
|
+
).cases;
|
|
27
|
+
|
|
28
|
+
function sourceSection(): Record<string, string> {
|
|
29
|
+
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).default_price_types;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const PRODUCT_TYPES = ProductTypeProto as unknown as Record<string, ProductTypeProto>;
|
|
33
|
+
const PRICE_TYPES = PriceTypeProto as unknown as Record<string, PriceTypeProto>;
|
|
34
|
+
|
|
35
|
+
// ---------- metric 3: every product resolves to the fixture, never UNKNOWN ----------
|
|
36
|
+
|
|
37
|
+
test('the fixture lists every ProductTypeProto enum value', () => {
|
|
38
|
+
expect(Object.keys(CASES).sort()).toEqual(Object.keys(ProductTypeProto).sort());
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('the fixture covers deepest-node-wins', () => {
|
|
42
|
+
expect(CASES.SOFR_SERIES).toBe('RATE');
|
|
43
|
+
expect(CASES.T_BILL_13_WEEK_SERIES).toBe('RATE');
|
|
44
|
+
expect(CASES.CPI_SERIES).toBe('INDEX_LEVEL');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test.each(Object.entries(CASES))('%s resolves as the fixture says (%s)', (productType, expected) => {
|
|
48
|
+
const security = new SecurityProto().setProductType(PRODUCT_TYPES[productType]);
|
|
49
|
+
if (expected === 'raises') {
|
|
50
|
+
expect(defaultPriceTypeFor(security)).toBeNull();
|
|
51
|
+
expect(() => resolveTradePriceType(security)).toThrow(NoDefaultPriceTypeError);
|
|
52
|
+
} else {
|
|
53
|
+
const resolved = resolveTradePriceType(security);
|
|
54
|
+
expect(resolved).toBe(PRICE_TYPES[expected]);
|
|
55
|
+
expect(resolved).not.toBe(PriceTypeProto.UNKNOWN_PRICE_TYPE);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('each table key resolves to its own entry', () => {
|
|
60
|
+
const section = sourceSection();
|
|
61
|
+
expect(Object.keys(section).length).toBeGreaterThan(0);
|
|
62
|
+
for (const [node, name] of Object.entries(section)) {
|
|
63
|
+
expect(shippedDefaultPriceTypes().defaultFor(node)).toBe(PRICE_TYPES[name]);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('the shipped entries are read-only', () => {
|
|
68
|
+
const entries = shippedDefaultPriceTypes().entries as Map<string, PriceTypeProto>;
|
|
69
|
+
expect(() => entries.set('BOND', PriceTypeProto.ABSOLUTE)).toThrow(TypeError);
|
|
70
|
+
expect(shippedDefaultPriceTypes().defaultFor('BOND')).toBe(PriceTypeProto.PERCENTAGE);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('the source section parses to the shipped table', () => {
|
|
74
|
+
expect([...parseDefaultPriceTypes(sourceSection()).entries])
|
|
75
|
+
.toEqual([...shippedDefaultPriceTypes().entries]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// ---------- guardrail 3: a broken section throws at load ----------
|
|
79
|
+
|
|
80
|
+
test.each([
|
|
81
|
+
['an unknown node', { NOT_A_NODE: 'PERCENTAGE' }, 'NOT_A_NODE'],
|
|
82
|
+
['an unknown type name', { BOND: 'PERCENT' }, 'PERCENT'],
|
|
83
|
+
['an UNKNOWN_PRICE_TYPE value', { BOND: 'UNKNOWN_PRICE_TYPE' }, 'UNKNOWN_PRICE_TYPE'],
|
|
84
|
+
['an inherited key as a type name', { BOND: 'toString' }, 'toString'],
|
|
85
|
+
['a non-string value', { BOND: 2 }, 'BOND'],
|
|
86
|
+
['a missing section', undefined, 'missing'],
|
|
87
|
+
['a section that is not an object', ['BOND', 'PERCENTAGE'], 'object'],
|
|
88
|
+
])('%s throws', (_name, section, match) => {
|
|
89
|
+
expect(() => parseDefaultPriceTypes(section)).toThrow(/default_price_types/);
|
|
90
|
+
expect(() => parseDefaultPriceTypes(section)).toThrow(match);
|
|
91
|
+
});
|