@barchart/portfolio-api-common 1.0.237 → 1.0.238
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,18 +36,19 @@ 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
40
|
|
|
41
|
-
|
|
41
|
+
delete instrument.id;
|
|
42
|
+
|
|
43
|
+
map[p.position] = instrument;
|
|
42
44
|
}, { });
|
|
43
45
|
|
|
44
46
|
return transactions.reduce((list, transaction) => {
|
|
45
47
|
const position = transaction.position;
|
|
46
48
|
|
|
47
49
|
if (instruments.hasOwnProperty(position)) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let formatted = getBasicTransaction(transaction);
|
|
50
|
+
let instrument = instruments[position];
|
|
51
|
+
let formatted = getBasicTransaction(transaction, instrument);
|
|
51
52
|
|
|
52
53
|
if (formatters.has(transaction.type)) {
|
|
53
54
|
const formatterFunction = formatters.get(transaction.type);
|
|
@@ -55,7 +56,7 @@ module.exports = (() => {
|
|
|
55
56
|
|
|
56
57
|
Object.keys(formattedTransaction).map((key) => {
|
|
57
58
|
if (!is.undefined(formattedTransaction[key]) && formattedTransaction[key] instanceof Decimal) {
|
|
58
|
-
const precision =
|
|
59
|
+
const precision = instrument.currency.precision;
|
|
59
60
|
|
|
60
61
|
formattedTransaction[key] = formatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
|
|
61
62
|
}
|
|
@@ -86,20 +87,14 @@ module.exports = (() => {
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
const getBasicTransaction = (t) => {
|
|
90
|
-
|
|
90
|
+
const getBasicTransaction = (t, i) => {
|
|
91
|
+
return {
|
|
91
92
|
date: t.date,
|
|
92
93
|
type: t.type.display,
|
|
93
94
|
sequence: t.sequence,
|
|
94
|
-
instrument:
|
|
95
|
+
instrument: i,
|
|
95
96
|
position: t.position
|
|
96
97
|
};
|
|
97
|
-
|
|
98
|
-
if (basic.instrument) {
|
|
99
|
-
delete basic.instrument.id;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return basic;
|
|
103
98
|
};
|
|
104
99
|
|
|
105
100
|
const formatters = new Map();
|