@barchart/portfolio-api-common 1.2.67 → 1.2.71
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.
|
@@ -46,7 +46,6 @@ module.exports = (() => {
|
|
|
46
46
|
this._usesSymbols = usesSymbols;
|
|
47
47
|
this._hasCorporateActions = hasCorporateActions;
|
|
48
48
|
this._closeFractional = closeFractional;
|
|
49
|
-
this._closeFractional = strictOrdering;
|
|
50
49
|
this._roundQuantity = roundQuantity;
|
|
51
50
|
this._strictOrdering = strictOrdering;
|
|
52
51
|
|
|
@@ -19,6 +19,25 @@ module.exports = (() => {
|
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Determines the desired sequence number for a transaction.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
* @param {Object} transaction
|
|
27
|
+
* @return {Number}
|
|
28
|
+
*/
|
|
29
|
+
static getSortSequence(transaction) {
|
|
30
|
+
let effective;
|
|
31
|
+
|
|
32
|
+
if (is.number(transaction.resequence)) {
|
|
33
|
+
effective = transaction.resequence;
|
|
34
|
+
} else {
|
|
35
|
+
effective = transaction.sequence;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return effective;
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
/**
|
|
23
42
|
* Given an array of transactions, ensures that all sequence numbers and dates
|
|
24
43
|
* are properly ordered.
|
|
@@ -85,7 +104,7 @@ module.exports = (() => {
|
|
|
85
104
|
assert.argumentIsArray(transactions, 'transactions');
|
|
86
105
|
assert.argumentIsOptional(strict, 'strict', Boolean);
|
|
87
106
|
|
|
88
|
-
return transactions.findIndex((t, i, a) => t
|
|
107
|
+
return transactions.findIndex((t, i, a) => TransactionValidator.getSortSequence(t) !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && is.boolean(strict) && strict && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
89
108
|
}
|
|
90
109
|
|
|
91
110
|
/**
|
|
@@ -30,13 +30,14 @@ module.exports = (() => {
|
|
|
30
30
|
* @static
|
|
31
31
|
* @param {Array.<Object>} transactions
|
|
32
32
|
* @param {Array.<Object>} positions
|
|
33
|
-
* @param {Boolean=}
|
|
33
|
+
* @param {Boolean=} descending
|
|
34
34
|
* @returns {Array}
|
|
35
35
|
*/
|
|
36
|
-
static format(transactions, positions, mutate) {
|
|
36
|
+
static format(transactions, positions, mutate, descending) {
|
|
37
37
|
assert.argumentIsArray(transactions, 'transactions');
|
|
38
38
|
assert.argumentIsArray(positions, 'positions');
|
|
39
39
|
assert.argumentIsOptional(mutate, 'mutate', Boolean);
|
|
40
|
+
assert.argumentIsOptional(descending, 'descending', Boolean);
|
|
40
41
|
|
|
41
42
|
const instruments = positions.reduce((map, p) => {
|
|
42
43
|
const instrument = Object.assign({ }, p.instrument || { });
|
|
@@ -68,22 +69,20 @@ module.exports = (() => {
|
|
|
68
69
|
formatted = Object.assign({}, formatted, formattedTransaction);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (mutate) {
|
|
74
|
-
transaction.formatted = formatted;
|
|
75
|
-
|
|
76
|
-
transactionToInsert = transaction;
|
|
77
|
-
} else {
|
|
78
|
-
transactionToInsert = formatted;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
list.push(transactionToInsert);
|
|
72
|
+
list.push(formatted);
|
|
82
73
|
}
|
|
83
74
|
|
|
84
75
|
return list;
|
|
85
76
|
}, [ ]);
|
|
86
77
|
|
|
78
|
+
let comparator;
|
|
79
|
+
|
|
80
|
+
if (is.boolean(descending) && descending) {
|
|
81
|
+
comparator = comparatorDescending;
|
|
82
|
+
} else {
|
|
83
|
+
comparator = comparatorAscending;
|
|
84
|
+
}
|
|
85
|
+
|
|
87
86
|
a.sort(comparator);
|
|
88
87
|
|
|
89
88
|
a.forEach((t) => {
|
|
@@ -99,9 +98,21 @@ module.exports = (() => {
|
|
|
99
98
|
* @public
|
|
100
99
|
* @static
|
|
101
100
|
* @param {Array.<Object>} transactions
|
|
101
|
+
* @param {Boolean=} descending
|
|
102
102
|
* @returns {Array}
|
|
103
103
|
*/
|
|
104
|
-
sort(transactions) {
|
|
104
|
+
sort(transactions, descending) {
|
|
105
|
+
assert.argumentIsArray(transactions, 'transactions');
|
|
106
|
+
assert.argumentIsOptional(descending, 'descending', Boolean);
|
|
107
|
+
|
|
108
|
+
let comparator;
|
|
109
|
+
|
|
110
|
+
if (is.boolean(descending) && descending) {
|
|
111
|
+
comparator = comparatorDescending;
|
|
112
|
+
} else {
|
|
113
|
+
comparator = comparatorAscending;
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
return transactions.sort(comparator);
|
|
106
117
|
}
|
|
107
118
|
|
|
@@ -277,15 +288,14 @@ module.exports = (() => {
|
|
|
277
288
|
}
|
|
278
289
|
}
|
|
279
290
|
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}).toComparator();
|
|
291
|
+
const comparatorAscending = ComparatorBuilder.startWith((a, b) => Day.compareDays(a.date, b.date))
|
|
292
|
+
.thenBy((a, b) => comparators.compareNumbers(getInstrumentTypePriority(a.instrument.type), getInstrumentTypePriority(b.instrument.type)))
|
|
293
|
+
.thenBy((a, b) => comparators.compareStrings(a.instrument.id, b.instrument.id))
|
|
294
|
+
.thenBy((a, b) => comparators.compareNumbers(a.sequence, b.sequence))
|
|
295
|
+
.toComparator();
|
|
296
|
+
|
|
297
|
+
const comparatorDescending = ComparatorBuilder.startWith((a, b) => comparatorAscending(b, a))
|
|
298
|
+
.toComparator();
|
|
289
299
|
|
|
290
300
|
return TransactionFormatter;
|
|
291
301
|
})();
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -47,7 +47,6 @@ module.exports = (() => {
|
|
|
47
47
|
this._usesSymbols = usesSymbols;
|
|
48
48
|
this._hasCorporateActions = hasCorporateActions;
|
|
49
49
|
this._closeFractional = closeFractional;
|
|
50
|
-
this._closeFractional = strictOrdering;
|
|
51
50
|
this._roundQuantity = roundQuantity;
|
|
52
51
|
this._strictOrdering = strictOrdering;
|
|
53
52
|
|
|
@@ -1103,6 +1102,25 @@ module.exports = (() => {
|
|
|
1103
1102
|
|
|
1104
1103
|
}
|
|
1105
1104
|
|
|
1105
|
+
/**
|
|
1106
|
+
* Determines the desired sequence number for a transaction.
|
|
1107
|
+
*
|
|
1108
|
+
* @public
|
|
1109
|
+
* @param {Object} transaction
|
|
1110
|
+
* @return {Number}
|
|
1111
|
+
*/
|
|
1112
|
+
static getSortSequence(transaction) {
|
|
1113
|
+
let effective;
|
|
1114
|
+
|
|
1115
|
+
if (is.number(transaction.resequence)) {
|
|
1116
|
+
effective = transaction.resequence;
|
|
1117
|
+
} else {
|
|
1118
|
+
effective = transaction.sequence;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
return effective;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1106
1124
|
/**
|
|
1107
1125
|
* Given an array of transactions, ensures that all sequence numbers and dates
|
|
1108
1126
|
* are properly ordered.
|
|
@@ -1169,7 +1187,7 @@ module.exports = (() => {
|
|
|
1169
1187
|
assert.argumentIsArray(transactions, 'transactions');
|
|
1170
1188
|
assert.argumentIsOptional(strict, 'strict', Boolean);
|
|
1171
1189
|
|
|
1172
|
-
return transactions.findIndex((t, i, a) => t
|
|
1190
|
+
return transactions.findIndex((t, i, a) => TransactionValidator.getSortSequence(t) !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && is.boolean(strict) && strict && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
1173
1191
|
}
|
|
1174
1192
|
|
|
1175
1193
|
/**
|