@barchart/portfolio-api-common 1.2.26 → 1.2.30
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 +39 -0
- package/lib/data/InstrumentType.js +2 -2
- package/lib/data/PositionSummaryFrame.js +3 -3
- package/lib/data/TransactionValidator.js +7 -7
- package/lib/processing/PositionContainer.js +3 -3
- package/lib/processing/PositionGroup.js +1 -1
- package/lib/processing/PositionItem.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 -0
- package/package.json +1 -1
- package/test/SpecRunner.js +21 -21
|
@@ -119,6 +119,18 @@ module.exports = (() => {
|
|
|
119
119
|
return transactionCreateFailedInvalidInitialType;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* The transaction (of this type) cannot be created by a user, instead,
|
|
124
|
+
* it is created and managed by the system (e.g. dividends).
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
* @static
|
|
128
|
+
* @returns {FailureType}
|
|
129
|
+
*/
|
|
130
|
+
static get TRANSACTION_CREATE_FAILED_TYPE_RESERVED() {
|
|
131
|
+
return transactionCreateFailedTypeReserved;
|
|
132
|
+
}
|
|
133
|
+
|
|
122
134
|
/**
|
|
123
135
|
* Deleting any transaction except for the most recent requires
|
|
124
136
|
* re-writing transaction history.
|
|
@@ -153,6 +165,29 @@ module.exports = (() => {
|
|
|
153
165
|
return transactionDeleteFailedDirectionSwitchOnRewrite;
|
|
154
166
|
}
|
|
155
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
|
+
|
|
156
191
|
toString() {
|
|
157
192
|
return '[PortfolioFailureType]';
|
|
158
193
|
}
|
|
@@ -170,10 +205,14 @@ module.exports = (() => {
|
|
|
170
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.');
|
|
171
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.');
|
|
172
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.');
|
|
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.');
|
|
173
209
|
|
|
174
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).');
|
|
175
211
|
const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.');
|
|
176
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.');
|
|
177
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
|
+
|
|
178
217
|
return PortfolioFailureType;
|
|
179
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);
|
|
@@ -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);
|
|
@@ -189,7 +189,7 @@ module.exports = (() => {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
if (this._currentPricePrevious !== quote.lastPrice) {
|
|
192
|
-
if (
|
|
192
|
+
if (quote.previousPrice) {
|
|
193
193
|
this._data.previousPrice = quote.previousPrice;
|
|
194
194
|
}
|
|
195
195
|
|
|
@@ -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,6 +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, true)
|
|
251
252
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
252
253
|
.withField('instrument.name', DataType.STRING, true)
|
|
253
254
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
@@ -266,6 +267,7 @@ module.exports = (() => {
|
|
|
266
267
|
const sell = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL.code)
|
|
267
268
|
.withField('portfolio', DataType.STRING)
|
|
268
269
|
.withField('position', DataType.STRING)
|
|
270
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
269
271
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
270
272
|
.withField('date', DataType.DAY)
|
|
271
273
|
.withField('price', DataType.DECIMAL)
|
|
@@ -278,6 +280,7 @@ module.exports = (() => {
|
|
|
278
280
|
const buyShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY_SHORT.code)
|
|
279
281
|
.withField('portfolio', DataType.STRING)
|
|
280
282
|
.withField('position', DataType.STRING)
|
|
283
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
281
284
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
282
285
|
.withField('date', DataType.DAY)
|
|
283
286
|
.withField('price', DataType.DECIMAL)
|
|
@@ -291,6 +294,7 @@ module.exports = (() => {
|
|
|
291
294
|
const sellShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL_SHORT.code)
|
|
292
295
|
.withField('portfolio', DataType.STRING)
|
|
293
296
|
.withField('position', DataType.STRING)
|
|
297
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
294
298
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
295
299
|
.withField('instrument.name', DataType.STRING, true)
|
|
296
300
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
@@ -385,6 +389,7 @@ module.exports = (() => {
|
|
|
385
389
|
const fee = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE.code)
|
|
386
390
|
.withField('portfolio', DataType.STRING)
|
|
387
391
|
.withField('position', DataType.STRING)
|
|
392
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
388
393
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
389
394
|
.withField('date', DataType.DAY)
|
|
390
395
|
.withField('fee', DataType.DECIMAL)
|
|
@@ -395,6 +400,7 @@ module.exports = (() => {
|
|
|
395
400
|
const feeUnits = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE_UNITS.code)
|
|
396
401
|
.withField('portfolio', DataType.STRING)
|
|
397
402
|
.withField('position', DataType.STRING)
|
|
403
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
398
404
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
399
405
|
.withField('date', DataType.DAY)
|
|
400
406
|
.withField('fee', DataType.DECIMAL)
|
|
@@ -406,6 +412,7 @@ module.exports = (() => {
|
|
|
406
412
|
const deposit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEPOSIT.code)
|
|
407
413
|
.withField('portfolio', DataType.STRING)
|
|
408
414
|
.withField('position', DataType.STRING)
|
|
415
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
409
416
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
410
417
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
411
418
|
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -419,6 +426,7 @@ module.exports = (() => {
|
|
|
419
426
|
const withdrawal = new TransactionSchema(SchemaBuilder.withName(TransactionType.WITHDRAWAL.code)
|
|
420
427
|
.withField('portfolio', DataType.STRING)
|
|
421
428
|
.withField('position', DataType.STRING)
|
|
429
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
422
430
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
423
431
|
.withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
|
|
424
432
|
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -454,6 +462,7 @@ module.exports = (() => {
|
|
|
454
462
|
const valuation = new TransactionSchema(SchemaBuilder.withName(TransactionType.VALUATION.code)
|
|
455
463
|
.withField('portfolio', DataType.STRING)
|
|
456
464
|
.withField('position', DataType.STRING)
|
|
465
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
457
466
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
458
467
|
.withField('date', DataType.DAY)
|
|
459
468
|
.withField('value', DataType.DECIMAL)
|
|
@@ -464,6 +473,7 @@ module.exports = (() => {
|
|
|
464
473
|
const income = new TransactionSchema(SchemaBuilder.withName(TransactionType.INCOME.code)
|
|
465
474
|
.withField('portfolio', DataType.STRING)
|
|
466
475
|
.withField('position', DataType.STRING)
|
|
476
|
+
.withField('sequence', DataType.NUMBER, true)
|
|
467
477
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
468
478
|
.withField('date', DataType.DAY)
|
|
469
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);
|
|
@@ -3254,7 +3254,7 @@ module.exports = (() => {
|
|
|
3254
3254
|
}
|
|
3255
3255
|
|
|
3256
3256
|
if (this._currentPricePrevious !== quote.lastPrice) {
|
|
3257
|
-
if (
|
|
3257
|
+
if (quote.previousPrice) {
|
|
3258
3258
|
this._data.previousPrice = quote.previousPrice;
|
|
3259
3259
|
}
|
|
3260
3260
|
|
|
@@ -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;
|