@barchart/portfolio-api-common 1.0.192 → 1.0.196
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.
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const FailureType = require('@barchart/common-js/api/failures/FailureType');
|
|
2
|
+
|
|
3
|
+
module.exports = (() => {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A static container for portfolio-specific {@link FailureType} items.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class PortfolioFailureType {
|
|
12
|
+
constructor() {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The transaction would occur before an existing transaction.
|
|
17
|
+
*
|
|
18
|
+
* @static
|
|
19
|
+
* @returns {FailureType}
|
|
20
|
+
*/
|
|
21
|
+
static get TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE() {
|
|
22
|
+
return transactionCreateFailedOutOfSequence;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString() {
|
|
26
|
+
return '[PortfolioFailureType]';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to create transaction, the transaction date is out-of-sequence (i.e. it would occur before an existing transaction). Please confirm your intent to re-write transaction history.');
|
|
31
|
+
|
|
32
|
+
return PortfolioFailureType;
|
|
33
|
+
})();
|
|
@@ -5,6 +5,7 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
5
5
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
6
6
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
7
7
|
DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
|
|
8
|
+
Event = require('@barchart/common-js/messaging/Event'),
|
|
8
9
|
is = require('@barchart/common-js/lang/is'),
|
|
9
10
|
Rate = require('@barchart/common-js/lang/Rate'),
|
|
10
11
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
@@ -48,6 +49,9 @@ module.exports = (() => {
|
|
|
48
49
|
|
|
49
50
|
this._groupBindings = { };
|
|
50
51
|
|
|
52
|
+
this._positionSymbolAddedEvent = new Event(this);
|
|
53
|
+
this._positionSymbolRemovedEvent = new Event(this);
|
|
54
|
+
|
|
51
55
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
52
56
|
map[portfolio.portfolio] = portfolio;
|
|
53
57
|
|
|
@@ -241,7 +245,9 @@ module.exports = (() => {
|
|
|
241
245
|
}
|
|
242
246
|
|
|
243
247
|
this.startTransaction(() => {
|
|
244
|
-
this.
|
|
248
|
+
const existingBarchartSymbols = this.getPositionSymbols(false);
|
|
249
|
+
|
|
250
|
+
removePositionItem.call(this, this._items.find((item) => item.position.position === position.position));
|
|
245
251
|
|
|
246
252
|
summaries.forEach((summary) => {
|
|
247
253
|
addSummaryCurrent(this._summariesCurrent, summary, this._currentSummaryFrame, this._currentSummaryRange);
|
|
@@ -281,6 +287,12 @@ module.exports = (() => {
|
|
|
281
287
|
};
|
|
282
288
|
|
|
283
289
|
this._definitions.forEach(definition => createGroupOrInjectItem(this._trees[definition.name], definition, definition.definitions));
|
|
290
|
+
|
|
291
|
+
const addedBarchartSymbol = extractSymbolForBarchart(item.position);
|
|
292
|
+
|
|
293
|
+
if (addedBarchartSymbol !== null && !existingBarchartSymbols.some(existingBarchartSymbol => existingBarchartSymbol === addedBarchartSymbol)) {
|
|
294
|
+
this._positionSymbolAddedEvent.fire(addedBarchartSymbol);
|
|
295
|
+
}
|
|
284
296
|
});
|
|
285
297
|
}
|
|
286
298
|
|
|
@@ -529,6 +541,31 @@ module.exports = (() => {
|
|
|
529
541
|
namesToUse.forEach((name) => this._trees[name].walk(group => group.setSuspended(false), false, false));
|
|
530
542
|
}
|
|
531
543
|
|
|
544
|
+
/**
|
|
545
|
+
* Registers an observer for symbol addition (this occurs when a new position is added
|
|
546
|
+
* for a symbol that does not already exist in the container). This event only fires
|
|
547
|
+
* after the constructor completes (and initial positions have been added).
|
|
548
|
+
*
|
|
549
|
+
* @public
|
|
550
|
+
* @param {Function} handler
|
|
551
|
+
* @returns {Disposable}
|
|
552
|
+
*/
|
|
553
|
+
registerPositionSymbolAddedHandler(handler) {
|
|
554
|
+
return this._positionSymbolAddedEvent.register(handler);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Registers an observer for symbol removal (this occurs when the last position for a
|
|
559
|
+
* symbol is removed from the container).
|
|
560
|
+
*
|
|
561
|
+
* @public
|
|
562
|
+
* @param {Function} handler
|
|
563
|
+
* @returns {Disposable}
|
|
564
|
+
*/
|
|
565
|
+
registerPositionSymbolRemovedHandler(handler) {
|
|
566
|
+
return this._positionSymbolRemovedEvent.register(handler);
|
|
567
|
+
}
|
|
568
|
+
|
|
532
569
|
toString() {
|
|
533
570
|
return '[PositionContainer]';
|
|
534
571
|
}
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -721,6 +721,7 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
721
721
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
722
722
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
723
723
|
DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
|
|
724
|
+
Event = require('@barchart/common-js/messaging/Event'),
|
|
724
725
|
is = require('@barchart/common-js/lang/is'),
|
|
725
726
|
Rate = require('@barchart/common-js/lang/Rate'),
|
|
726
727
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
@@ -764,6 +765,9 @@ module.exports = (() => {
|
|
|
764
765
|
|
|
765
766
|
this._groupBindings = { };
|
|
766
767
|
|
|
768
|
+
this._positionSymbolAddedEvent = new Event(this);
|
|
769
|
+
this._positionSymbolRemovedEvent = new Event(this);
|
|
770
|
+
|
|
767
771
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
768
772
|
map[portfolio.portfolio] = portfolio;
|
|
769
773
|
|
|
@@ -957,7 +961,9 @@ module.exports = (() => {
|
|
|
957
961
|
}
|
|
958
962
|
|
|
959
963
|
this.startTransaction(() => {
|
|
960
|
-
this.
|
|
964
|
+
const existingBarchartSymbols = this.getPositionSymbols(false);
|
|
965
|
+
|
|
966
|
+
removePositionItem.call(this, this._items.find((item) => item.position.position === position.position));
|
|
961
967
|
|
|
962
968
|
summaries.forEach((summary) => {
|
|
963
969
|
addSummaryCurrent(this._summariesCurrent, summary, this._currentSummaryFrame, this._currentSummaryRange);
|
|
@@ -997,6 +1003,12 @@ module.exports = (() => {
|
|
|
997
1003
|
};
|
|
998
1004
|
|
|
999
1005
|
this._definitions.forEach(definition => createGroupOrInjectItem(this._trees[definition.name], definition, definition.definitions));
|
|
1006
|
+
|
|
1007
|
+
const addedBarchartSymbol = extractSymbolForBarchart(item.position);
|
|
1008
|
+
|
|
1009
|
+
if (addedBarchartSymbol !== null && !existingBarchartSymbols.some(existingBarchartSymbol => existingBarchartSymbol === addedBarchartSymbol)) {
|
|
1010
|
+
this._positionSymbolAddedEvent.fire(addedBarchartSymbol);
|
|
1011
|
+
}
|
|
1000
1012
|
});
|
|
1001
1013
|
}
|
|
1002
1014
|
|
|
@@ -1245,6 +1257,31 @@ module.exports = (() => {
|
|
|
1245
1257
|
namesToUse.forEach((name) => this._trees[name].walk(group => group.setSuspended(false), false, false));
|
|
1246
1258
|
}
|
|
1247
1259
|
|
|
1260
|
+
/**
|
|
1261
|
+
* Registers an observer for symbol addition (this occurs when a new position is added
|
|
1262
|
+
* for a symbol that does not already exist in the container). This event only fires
|
|
1263
|
+
* after the constructor completes (and initial positions have been added).
|
|
1264
|
+
*
|
|
1265
|
+
* @public
|
|
1266
|
+
* @param {Function} handler
|
|
1267
|
+
* @returns {Disposable}
|
|
1268
|
+
*/
|
|
1269
|
+
registerPositionSymbolAddedHandler(handler) {
|
|
1270
|
+
return this._positionSymbolAddedEvent.register(handler);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* Registers an observer for symbol removal (this occurs when the last position for a
|
|
1275
|
+
* symbol is removed from the container).
|
|
1276
|
+
*
|
|
1277
|
+
* @public
|
|
1278
|
+
* @param {Function} handler
|
|
1279
|
+
* @returns {Disposable}
|
|
1280
|
+
*/
|
|
1281
|
+
registerPositionSymbolRemovedHandler(handler) {
|
|
1282
|
+
return this._positionSymbolRemovedEvent.register(handler);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1248
1285
|
toString() {
|
|
1249
1286
|
return '[PositionContainer]';
|
|
1250
1287
|
}
|
|
@@ -1532,7 +1569,7 @@ module.exports = (() => {
|
|
|
1532
1569
|
return PositionContainer;
|
|
1533
1570
|
})();
|
|
1534
1571
|
|
|
1535
|
-
},{"./../data/PositionSummaryFrame":2,"./PositionGroup":5,"./PositionItem":6,"./definitions/PositionLevelDefinition":7,"./definitions/PositionLevelType":8,"./definitions/PositionTreeDefinition":9,"@barchart/common-js/collections/Tree":11,"@barchart/common-js/collections/sorting/ComparatorBuilder":12,"@barchart/common-js/collections/sorting/comparators":13,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24}],5:[function(require,module,exports){
|
|
1572
|
+
},{"./../data/PositionSummaryFrame":2,"./PositionGroup":5,"./PositionItem":6,"./definitions/PositionLevelDefinition":7,"./definitions/PositionLevelType":8,"./definitions/PositionTreeDefinition":9,"@barchart/common-js/collections/Tree":11,"@barchart/common-js/collections/sorting/ComparatorBuilder":12,"@barchart/common-js/collections/sorting/comparators":13,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],5:[function(require,module,exports){
|
|
1536
1573
|
const array = require('@barchart/common-js/lang/array'),
|
|
1537
1574
|
assert = require('@barchart/common-js/lang/assert'),
|
|
1538
1575
|
Currency = require('@barchart/common-js/lang/Currency'),
|