@barchart/portfolio-api-common 1.2.74 → 1.2.78

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.
@@ -6,6 +6,7 @@ const array = require('@barchart/common-js/lang/array'),
6
6
  Decimal = require('@barchart/common-js/lang/Decimal'),
7
7
  DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
8
8
  Event = require('@barchart/common-js/messaging/Event'),
9
+ is = require('@barchart/common-js/lang/array'),
9
10
  Rate = require('@barchart/common-js/lang/Rate'),
10
11
  Tree = require('@barchart/common-js/collections/Tree');
11
12
 
@@ -370,6 +371,21 @@ module.exports = (() => {
370
371
  return array.unique(symbols);
371
372
  }
372
373
 
374
+ setPositionLock(position) {
375
+ if (position) {
376
+ assert.argumentIsRequired(position, 'position', Object);
377
+ assert.argumentIsRequired(position.position, 'position.position', String);
378
+
379
+ const item = this._items.find((i) => i.position.position === position.position);
380
+
381
+ if (item) {
382
+ const locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
383
+
384
+ item.setPositionLock(locked);
385
+ }
386
+ }
387
+ }
388
+
373
389
  /**
374
390
  * Performs a batch update of both position quotes and forex quotes,
375
391
  * triggering updates to position(s) and data aggregation(s).
@@ -717,6 +733,8 @@ module.exports = (() => {
717
733
  });
718
734
  }
719
735
  }
736
+
737
+ recalculatePercentages.call(this);
720
738
  }));
721
739
  }
722
740
 
@@ -72,6 +72,7 @@ module.exports = (() => {
72
72
  this._dataFormat.description = this._description;
73
73
  this._dataFormat.hide = false;
74
74
  this._dataFormat.invalid = false;
75
+ this._dataFormat.locked = false;
75
76
  this._dataFormat.newsExists = false;
76
77
  this._dataFormat.quantity = null;
77
78
  this._dataFormat.basisPrice = null;
@@ -541,12 +542,17 @@ module.exports = (() => {
541
542
  });
542
543
 
543
544
  let newsBinding = Disposable.getEmpty();
545
+ let lockedBinding = Disposable.getEmpty();
544
546
 
545
547
  if (this._single) {
546
548
  newsBinding = item.registerNewsExistsChangeHandler((exists) => {
547
549
  this._dataActual.newsExists = exists;
548
550
  this._dataFormat.newsExists = exists;
549
551
  });
552
+
553
+ lockedBinding = item.registerLockChangeHandler((locked) => {
554
+ this._dataFormat.locked = locked;
555
+ });
550
556
  }
551
557
 
552
558
  this._disposeStack.push(item.registerPortfolioChangeHandler((portfolio) => {
@@ -558,14 +564,16 @@ module.exports = (() => {
558
564
  this._dataFormat.description = this._description;
559
565
  }));
560
566
 
567
+ this._disposeStack.push(fundamentalBinding);
561
568
  this._disposeStack.push(quoteBinding);
569
+ this._disposeStack.push(lockedBinding);
562
570
  this._disposeStack.push(newsBinding);
563
- this._disposeStack.push(fundamentalBinding);
564
571
 
565
572
  this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
573
+ fundamentalBinding.dispose();
566
574
  quoteBinding.dispose();
567
575
  newsBinding.dispose();
568
- fundamentalBinding.dispose();
576
+ lockedBinding.dispose();
569
577
 
570
578
  array.remove(this._items, i => i === item);
571
579
  array.remove(this._excludedItems, i => i === item);
@@ -692,6 +700,7 @@ module.exports = (() => {
692
700
  format.basisPrice = formatCurrency(actual.basisPrice, currency);
693
701
 
694
702
  format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
703
+ format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
695
704
  }
696
705
 
697
706
  const groupItems = group._items;
@@ -70,13 +70,15 @@ module.exports = (() => {
70
70
 
71
71
  this._data.newsExists = false;
72
72
  this._data.fundamental = { };
73
+ this._data.locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
73
74
 
74
75
  calculateStaticData(this);
75
76
  calculatePriceData(this, null);
76
77
 
77
78
  this._quoteChangedEvent = new Event(this);
78
79
  this._newsExistsChangedEvent = new Event(this);
79
- this._fundamentalDataChangeEvent = new Event(this);
80
+ this._fundamentalDataChangedEvent = new Event(this);
81
+ this._lockChangedEvent = new Event(this);
80
82
  this._portfolioChangedEvent = new Event(this);
81
83
  this._positionItemDisposeEvent = new Event(this);
82
84
  }
@@ -204,6 +206,25 @@ module.exports = (() => {
204
206
  }
205
207
  }
206
208
 
209
+ /**
210
+ * Sets a flag which indicates if news article(s) exist for the encapsulated position's
211
+ * symbol.
212
+ *
213
+ * @public
214
+ * @param {Boolean} value
215
+ */
216
+ setNewsArticleExists(value) {
217
+ assert.argumentIsRequired(value, 'value', Boolean);
218
+
219
+ if (this.getIsDisposed()) {
220
+ return;
221
+ }
222
+
223
+ if (this._data.newsExists !== value) {
224
+ this._newsExistsChangedEvent.fire(this._data.newsExists = value);
225
+ }
226
+ }
227
+
207
228
  /**
208
229
  * Sets fundamental data for the position.
209
230
  *
@@ -217,25 +238,24 @@ module.exports = (() => {
217
238
  return;
218
239
  }
219
240
 
220
- this._fundamentalDataChangeEvent.fire(this._data.fundamental = data);
241
+ this._fundamentalDataChangedEvent.fire(this._data.fundamental = data);
221
242
  }
222
243
 
223
244
  /**
224
- * Sets a flag which indicates if news article(s) exist for the encapsulated position's
225
- * symbol.
245
+ * Sets position lock status.
226
246
  *
227
247
  * @public
228
248
  * @param {Boolean} value
229
249
  */
230
- setNewsArticleExists(value) {
250
+ setPositionLock(value) {
231
251
  assert.argumentIsRequired(value, 'value', Boolean);
232
252
 
233
253
  if (this.getIsDisposed()) {
234
254
  return;
235
255
  }
236
256
 
237
- if (this._data.newsExists !== value) {
238
- this._newsExistsChangedEvent.fire(this._data.newsExists = value);
257
+ if (this._data.locked !== value) {
258
+ this._lockChangedEvent.fire(this._data.locked = value);
239
259
  }
240
260
  }
241
261
 
@@ -251,6 +271,17 @@ module.exports = (() => {
251
271
  return this._quoteChangedEvent.register(handler);
252
272
  }
253
273
 
274
+ /**
275
+ * Registers an observer changes to the status of news existence.
276
+ *
277
+ * @public
278
+ * @param {Function} handler
279
+ * @returns {Disposable}
280
+ */
281
+ registerNewsExistsChangeHandler(handler) {
282
+ return this._newsExistsChangedEvent.register(handler);
283
+ }
284
+
254
285
  /**
255
286
  * Registers an observer for fundamental data changes.
256
287
  *
@@ -259,18 +290,18 @@ module.exports = (() => {
259
290
  * @returns {Disposable}
260
291
  */
261
292
  registerFundamentalDataChangeHandler(handler) {
262
- return this._fundamentalDataChangeEvent.register(handler);
293
+ return this._fundamentalDataChangedEvent.register(handler);
263
294
  }
264
295
 
265
296
  /**
266
- * Registers an observer changes to the status of news existence.
297
+ * Registers an observer for position lock changes.
267
298
  *
268
299
  * @public
269
300
  * @param {Function} handler
270
301
  * @returns {Disposable}
271
302
  */
272
- registerNewsExistsChangeHandler(handler) {
273
- return this._newsExistsChangedEvent.register(handler);
303
+ registerLockChangeHandler(handler) {
304
+ return this._lockChangedEvent.register(handler);
274
305
  }
275
306
 
276
307
  /**
@@ -300,7 +331,8 @@ module.exports = (() => {
300
331
 
301
332
  this._quoteChangedEvent.clear();
302
333
  this._newsExistsChangedEvent.clear();
303
- this._fundamentalDataChangeEvent.clear();
334
+ this._fundamentalDataChangedEvent.clear();
335
+ this._lockChangedEvent.clear();
304
336
  this._portfolioChangedEvent.clear();
305
337
  this._positionItemDisposeEvent.clear();
306
338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.74",
3
+ "version": "1.2.78",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1385,6 +1385,7 @@ const array = require('@barchart/common-js/lang/array'),
1385
1385
  Decimal = require('@barchart/common-js/lang/Decimal'),
1386
1386
  DisposableStack = require('@barchart/common-js/collections/specialized/DisposableStack'),
1387
1387
  Event = require('@barchart/common-js/messaging/Event'),
1388
+ is = require('@barchart/common-js/lang/array'),
1388
1389
  Rate = require('@barchart/common-js/lang/Rate'),
1389
1390
  Tree = require('@barchart/common-js/collections/Tree');
1390
1391
 
@@ -1749,6 +1750,21 @@ module.exports = (() => {
1749
1750
  return array.unique(symbols);
1750
1751
  }
1751
1752
 
1753
+ setPositionLock(position) {
1754
+ if (position) {
1755
+ assert.argumentIsRequired(position, 'position', Object);
1756
+ assert.argumentIsRequired(position.position, 'position.position', String);
1757
+
1758
+ const item = this._items.find((i) => i.position.position === position.position);
1759
+
1760
+ if (item) {
1761
+ const locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
1762
+
1763
+ item.setPositionLock(locked);
1764
+ }
1765
+ }
1766
+ }
1767
+
1752
1768
  /**
1753
1769
  * Performs a batch update of both position quotes and forex quotes,
1754
1770
  * triggering updates to position(s) and data aggregation(s).
@@ -2096,6 +2112,8 @@ module.exports = (() => {
2096
2112
  });
2097
2113
  }
2098
2114
  }
2115
+
2116
+ recalculatePercentages.call(this);
2099
2117
  }));
2100
2118
  }
2101
2119
 
@@ -2393,6 +2411,7 @@ module.exports = (() => {
2393
2411
  this._dataFormat.description = this._description;
2394
2412
  this._dataFormat.hide = false;
2395
2413
  this._dataFormat.invalid = false;
2414
+ this._dataFormat.locked = false;
2396
2415
  this._dataFormat.newsExists = false;
2397
2416
  this._dataFormat.quantity = null;
2398
2417
  this._dataFormat.basisPrice = null;
@@ -2862,12 +2881,17 @@ module.exports = (() => {
2862
2881
  });
2863
2882
 
2864
2883
  let newsBinding = Disposable.getEmpty();
2884
+ let lockedBinding = Disposable.getEmpty();
2865
2885
 
2866
2886
  if (this._single) {
2867
2887
  newsBinding = item.registerNewsExistsChangeHandler((exists) => {
2868
2888
  this._dataActual.newsExists = exists;
2869
2889
  this._dataFormat.newsExists = exists;
2870
2890
  });
2891
+
2892
+ lockedBinding = item.registerLockChangeHandler((locked) => {
2893
+ this._dataFormat.locked = locked;
2894
+ });
2871
2895
  }
2872
2896
 
2873
2897
  this._disposeStack.push(item.registerPortfolioChangeHandler((portfolio) => {
@@ -2879,14 +2903,16 @@ module.exports = (() => {
2879
2903
  this._dataFormat.description = this._description;
2880
2904
  }));
2881
2905
 
2906
+ this._disposeStack.push(fundamentalBinding);
2882
2907
  this._disposeStack.push(quoteBinding);
2908
+ this._disposeStack.push(lockedBinding);
2883
2909
  this._disposeStack.push(newsBinding);
2884
- this._disposeStack.push(fundamentalBinding);
2885
2910
 
2886
2911
  this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
2912
+ fundamentalBinding.dispose();
2887
2913
  quoteBinding.dispose();
2888
2914
  newsBinding.dispose();
2889
- fundamentalBinding.dispose();
2915
+ lockedBinding.dispose();
2890
2916
 
2891
2917
  array.remove(this._items, i => i === item);
2892
2918
  array.remove(this._excludedItems, i => i === item);
@@ -3013,6 +3039,7 @@ module.exports = (() => {
3013
3039
  format.basisPrice = formatCurrency(actual.basisPrice, currency);
3014
3040
 
3015
3041
  format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
3042
+ format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
3016
3043
  }
3017
3044
 
3018
3045
  const groupItems = group._items;
@@ -3251,13 +3278,15 @@ module.exports = (() => {
3251
3278
 
3252
3279
  this._data.newsExists = false;
3253
3280
  this._data.fundamental = { };
3281
+ this._data.locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
3254
3282
 
3255
3283
  calculateStaticData(this);
3256
3284
  calculatePriceData(this, null);
3257
3285
 
3258
3286
  this._quoteChangedEvent = new Event(this);
3259
3287
  this._newsExistsChangedEvent = new Event(this);
3260
- this._fundamentalDataChangeEvent = new Event(this);
3288
+ this._fundamentalDataChangedEvent = new Event(this);
3289
+ this._lockChangedEvent = new Event(this);
3261
3290
  this._portfolioChangedEvent = new Event(this);
3262
3291
  this._positionItemDisposeEvent = new Event(this);
3263
3292
  }
@@ -3385,6 +3414,25 @@ module.exports = (() => {
3385
3414
  }
3386
3415
  }
3387
3416
 
3417
+ /**
3418
+ * Sets a flag which indicates if news article(s) exist for the encapsulated position's
3419
+ * symbol.
3420
+ *
3421
+ * @public
3422
+ * @param {Boolean} value
3423
+ */
3424
+ setNewsArticleExists(value) {
3425
+ assert.argumentIsRequired(value, 'value', Boolean);
3426
+
3427
+ if (this.getIsDisposed()) {
3428
+ return;
3429
+ }
3430
+
3431
+ if (this._data.newsExists !== value) {
3432
+ this._newsExistsChangedEvent.fire(this._data.newsExists = value);
3433
+ }
3434
+ }
3435
+
3388
3436
  /**
3389
3437
  * Sets fundamental data for the position.
3390
3438
  *
@@ -3398,25 +3446,24 @@ module.exports = (() => {
3398
3446
  return;
3399
3447
  }
3400
3448
 
3401
- this._fundamentalDataChangeEvent.fire(this._data.fundamental = data);
3449
+ this._fundamentalDataChangedEvent.fire(this._data.fundamental = data);
3402
3450
  }
3403
3451
 
3404
3452
  /**
3405
- * Sets a flag which indicates if news article(s) exist for the encapsulated position's
3406
- * symbol.
3453
+ * Sets position lock status.
3407
3454
  *
3408
3455
  * @public
3409
3456
  * @param {Boolean} value
3410
3457
  */
3411
- setNewsArticleExists(value) {
3458
+ setPositionLock(value) {
3412
3459
  assert.argumentIsRequired(value, 'value', Boolean);
3413
3460
 
3414
3461
  if (this.getIsDisposed()) {
3415
3462
  return;
3416
3463
  }
3417
3464
 
3418
- if (this._data.newsExists !== value) {
3419
- this._newsExistsChangedEvent.fire(this._data.newsExists = value);
3465
+ if (this._data.locked !== value) {
3466
+ this._lockChangedEvent.fire(this._data.locked = value);
3420
3467
  }
3421
3468
  }
3422
3469
 
@@ -3432,6 +3479,17 @@ module.exports = (() => {
3432
3479
  return this._quoteChangedEvent.register(handler);
3433
3480
  }
3434
3481
 
3482
+ /**
3483
+ * Registers an observer changes to the status of news existence.
3484
+ *
3485
+ * @public
3486
+ * @param {Function} handler
3487
+ * @returns {Disposable}
3488
+ */
3489
+ registerNewsExistsChangeHandler(handler) {
3490
+ return this._newsExistsChangedEvent.register(handler);
3491
+ }
3492
+
3435
3493
  /**
3436
3494
  * Registers an observer for fundamental data changes.
3437
3495
  *
@@ -3440,18 +3498,18 @@ module.exports = (() => {
3440
3498
  * @returns {Disposable}
3441
3499
  */
3442
3500
  registerFundamentalDataChangeHandler(handler) {
3443
- return this._fundamentalDataChangeEvent.register(handler);
3501
+ return this._fundamentalDataChangedEvent.register(handler);
3444
3502
  }
3445
3503
 
3446
3504
  /**
3447
- * Registers an observer changes to the status of news existence.
3505
+ * Registers an observer for position lock changes.
3448
3506
  *
3449
3507
  * @public
3450
3508
  * @param {Function} handler
3451
3509
  * @returns {Disposable}
3452
3510
  */
3453
- registerNewsExistsChangeHandler(handler) {
3454
- return this._newsExistsChangedEvent.register(handler);
3511
+ registerLockChangeHandler(handler) {
3512
+ return this._lockChangedEvent.register(handler);
3455
3513
  }
3456
3514
 
3457
3515
  /**
@@ -3481,7 +3539,8 @@ module.exports = (() => {
3481
3539
 
3482
3540
  this._quoteChangedEvent.clear();
3483
3541
  this._newsExistsChangedEvent.clear();
3484
- this._fundamentalDataChangeEvent.clear();
3542
+ this._fundamentalDataChangedEvent.clear();
3543
+ this._lockChangedEvent.clear();
3485
3544
  this._portfolioChangedEvent.clear();
3486
3545
  this._positionItemDisposeEvent.clear();
3487
3546
  }
@@ -5920,12 +5979,11 @@ module.exports = function () {
5920
5979
  }
5921
5980
 
5922
5981
  /**
5923
- * Converts a string (which matches the output of {@link Day#format} into
5924
- * a {@link Day} instance.
5982
+ * Clones a {@link Day} instance.
5925
5983
  *
5926
5984
  * @public
5927
5985
  * @static
5928
- * @param {String} value
5986
+ * @param {Day} value
5929
5987
  * @returns {Day}
5930
5988
  */
5931
5989
 
@@ -5966,6 +6024,24 @@ module.exports = function () {
5966
6024
  return this._day;
5967
6025
  }
5968
6026
  }], [{
6027
+ key: 'clone',
6028
+ value: function clone(value) {
6029
+ assert.argumentIsRequired(value, 'value', Day, 'Day');
6030
+
6031
+ return new Day(value.year, value.month, value.day);
6032
+ }
6033
+
6034
+ /**
6035
+ * Converts a string (which matches the output of {@link Day#format} into
6036
+ * a {@link Day} instance.
6037
+ *
6038
+ * @public
6039
+ * @static
6040
+ * @param {String} value
6041
+ * @returns {Day}
6042
+ */
6043
+
6044
+ }, {
5969
6045
  key: 'parse',
5970
6046
  value: function parse(value) {
5971
6047
  assert.argumentIsRequired(value, 'value', String);
@@ -6476,10 +6552,11 @@ module.exports = function () {
6476
6552
  }
6477
6553
 
6478
6554
  /**
6479
- * Parses the value emitted by {@link Decimal#toJSON}.
6555
+ * Clones a {@link Decimal} instance.
6480
6556
  *
6481
6557
  * @public
6482
- * @param {String} value
6558
+ * @static
6559
+ * @param {Decimal} value
6483
6560
  * @returns {Decimal}
6484
6561
  */
6485
6562
 
@@ -6489,6 +6566,22 @@ module.exports = function () {
6489
6566
  return '[Decimal]';
6490
6567
  }
6491
6568
  }], [{
6569
+ key: 'clone',
6570
+ value: function clone(value) {
6571
+ assert.argumentIsRequired(value, 'value', Decimal, 'Decimal');
6572
+
6573
+ return new Decimal(value._big);
6574
+ }
6575
+
6576
+ /**
6577
+ * Parses the value emitted by {@link Decimal#toJSON}.
6578
+ *
6579
+ * @public
6580
+ * @param {String} value
6581
+ * @returns {Decimal}
6582
+ */
6583
+
6584
+ }, {
6492
6585
  key: 'parse',
6493
6586
  value: function parse(value) {
6494
6587
  return new Decimal(value);
@@ -7510,10 +7603,11 @@ module.exports = function () {
7510
7603
  }
7511
7604
 
7512
7605
  /**
7513
- * Parses the value emitted by {@link Timestamp#toJSON}.
7606
+ * Clones a {@link Timestamp} instance.
7514
7607
  *
7515
7608
  * @public
7516
- * @param {Number} value
7609
+ * @static
7610
+ * @param {Timestamp} value
7517
7611
  * @returns {Timestamp}
7518
7612
  */
7519
7613
 
@@ -7549,6 +7643,22 @@ module.exports = function () {
7549
7643
  return this._moment;
7550
7644
  }
7551
7645
  }], [{
7646
+ key: 'clone',
7647
+ value: function clone(value) {
7648
+ assert.argumentIsRequired(value, 'value', Timestamp, 'Timestamp');
7649
+
7650
+ return new Timestamp(value._timestamp, value._timezone);
7651
+ }
7652
+
7653
+ /**
7654
+ * Parses the value emitted by {@link Timestamp#toJSON}.
7655
+ *
7656
+ * @public
7657
+ * @param {Number} value
7658
+ * @returns {Timestamp}
7659
+ */
7660
+
7661
+ }, {
7552
7662
  key: 'parse',
7553
7663
  value: function parse(value) {
7554
7664
  return new Timestamp(value);