@barchart/portfolio-api-common 1.2.68 → 1.2.69
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.
|
@@ -31,12 +31,14 @@ module.exports = (() => {
|
|
|
31
31
|
* @param {Array.<Object>} transactions
|
|
32
32
|
* @param {Array.<Object>} positions
|
|
33
33
|
* @param {Boolean=} mutate
|
|
34
|
+
* @param {Boolean=} descending
|
|
34
35
|
* @returns {Array}
|
|
35
36
|
*/
|
|
36
|
-
static format(transactions, positions, mutate) {
|
|
37
|
+
static format(transactions, positions, mutate, descending) {
|
|
37
38
|
assert.argumentIsArray(transactions, 'transactions');
|
|
38
39
|
assert.argumentIsArray(positions, 'positions');
|
|
39
40
|
assert.argumentIsOptional(mutate, 'mutate', Boolean);
|
|
41
|
+
assert.argumentIsOptional(descending, 'descending', Boolean);
|
|
40
42
|
|
|
41
43
|
const instruments = positions.reduce((map, p) => {
|
|
42
44
|
const instrument = Object.assign({ }, p.instrument || { });
|
|
@@ -84,6 +86,14 @@ module.exports = (() => {
|
|
|
84
86
|
return list;
|
|
85
87
|
}, [ ]);
|
|
86
88
|
|
|
89
|
+
let comparator;
|
|
90
|
+
|
|
91
|
+
if (is.boolean(descending) && descending) {
|
|
92
|
+
comparator = comparatorDescending;
|
|
93
|
+
} else {
|
|
94
|
+
comparator = comparatorAscending;
|
|
95
|
+
}
|
|
96
|
+
|
|
87
97
|
a.sort(comparator);
|
|
88
98
|
|
|
89
99
|
a.forEach((t) => {
|
|
@@ -99,9 +109,21 @@ module.exports = (() => {
|
|
|
99
109
|
* @public
|
|
100
110
|
* @static
|
|
101
111
|
* @param {Array.<Object>} transactions
|
|
112
|
+
* @param {Boolean=} descending
|
|
102
113
|
* @returns {Array}
|
|
103
114
|
*/
|
|
104
|
-
sort(transactions) {
|
|
115
|
+
sort(transactions, descending) {
|
|
116
|
+
assert.argumentIsArray(transactions, 'transactions');
|
|
117
|
+
assert.argumentIsOptional(descending, 'descending', Boolean);
|
|
118
|
+
|
|
119
|
+
let comparator;
|
|
120
|
+
|
|
121
|
+
if (is.boolean(descending) && descending) {
|
|
122
|
+
comparator = comparatorDescending;
|
|
123
|
+
} else {
|
|
124
|
+
comparator = comparatorAscending;
|
|
125
|
+
}
|
|
126
|
+
|
|
105
127
|
return transactions.sort(comparator);
|
|
106
128
|
}
|
|
107
129
|
|
|
@@ -277,15 +299,14 @@ module.exports = (() => {
|
|
|
277
299
|
}
|
|
278
300
|
}
|
|
279
301
|
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}).toComparator();
|
|
302
|
+
const comparatorAscending = ComparatorBuilder.startWith((a, b) => Day.compareDays(a.date, b.date))
|
|
303
|
+
.thenBy((a, b) => comparators.compareNumbers(getInstrumentTypePriority(a.instrument.type), getInstrumentTypePriority(b.instrument.type))
|
|
304
|
+
.thenBy((a, b) => comparators.compareStrings(a.instrument.id, b.instrument.id))
|
|
305
|
+
.thenBy((a, b) => comparators.compareNumbers(a.sequence, b.sequence))
|
|
306
|
+
.toComparator();
|
|
307
|
+
|
|
308
|
+
const comparatorDescending = ComparatorBuilder.startWith((a, b) => comparatorAscending(b, a))
|
|
309
|
+
.toComparator();
|
|
289
310
|
|
|
290
311
|
return TransactionFormatter;
|
|
291
312
|
})();
|