@barchart/portfolio-api-common 1.2.28 → 1.2.32
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.
- package/lib/api/failures/PortfolioFailureType.js +27 -1
- package/lib/data/InstrumentType.js +2 -2
- package/lib/data/PositionSummaryFrame.js +3 -3
- package/lib/data/TransactionValidator.js +7 -7
- package/lib/formatters/TransactionFormatter.js +52 -13
- package/lib/processing/PositionContainer.js +3 -3
- package/lib/processing/PositionGroup.js +1 -1
- package/lib/processing/definitions/PositionLevelDefinition.js +3 -3
- package/lib/processing/definitions/PositionTreeDefinition.js +1 -1
- package/lib/serialization/TransactionSchema.js +10 -10
- package/package.json +1 -1
- package/test/SpecRunner.js +20 -20
|
@@ -165,6 +165,29 @@ module.exports = (() => {
|
|
|
165
165
|
return transactionDeleteFailedDirectionSwitchOnRewrite;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Unable to edit, the transaction doesn't exist.
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
172
|
+
* @static
|
|
173
|
+
* @returns {FailureType}
|
|
174
|
+
*/
|
|
175
|
+
static get TRANSACTION_EDIT_FAILED_NO_TRANSACTION() {
|
|
176
|
+
return transactionEditFailedNoTransaction;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The transaction (of this type) cannot be edited by a user, instead,
|
|
181
|
+
* it is managed by the system (e.g. dividends).
|
|
182
|
+
*
|
|
183
|
+
* @public
|
|
184
|
+
* @static
|
|
185
|
+
* @returns {FailureType}
|
|
186
|
+
*/
|
|
187
|
+
static get TRANSACTION_EDIT_FAILED_TYPE_RESERVED() {
|
|
188
|
+
return transactionEditFailedTypeReserved;
|
|
189
|
+
}
|
|
190
|
+
|
|
168
191
|
toString() {
|
|
169
192
|
return '[PortfolioFailureType]';
|
|
170
193
|
}
|
|
@@ -182,11 +205,14 @@ module.exports = (() => {
|
|
|
182
205
|
const transactionCreateFailedTypeInvalidForDirection = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION', 'Unable to process transaction, a {L|positionDirection.description} position would be created (i.e. you would have {L|positionDirection.sign} shares/units). {u|instrumentType.description} positions cannot have {L|positionDirection.description} positions.');
|
|
183
206
|
const transactionCreateFailedInvalidDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DIRECTION_SWITCH', 'Unable to process transaction, the transaction would switch the position from {L|currentDirection.description} to {L|proposedDirection.description} (i.e. {L|currentDirection.sign} to {L|proposedDirection.sign} shares/units). This is not allowed. Please close the current position (i.e. zero it out) and then enter a second transaction.');
|
|
184
207
|
const transactionCreateFailedInvalidInitialType = new FailureType('TRANSACTION_CREATE_FAILED_INITIAL_TYPE', 'Unable to process operation because the first transaction would to be a {U|transactionType.description}, which is not allowed -- since {U|transactionType.description} transactions cannot open a position.');
|
|
185
|
-
const transactionCreateFailedTypeReserved = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_RESERVED', 'Unable to
|
|
208
|
+
const transactionCreateFailedTypeReserved = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_RESERVED', 'Unable to create {U|type.description} transaction, this type of transaction is managed by the system.');
|
|
186
209
|
|
|
187
210
|
const transactionDeleteFailedOutOfSequence = new FailureType('TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE', 'Deleting any transaction, except for the most recent, will cause transaction history to be re-written. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
188
211
|
const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
|
|
189
212
|
const transactionDeleteFailedDirectionSwitchOnRewrite = new FailureType('TRANSACTION_DELETE_FAILED_DIRECTION_SWITCH_ON_REWRITE', 'Deleting this transaction would cause your history to be re-written and the position to switch from long to short (i.e. positive to negative) or vice versa.');
|
|
190
213
|
|
|
214
|
+
const transactionEditFailedNoTransaction = new FailureType('TRANSACTION_EDIT_FAILED_NO_TRANSACTION', 'Unable to edit transaction. The referenced transaction does not exist.');
|
|
215
|
+
const transactionEditFailedTypeReserved = new FailureType('TRANSACTION_EDIT_FAILED_TYPE_RESERVED', 'Unable to edit {U|type.description} transaction, this type of transaction is managed by the system.');
|
|
216
|
+
|
|
191
217
|
return PortfolioFailureType;
|
|
192
218
|
})();
|
|
@@ -47,7 +47,7 @@ module.exports = (() => {
|
|
|
47
47
|
* A human-readable description.
|
|
48
48
|
*
|
|
49
49
|
* @public
|
|
50
|
-
* @
|
|
50
|
+
* @returns {String}
|
|
51
51
|
*/
|
|
52
52
|
get alternateDescription() {
|
|
53
53
|
return this._alternateDescription;
|
|
@@ -182,7 +182,7 @@ module.exports = (() => {
|
|
|
182
182
|
* @public
|
|
183
183
|
* @static
|
|
184
184
|
* @param code
|
|
185
|
-
* @
|
|
185
|
+
* @returns {InstrumentType}
|
|
186
186
|
*/
|
|
187
187
|
static fromSymbolType(code) {
|
|
188
188
|
assert.argumentIsRequired(code, 'code', Number);
|
|
@@ -42,7 +42,7 @@ module.exports = (() => {
|
|
|
42
42
|
* exist for a position.
|
|
43
43
|
*
|
|
44
44
|
* @public
|
|
45
|
-
* @
|
|
45
|
+
* @returns {Boolean}
|
|
46
46
|
*/
|
|
47
47
|
get unique() {
|
|
48
48
|
return this._unique;
|
|
@@ -53,8 +53,8 @@ module.exports = (() => {
|
|
|
53
53
|
* start and end dates.
|
|
54
54
|
*
|
|
55
55
|
* @public
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
56
|
+
* @returns {PositionSummaryRange} range
|
|
57
|
+
* @returns {String}
|
|
58
58
|
*/
|
|
59
59
|
describeRange(range) {
|
|
60
60
|
return this._descriptionCalculator(range.start, range.end);
|
|
@@ -25,7 +25,7 @@ module.exports = (() => {
|
|
|
25
25
|
* @public
|
|
26
26
|
* @static
|
|
27
27
|
* @param {Array.<Object>} transactions
|
|
28
|
-
* @
|
|
28
|
+
* @returns {Boolean}
|
|
29
29
|
*/
|
|
30
30
|
static validateOrder(transactions) {
|
|
31
31
|
return TransactionValidator.getInvalidIndex(transactions) < 0;
|
|
@@ -38,7 +38,7 @@ module.exports = (() => {
|
|
|
38
38
|
* @public
|
|
39
39
|
* @static
|
|
40
40
|
* @param {Array.<Object>} transactions
|
|
41
|
-
* @
|
|
41
|
+
* @returns {Number}
|
|
42
42
|
*/
|
|
43
43
|
static getInvalidIndex(transactions) {
|
|
44
44
|
assert.argumentIsArray(transactions, 'transactions');
|
|
@@ -54,7 +54,7 @@ module.exports = (() => {
|
|
|
54
54
|
* @param {InstrumentType} instrumentType
|
|
55
55
|
* @param {Boolean=} userInitiated
|
|
56
56
|
* @pararm {PositionDirection=} currentDirection
|
|
57
|
-
* @
|
|
57
|
+
* @returns {Array.<TransactionType>}
|
|
58
58
|
*/
|
|
59
59
|
static getTransactionTypesFor(instrumentType, userInitiated, currentDirection) {
|
|
60
60
|
assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
|
|
@@ -79,7 +79,7 @@ module.exports = (() => {
|
|
|
79
79
|
*
|
|
80
80
|
* @public
|
|
81
81
|
* @static
|
|
82
|
-
* @
|
|
82
|
+
* @returns {Array.<TransactionType>}
|
|
83
83
|
*/
|
|
84
84
|
static getUserInitiatedTransactionTypes() {
|
|
85
85
|
return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
|
|
@@ -103,7 +103,7 @@ module.exports = (() => {
|
|
|
103
103
|
* @param {InstrumentType} instrumentType
|
|
104
104
|
* @param {TransactionType} transactionType
|
|
105
105
|
* @param {Boolean=} userInitiated
|
|
106
|
-
* @
|
|
106
|
+
* @returns {Boolean}
|
|
107
107
|
*/
|
|
108
108
|
static validateTransactionType(instrumentType, transactionType, userInitiated) {
|
|
109
109
|
assert.argumentIsRequired(transactionType, 'transactionType', TransactionType, 'TransactionType');
|
|
@@ -131,7 +131,7 @@ module.exports = (() => {
|
|
|
131
131
|
* @public
|
|
132
132
|
* @param {InstrumentType} instrumentType
|
|
133
133
|
* @param {PositionDirection} direction
|
|
134
|
-
* @
|
|
134
|
+
* @returns {Boolean}
|
|
135
135
|
*/
|
|
136
136
|
static validateDirection(instrumentType, direction) {
|
|
137
137
|
assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
|
|
@@ -149,7 +149,7 @@ module.exports = (() => {
|
|
|
149
149
|
* @param {InstrumentType} instrumentType
|
|
150
150
|
* @param {PositionDirection|null|undefined} currentDirection
|
|
151
151
|
* @param {PositionDirection} proposedDirection
|
|
152
|
-
* @
|
|
152
|
+
* @returns {Boolean}
|
|
153
153
|
*/
|
|
154
154
|
static validateDirectionSwitch(instrumentType, currentDirection, proposedDirection) {
|
|
155
155
|
return currentDirection === null || instrumentType.canSwitchDirection || (currentDirection.closed || proposedDirection.closed || currentDirection.positive === proposedDirection.positive);
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
|
|
3
|
+
comparators = require('@barchart/common-js/collections/sorting/comparators'),
|
|
4
|
+
Day = require('@barchart/common-js/lang/Day'),
|
|
2
5
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
3
6
|
is = require('@barchart/common-js/lang/is'),
|
|
4
7
|
formatter = require('@barchart/common-js/lang/formatter');
|
|
5
8
|
|
|
6
|
-
const
|
|
9
|
+
const InstrumentType = require('./../data/InstrumentType'),
|
|
10
|
+
TransactionType = require('./../data/TransactionType');
|
|
7
11
|
|
|
8
12
|
module.exports = (() => {
|
|
9
13
|
'use strict';
|
|
@@ -19,33 +23,30 @@ module.exports = (() => {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
|
-
* Maps transaction objects into new objects whose properties are human-readable or
|
|
23
|
-
*
|
|
24
|
-
* each transaction.
|
|
26
|
+
* Maps transaction objects into new objects whose properties are human-readable (or
|
|
27
|
+
* mutates the original objects, adding a "formatted" property to each transaction).
|
|
25
28
|
*
|
|
26
29
|
* @public
|
|
27
30
|
* @static
|
|
28
|
-
* @param {Array
|
|
29
|
-
* @param {Array
|
|
30
|
-
* @param {Boolean=}
|
|
31
|
+
* @param {Array.<Object>} transactions
|
|
32
|
+
* @param {Array.<Object>} positions
|
|
33
|
+
* @param {Boolean=} mutate
|
|
31
34
|
* @returns {Array}
|
|
32
35
|
*/
|
|
33
|
-
static format(transactions, positions,
|
|
36
|
+
static format(transactions, positions, mutate) {
|
|
34
37
|
assert.argumentIsArray(transactions, 'transactions');
|
|
35
38
|
assert.argumentIsArray(positions, 'positions');
|
|
36
|
-
assert.argumentIsOptional(
|
|
39
|
+
assert.argumentIsOptional(mutate, 'mutate', Boolean);
|
|
37
40
|
|
|
38
41
|
const instruments = positions.reduce((map, p) => {
|
|
39
42
|
const instrument = Object.assign({ }, p.instrument || { });
|
|
40
43
|
|
|
41
|
-
delete instrument.id;
|
|
42
|
-
|
|
43
44
|
map[p.position] = instrument;
|
|
44
45
|
|
|
45
46
|
return map;
|
|
46
47
|
}, { });
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
const a = transactions.reduce((list, transaction) => {
|
|
49
50
|
const position = transaction.position;
|
|
50
51
|
|
|
51
52
|
if (instruments.hasOwnProperty(position)) {
|
|
@@ -69,7 +70,7 @@ module.exports = (() => {
|
|
|
69
70
|
|
|
70
71
|
let transactionToInsert;
|
|
71
72
|
|
|
72
|
-
if (
|
|
73
|
+
if (mutate) {
|
|
73
74
|
transaction.formatted = formatted;
|
|
74
75
|
|
|
75
76
|
transactionToInsert = transaction;
|
|
@@ -82,6 +83,26 @@ module.exports = (() => {
|
|
|
82
83
|
|
|
83
84
|
return list;
|
|
84
85
|
}, [ ]);
|
|
86
|
+
|
|
87
|
+
a.sort(comparator);
|
|
88
|
+
|
|
89
|
+
a.forEach((t) => {
|
|
90
|
+
delete t.instrument.id;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return a;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Sorts an array of formatted transaction objects.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
* @static
|
|
101
|
+
* @param {Array.<Object>} transactions
|
|
102
|
+
* @returns {Array}
|
|
103
|
+
*/
|
|
104
|
+
sort(transactions) {
|
|
105
|
+
return transactions.sort(comparator);
|
|
85
106
|
}
|
|
86
107
|
|
|
87
108
|
toString() {
|
|
@@ -237,5 +258,23 @@ module.exports = (() => {
|
|
|
237
258
|
return formatted;
|
|
238
259
|
});
|
|
239
260
|
|
|
261
|
+
function getInstrumentTypePriority(type) {
|
|
262
|
+
if (type === InstrumentType.CASH) {
|
|
263
|
+
return 1;
|
|
264
|
+
} else {
|
|
265
|
+
return 0;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const comparator = ComparatorBuilder.startWith((a, b) => {
|
|
270
|
+
return Day.compareDays(b.date, a.date);
|
|
271
|
+
}).thenBy((a, b) => {
|
|
272
|
+
return comparators.compareNumbers(getInstrumentTypePriority(a.instrument.type), getInstrumentTypePriority(b.instrument.type));
|
|
273
|
+
}).thenBy((a, b) => {
|
|
274
|
+
return comparators.compareStrings(a.instrument.id, b.instrument.id);
|
|
275
|
+
}).thenBy((a, b) => {
|
|
276
|
+
return comparators.compareStrings(a.sequence, b.sequence);
|
|
277
|
+
}).toComparator();
|
|
278
|
+
|
|
240
279
|
return TransactionFormatter;
|
|
241
280
|
})();
|
|
@@ -555,7 +555,7 @@ module.exports = (() => {
|
|
|
555
555
|
* Returns all portfolios in the container.
|
|
556
556
|
*
|
|
557
557
|
* @public
|
|
558
|
-
* @
|
|
558
|
+
* @returns {Array.<Object>}
|
|
559
559
|
*/
|
|
560
560
|
getPortfolios() {
|
|
561
561
|
return Object.keys(this._portfolios).map(id => this._portfolios[id]);
|
|
@@ -566,7 +566,7 @@ module.exports = (() => {
|
|
|
566
566
|
*
|
|
567
567
|
* @public
|
|
568
568
|
* @param {String} portfolio
|
|
569
|
-
* @
|
|
569
|
+
* @returns {Array.<Object>}
|
|
570
570
|
*/
|
|
571
571
|
getPositions(portfolio) {
|
|
572
572
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
@@ -583,7 +583,7 @@ module.exports = (() => {
|
|
|
583
583
|
* @public
|
|
584
584
|
* @param {String} portfolio
|
|
585
585
|
* @param {String} position
|
|
586
|
-
* @
|
|
586
|
+
* @returns {Object|null}
|
|
587
587
|
*/
|
|
588
588
|
getPosition(portfolio, position) {
|
|
589
589
|
assert.argumentIsRequired(position, 'position', String);
|
|
@@ -67,7 +67,7 @@ module.exports = (() => {
|
|
|
67
67
|
* A general description of the type of items grouped together.
|
|
68
68
|
*
|
|
69
69
|
* @public
|
|
70
|
-
* @
|
|
70
|
+
* @returns {PositionLevelType}
|
|
71
71
|
*/
|
|
72
72
|
get type() {
|
|
73
73
|
return this._type;
|
|
@@ -160,7 +160,7 @@ module.exports = (() => {
|
|
|
160
160
|
* @public
|
|
161
161
|
* @static
|
|
162
162
|
* @param {Object} portfolio
|
|
163
|
-
* @
|
|
163
|
+
* @returns {PositionLevelDefinition~RequiredGroup}
|
|
164
164
|
*/
|
|
165
165
|
static buildRequiredGroupForPortfolio(portfolio) {
|
|
166
166
|
return {
|
|
@@ -203,7 +203,7 @@ module.exports = (() => {
|
|
|
203
203
|
* @static
|
|
204
204
|
* @param {InstrumentType} type
|
|
205
205
|
* @param {Currency} currency
|
|
206
|
-
* @
|
|
206
|
+
* @returns {PositionLevelDefinition~RequiredGroup}
|
|
207
207
|
*/
|
|
208
208
|
static buildRequiredGroupForAssetClass(type, currency) {
|
|
209
209
|
return {
|
|
@@ -248,7 +248,7 @@ module.exports = (() => {
|
|
|
248
248
|
const buy = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY.code)
|
|
249
249
|
.withField('portfolio', DataType.STRING)
|
|
250
250
|
.withField('position', DataType.STRING)
|
|
251
|
-
.withField('sequence', DataType.NUMBER)
|
|
251
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
252
252
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
253
253
|
.withField('instrument.name', DataType.STRING, true)
|
|
254
254
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
@@ -267,7 +267,7 @@ module.exports = (() => {
|
|
|
267
267
|
const sell = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL.code)
|
|
268
268
|
.withField('portfolio', DataType.STRING)
|
|
269
269
|
.withField('position', DataType.STRING)
|
|
270
|
-
.withField('sequence', DataType.NUMBER)
|
|
270
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
271
271
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
272
272
|
.withField('date', DataType.DAY)
|
|
273
273
|
.withField('price', DataType.DECIMAL)
|
|
@@ -280,7 +280,7 @@ module.exports = (() => {
|
|
|
280
280
|
const buyShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY_SHORT.code)
|
|
281
281
|
.withField('portfolio', DataType.STRING)
|
|
282
282
|
.withField('position', DataType.STRING)
|
|
283
|
-
.withField('sequence', DataType.NUMBER)
|
|
283
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
284
284
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
285
285
|
.withField('date', DataType.DAY)
|
|
286
286
|
.withField('price', DataType.DECIMAL)
|
|
@@ -294,7 +294,7 @@ module.exports = (() => {
|
|
|
294
294
|
const sellShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL_SHORT.code)
|
|
295
295
|
.withField('portfolio', DataType.STRING)
|
|
296
296
|
.withField('position', DataType.STRING)
|
|
297
|
-
.withField('sequence', DataType.NUMBER)
|
|
297
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
298
298
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
299
299
|
.withField('instrument.name', DataType.STRING, true)
|
|
300
300
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
@@ -389,7 +389,7 @@ module.exports = (() => {
|
|
|
389
389
|
const fee = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE.code)
|
|
390
390
|
.withField('portfolio', DataType.STRING)
|
|
391
391
|
.withField('position', DataType.STRING)
|
|
392
|
-
.withField('sequence', DataType.NUMBER)
|
|
392
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
393
393
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
394
394
|
.withField('date', DataType.DAY)
|
|
395
395
|
.withField('fee', DataType.DECIMAL)
|
|
@@ -400,7 +400,7 @@ module.exports = (() => {
|
|
|
400
400
|
const feeUnits = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE_UNITS.code)
|
|
401
401
|
.withField('portfolio', DataType.STRING)
|
|
402
402
|
.withField('position', DataType.STRING)
|
|
403
|
-
.withField('sequence', DataType.NUMBER)
|
|
403
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
404
404
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
405
405
|
.withField('date', DataType.DAY)
|
|
406
406
|
.withField('fee', DataType.DECIMAL)
|
|
@@ -412,7 +412,7 @@ module.exports = (() => {
|
|
|
412
412
|
const deposit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEPOSIT.code)
|
|
413
413
|
.withField('portfolio', DataType.STRING)
|
|
414
414
|
.withField('position', DataType.STRING)
|
|
415
|
-
.withField('sequence', DataType.NUMBER)
|
|
415
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
416
416
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
417
417
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
418
418
|
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -426,7 +426,7 @@ module.exports = (() => {
|
|
|
426
426
|
const withdrawal = new TransactionSchema(SchemaBuilder.withName(TransactionType.WITHDRAWAL.code)
|
|
427
427
|
.withField('portfolio', DataType.STRING)
|
|
428
428
|
.withField('position', DataType.STRING)
|
|
429
|
-
.withField('sequence', DataType.NUMBER)
|
|
429
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
430
430
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
431
431
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
432
432
|
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -462,7 +462,7 @@ module.exports = (() => {
|
|
|
462
462
|
const valuation = new TransactionSchema(SchemaBuilder.withName(TransactionType.VALUATION.code)
|
|
463
463
|
.withField('portfolio', DataType.STRING)
|
|
464
464
|
.withField('position', DataType.STRING)
|
|
465
|
-
.withField('sequence', DataType.NUMBER)
|
|
465
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
466
466
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
467
467
|
.withField('date', DataType.DAY)
|
|
468
468
|
.withField('value', DataType.DECIMAL)
|
|
@@ -473,7 +473,7 @@ module.exports = (() => {
|
|
|
473
473
|
const income = new TransactionSchema(SchemaBuilder.withName(TransactionType.INCOME.code)
|
|
474
474
|
.withField('portfolio', DataType.STRING)
|
|
475
475
|
.withField('position', DataType.STRING)
|
|
476
|
-
.withField('sequence', DataType.NUMBER)
|
|
476
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
477
477
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
478
478
|
.withField('date', DataType.DAY)
|
|
479
479
|
.withField('income', DataType.DECIMAL)
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -48,7 +48,7 @@ module.exports = (() => {
|
|
|
48
48
|
* A human-readable description.
|
|
49
49
|
*
|
|
50
50
|
* @public
|
|
51
|
-
* @
|
|
51
|
+
* @returns {String}
|
|
52
52
|
*/
|
|
53
53
|
get alternateDescription() {
|
|
54
54
|
return this._alternateDescription;
|
|
@@ -183,7 +183,7 @@ module.exports = (() => {
|
|
|
183
183
|
* @public
|
|
184
184
|
* @static
|
|
185
185
|
* @param code
|
|
186
|
-
* @
|
|
186
|
+
* @returns {InstrumentType}
|
|
187
187
|
*/
|
|
188
188
|
static fromSymbolType(code) {
|
|
189
189
|
assert.argumentIsRequired(code, 'code', Number);
|
|
@@ -392,7 +392,7 @@ module.exports = (() => {
|
|
|
392
392
|
* exist for a position.
|
|
393
393
|
*
|
|
394
394
|
* @public
|
|
395
|
-
* @
|
|
395
|
+
* @returns {Boolean}
|
|
396
396
|
*/
|
|
397
397
|
get unique() {
|
|
398
398
|
return this._unique;
|
|
@@ -403,8 +403,8 @@ module.exports = (() => {
|
|
|
403
403
|
* start and end dates.
|
|
404
404
|
*
|
|
405
405
|
* @public
|
|
406
|
-
* @
|
|
407
|
-
* @
|
|
406
|
+
* @returns {PositionSummaryRange} range
|
|
407
|
+
* @returns {String}
|
|
408
408
|
*/
|
|
409
409
|
describeRange(range) {
|
|
410
410
|
return this._descriptionCalculator(range.start, range.end);
|
|
@@ -1053,7 +1053,7 @@ module.exports = (() => {
|
|
|
1053
1053
|
* @public
|
|
1054
1054
|
* @static
|
|
1055
1055
|
* @param {Array.<Object>} transactions
|
|
1056
|
-
* @
|
|
1056
|
+
* @returns {Boolean}
|
|
1057
1057
|
*/
|
|
1058
1058
|
static validateOrder(transactions) {
|
|
1059
1059
|
return TransactionValidator.getInvalidIndex(transactions) < 0;
|
|
@@ -1066,7 +1066,7 @@ module.exports = (() => {
|
|
|
1066
1066
|
* @public
|
|
1067
1067
|
* @static
|
|
1068
1068
|
* @param {Array.<Object>} transactions
|
|
1069
|
-
* @
|
|
1069
|
+
* @returns {Number}
|
|
1070
1070
|
*/
|
|
1071
1071
|
static getInvalidIndex(transactions) {
|
|
1072
1072
|
assert.argumentIsArray(transactions, 'transactions');
|
|
@@ -1082,7 +1082,7 @@ module.exports = (() => {
|
|
|
1082
1082
|
* @param {InstrumentType} instrumentType
|
|
1083
1083
|
* @param {Boolean=} userInitiated
|
|
1084
1084
|
* @pararm {PositionDirection=} currentDirection
|
|
1085
|
-
* @
|
|
1085
|
+
* @returns {Array.<TransactionType>}
|
|
1086
1086
|
*/
|
|
1087
1087
|
static getTransactionTypesFor(instrumentType, userInitiated, currentDirection) {
|
|
1088
1088
|
assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
|
|
@@ -1107,7 +1107,7 @@ module.exports = (() => {
|
|
|
1107
1107
|
*
|
|
1108
1108
|
* @public
|
|
1109
1109
|
* @static
|
|
1110
|
-
* @
|
|
1110
|
+
* @returns {Array.<TransactionType>}
|
|
1111
1111
|
*/
|
|
1112
1112
|
static getUserInitiatedTransactionTypes() {
|
|
1113
1113
|
return array.unique(Object.keys(validTransactionTypes).reduce((types, key) => {
|
|
@@ -1131,7 +1131,7 @@ module.exports = (() => {
|
|
|
1131
1131
|
* @param {InstrumentType} instrumentType
|
|
1132
1132
|
* @param {TransactionType} transactionType
|
|
1133
1133
|
* @param {Boolean=} userInitiated
|
|
1134
|
-
* @
|
|
1134
|
+
* @returns {Boolean}
|
|
1135
1135
|
*/
|
|
1136
1136
|
static validateTransactionType(instrumentType, transactionType, userInitiated) {
|
|
1137
1137
|
assert.argumentIsRequired(transactionType, 'transactionType', TransactionType, 'TransactionType');
|
|
@@ -1159,7 +1159,7 @@ module.exports = (() => {
|
|
|
1159
1159
|
* @public
|
|
1160
1160
|
* @param {InstrumentType} instrumentType
|
|
1161
1161
|
* @param {PositionDirection} direction
|
|
1162
|
-
* @
|
|
1162
|
+
* @returns {Boolean}
|
|
1163
1163
|
*/
|
|
1164
1164
|
static validateDirection(instrumentType, direction) {
|
|
1165
1165
|
assert.argumentIsRequired(instrumentType, 'instrumentType', InstrumentType, 'InstrumentType');
|
|
@@ -1177,7 +1177,7 @@ module.exports = (() => {
|
|
|
1177
1177
|
* @param {InstrumentType} instrumentType
|
|
1178
1178
|
* @param {PositionDirection|null|undefined} currentDirection
|
|
1179
1179
|
* @param {PositionDirection} proposedDirection
|
|
1180
|
-
* @
|
|
1180
|
+
* @returns {Boolean}
|
|
1181
1181
|
*/
|
|
1182
1182
|
static validateDirectionSwitch(instrumentType, currentDirection, proposedDirection) {
|
|
1183
1183
|
return currentDirection === null || instrumentType.canSwitchDirection || (currentDirection.closed || proposedDirection.closed || currentDirection.positive === proposedDirection.positive);
|
|
@@ -1817,7 +1817,7 @@ module.exports = (() => {
|
|
|
1817
1817
|
* Returns all portfolios in the container.
|
|
1818
1818
|
*
|
|
1819
1819
|
* @public
|
|
1820
|
-
* @
|
|
1820
|
+
* @returns {Array.<Object>}
|
|
1821
1821
|
*/
|
|
1822
1822
|
getPortfolios() {
|
|
1823
1823
|
return Object.keys(this._portfolios).map(id => this._portfolios[id]);
|
|
@@ -1828,7 +1828,7 @@ module.exports = (() => {
|
|
|
1828
1828
|
*
|
|
1829
1829
|
* @public
|
|
1830
1830
|
* @param {String} portfolio
|
|
1831
|
-
* @
|
|
1831
|
+
* @returns {Array.<Object>}
|
|
1832
1832
|
*/
|
|
1833
1833
|
getPositions(portfolio) {
|
|
1834
1834
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
@@ -1845,7 +1845,7 @@ module.exports = (() => {
|
|
|
1845
1845
|
* @public
|
|
1846
1846
|
* @param {String} portfolio
|
|
1847
1847
|
* @param {String} position
|
|
1848
|
-
* @
|
|
1848
|
+
* @returns {Object|null}
|
|
1849
1849
|
*/
|
|
1850
1850
|
getPosition(portfolio, position) {
|
|
1851
1851
|
assert.argumentIsRequired(position, 'position', String);
|
|
@@ -2646,7 +2646,7 @@ module.exports = (() => {
|
|
|
2646
2646
|
*
|
|
2647
2647
|
* @public
|
|
2648
2648
|
* @param {Function} handler
|
|
2649
|
-
* @
|
|
2649
|
+
* @returns {Disposable}
|
|
2650
2650
|
*/
|
|
2651
2651
|
registerGroupExcludedChangeHandler(handler) {
|
|
2652
2652
|
return this._groupExcludedChangeEvent.register(handler);
|
|
@@ -3629,7 +3629,7 @@ module.exports = (() => {
|
|
|
3629
3629
|
* A general description of the type of items grouped together.
|
|
3630
3630
|
*
|
|
3631
3631
|
* @public
|
|
3632
|
-
* @
|
|
3632
|
+
* @returns {PositionLevelType}
|
|
3633
3633
|
*/
|
|
3634
3634
|
get type() {
|
|
3635
3635
|
return this._type;
|
|
@@ -3722,7 +3722,7 @@ module.exports = (() => {
|
|
|
3722
3722
|
* @public
|
|
3723
3723
|
* @static
|
|
3724
3724
|
* @param {Object} portfolio
|
|
3725
|
-
* @
|
|
3725
|
+
* @returns {PositionLevelDefinition~RequiredGroup}
|
|
3726
3726
|
*/
|
|
3727
3727
|
static buildRequiredGroupForPortfolio(portfolio) {
|
|
3728
3728
|
return {
|
|
@@ -3765,7 +3765,7 @@ module.exports = (() => {
|
|
|
3765
3765
|
* @static
|
|
3766
3766
|
* @param {InstrumentType} type
|
|
3767
3767
|
* @param {Currency} currency
|
|
3768
|
-
* @
|
|
3768
|
+
* @returns {PositionLevelDefinition~RequiredGroup}
|
|
3769
3769
|
*/
|
|
3770
3770
|
static buildRequiredGroupForAssetClass(type, currency) {
|
|
3771
3771
|
return {
|
|
@@ -3926,7 +3926,7 @@ module.exports = (() => {
|
|
|
3926
3926
|
* group (from the current tree) is excluded.
|
|
3927
3927
|
*
|
|
3928
3928
|
* @public
|
|
3929
|
-
* @
|
|
3929
|
+
* @returns {Array.<String>}
|
|
3930
3930
|
*/
|
|
3931
3931
|
get exclusionDependencies() {
|
|
3932
3932
|
return this._exclusionDependencies;
|