@barchart/portfolio-api-common 1.2.11 → 1.2.15
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.
|
@@ -73,6 +73,28 @@ module.exports = (() => {
|
|
|
73
73
|
return valid.map(d => d.type);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Returns transaction types which can be initiated by the user, regardless
|
|
78
|
+
* of instrument type.
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
* @static
|
|
82
|
+
* @return {Array.<TransactionType>}
|
|
83
|
+
*/
|
|
84
|
+
static getUserInitiatedTransactionTypes() {
|
|
85
|
+
return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
|
|
86
|
+
const instrumentTypes = validTransactionTypes[key];
|
|
87
|
+
|
|
88
|
+
instrumentTypes.forEach((data) => {
|
|
89
|
+
if (data.user) {
|
|
90
|
+
types.push(data.type);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return types;
|
|
95
|
+
}, [ ]));
|
|
96
|
+
}
|
|
97
|
+
|
|
76
98
|
/**
|
|
77
99
|
* Checks to see if an transaction type is applicable to an instrument type.
|
|
78
100
|
*
|
|
@@ -197,8 +197,18 @@ module.exports = (() => {
|
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
formatters.set(TransactionType.VALUATION, (t) => {
|
|
200
|
+
let rate;
|
|
201
|
+
|
|
202
|
+
if (t.valuation.rate) {
|
|
203
|
+
rate = t.valuation.rate;
|
|
204
|
+
} else if (t.snapshot.open.getIsZero()) {
|
|
205
|
+
rate = null;
|
|
206
|
+
} else {
|
|
207
|
+
rate = t.valuation.value.divide(t.snapshot.open)
|
|
208
|
+
}
|
|
209
|
+
|
|
200
210
|
return {
|
|
201
|
-
price:
|
|
211
|
+
price: rate
|
|
202
212
|
};
|
|
203
213
|
});
|
|
204
214
|
|
|
@@ -201,6 +201,7 @@ module.exports = (() => {
|
|
|
201
201
|
.withField('split.reference', DataType.STRING, true)
|
|
202
202
|
.withField('charge.amount', DataType.DECIMAL, true)
|
|
203
203
|
.withField('income.amount', DataType.DECIMAL, true)
|
|
204
|
+
.withField('valuation.rate', DataType.DECIMAL, true)
|
|
204
205
|
.withField('valuation.value', DataType.DECIMAL, true)
|
|
205
206
|
.withField('system.sequence', DataType.NUMBER)
|
|
206
207
|
.withField('system.version', DataType.STRING)
|
|
@@ -239,6 +240,7 @@ module.exports = (() => {
|
|
|
239
240
|
.withField('split.reference', DataType.STRING, true)
|
|
240
241
|
.withField('charge.amount', DataType.DECIMAL, true)
|
|
241
242
|
.withField('income.amount', DataType.DECIMAL, true)
|
|
243
|
+
.withField('valuation.rate', DataType.DECIMAL, true)
|
|
242
244
|
.withField('valuation.value', DataType.DECIMAL, true)
|
|
243
245
|
.schema
|
|
244
246
|
);
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1062,6 +1062,28 @@ module.exports = (() => {
|
|
|
1062
1062
|
return valid.map(d => d.type);
|
|
1063
1063
|
}
|
|
1064
1064
|
|
|
1065
|
+
/**
|
|
1066
|
+
* Returns transaction types which can be initiated by the user, regardless
|
|
1067
|
+
* of instrument type.
|
|
1068
|
+
*
|
|
1069
|
+
* @public
|
|
1070
|
+
* @static
|
|
1071
|
+
* @return {Array.<TransactionType>}
|
|
1072
|
+
*/
|
|
1073
|
+
static getUserInitiatedTransactionTypes() {
|
|
1074
|
+
return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
|
|
1075
|
+
const instrumentTypes = validTransactionTypes[key];
|
|
1076
|
+
|
|
1077
|
+
instrumentTypes.forEach((data) => {
|
|
1078
|
+
if (data.user) {
|
|
1079
|
+
types.push(data.type);
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
return types;
|
|
1084
|
+
}, [ ]));
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1065
1087
|
/**
|
|
1066
1088
|
* Checks to see if an transaction type is applicable to an instrument type.
|
|
1067
1089
|
*
|
|
@@ -9226,6 +9248,20 @@ describe('When validating transaction order', () => {
|
|
|
9226
9248
|
});
|
|
9227
9249
|
});
|
|
9228
9250
|
|
|
9251
|
+
describe('When requesting all the user-initiated transaction types', () => {
|
|
9252
|
+
'use strict';
|
|
9253
|
+
|
|
9254
|
+
let userInitiated;
|
|
9255
|
+
|
|
9256
|
+
beforeEach(() => {
|
|
9257
|
+
userInitiated = TransactionValidator.getUserInitiatedTransactionTypes();
|
|
9258
|
+
});
|
|
9259
|
+
|
|
9260
|
+
it('Only nine types should be returned', () => {
|
|
9261
|
+
expect(userInitiated.length).toEqual(9);
|
|
9262
|
+
});
|
|
9263
|
+
});
|
|
9264
|
+
|
|
9229
9265
|
},{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":18}],37:[function(require,module,exports){
|
|
9230
9266
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
9231
9267
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
@@ -41,3 +41,17 @@ describe('When validating transaction order', () => {
|
|
|
41
41
|
expect(TransactionValidator.validateOrder([ build(1, '2018-05-02'), build(2, '2018-05-01'), build(3, '2018-04-30') ])).toEqual(false);
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
describe('When requesting all the user-initiated transaction types', () => {
|
|
46
|
+
'use strict';
|
|
47
|
+
|
|
48
|
+
let userInitiated;
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
userInitiated = TransactionValidator.getUserInitiatedTransactionTypes();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('Only nine types should be returned', () => {
|
|
55
|
+
expect(userInitiated.length).toEqual(9);
|
|
56
|
+
});
|
|
57
|
+
});
|