@barchart/portfolio-api-common 1.0.237 → 1.0.241
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.
|
@@ -27,7 +27,7 @@ module.exports = (() => {
|
|
|
27
27
|
* @static
|
|
28
28
|
* @param {Array<Object>} transactions
|
|
29
29
|
* @param {Array<Object>} positions
|
|
30
|
-
* @param {Boolean=} append
|
|
30
|
+
* @param {Boolean=} append - Warning, if true, the transaction array will be mutated.
|
|
31
31
|
* @returns {Array}
|
|
32
32
|
*/
|
|
33
33
|
static format(transactions, positions, append) {
|
|
@@ -36,7 +36,11 @@ module.exports = (() => {
|
|
|
36
36
|
assert.argumentIsOptional(append, 'append', Boolean);
|
|
37
37
|
|
|
38
38
|
const instruments = positions.reduce((map, p) => {
|
|
39
|
-
|
|
39
|
+
const instrument = Object.assign({ }, p.instrument || { });
|
|
40
|
+
|
|
41
|
+
delete instrument.id;
|
|
42
|
+
|
|
43
|
+
map[p.position] = instrument;
|
|
40
44
|
|
|
41
45
|
return map;
|
|
42
46
|
}, { });
|
|
@@ -45,9 +49,8 @@ module.exports = (() => {
|
|
|
45
49
|
const position = transaction.position;
|
|
46
50
|
|
|
47
51
|
if (instruments.hasOwnProperty(position)) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let formatted = getBasicTransaction(transaction);
|
|
52
|
+
let instrument = instruments[position];
|
|
53
|
+
let formatted = getBasicTransaction(transaction, instrument);
|
|
51
54
|
|
|
52
55
|
if (formatters.has(transaction.type)) {
|
|
53
56
|
const formatterFunction = formatters.get(transaction.type);
|
|
@@ -55,7 +58,7 @@ module.exports = (() => {
|
|
|
55
58
|
|
|
56
59
|
Object.keys(formattedTransaction).map((key) => {
|
|
57
60
|
if (!is.undefined(formattedTransaction[key]) && formattedTransaction[key] instanceof Decimal) {
|
|
58
|
-
const precision =
|
|
61
|
+
const precision = instrument.currency.precision;
|
|
59
62
|
|
|
60
63
|
formattedTransaction[key] = formatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
|
|
61
64
|
}
|
|
@@ -86,20 +89,14 @@ module.exports = (() => {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
const getBasicTransaction = (t) => {
|
|
90
|
-
|
|
92
|
+
const getBasicTransaction = (t, i) => {
|
|
93
|
+
return {
|
|
91
94
|
date: t.date,
|
|
92
95
|
type: t.type.display,
|
|
93
96
|
sequence: t.sequence,
|
|
94
|
-
instrument:
|
|
97
|
+
instrument: i,
|
|
95
98
|
position: t.position
|
|
96
99
|
};
|
|
97
|
-
|
|
98
|
-
if (basic.instrument) {
|
|
99
|
-
delete basic.instrument.id;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return basic;
|
|
103
100
|
};
|
|
104
101
|
|
|
105
102
|
const formatters = new Map();
|
|
@@ -121,7 +118,7 @@ module.exports = (() => {
|
|
|
121
118
|
formatters.set(TransactionType.DIVIDEND, (t) => {
|
|
122
119
|
return {
|
|
123
120
|
shares: t.snapshot.open,
|
|
124
|
-
total: t.dividend.
|
|
121
|
+
total: t.dividend.amount,
|
|
125
122
|
rate: t.dividend.rate
|
|
126
123
|
};
|
|
127
124
|
});
|
package/package.json
CHANGED