@barchart/portfolio-api-common 1.2.79 → 1.2.83

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.
@@ -276,7 +276,7 @@ module.exports = (() => {
276
276
 
277
277
  const existingBarchartSymbols = this.getPositionSymbols(false);
278
278
 
279
- removePositionItem.call(this, this._items.find((item) => item.position.position === position.position));
279
+ removePositionItem.call(this, this._items.find(item => item.position.position === position.position));
280
280
 
281
281
  summaries.forEach((summary) => {
282
282
  addSummaryCurrent(this._summariesCurrent, summary, this._currentSummaryFrame, this._currentSummaryRange);
@@ -336,7 +336,7 @@ module.exports = (() => {
336
336
  assert.argumentIsRequired(position, 'position', Object);
337
337
  assert.argumentIsRequired(position.position, 'position.position', String);
338
338
 
339
- removePositionItem.call(this, this._items.find((item) => item.position.position === position.position));
339
+ removePositionItem.call(this, this._items.find(item => item.position.position === position.position));
340
340
 
341
341
  recalculatePercentages.call(this);
342
342
  }
@@ -371,21 +371,41 @@ module.exports = (() => {
371
371
  return array.unique(symbols);
372
372
  }
373
373
 
374
+ /**
375
+ * Causes a position to be flagged as locked (for editing).
376
+ *
377
+ * @public
378
+ * @param {Object} position
379
+ */
374
380
  setPositionLock(position) {
375
381
  if (position) {
376
382
  assert.argumentIsRequired(position, 'position', Object);
377
383
  assert.argumentIsRequired(position.position, 'position.position', String);
378
384
 
379
- const item = this._items.find((i) => i.position.position === position.position);
385
+ const item = this._items.find(i => i.position.position === position.position);
380
386
 
381
387
  if (item) {
382
- const locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
383
-
384
- item.setPositionLock(locked);
388
+ item.setPositionLock(position);
385
389
  }
386
390
  }
387
391
  }
388
392
 
393
+ /**
394
+ * Returns a position's lock status.
395
+ *
396
+ * @public
397
+ * @param {Object} position
398
+ * @return {Boolean}
399
+ */
400
+ getPositionLock(portfolio, position) {
401
+ assert.argumentIsRequired(position, 'position', Object);
402
+ assert.argumentIsRequired(position.position, 'position.position', String);
403
+
404
+ const item = this._items.find(i => i.position.position === position.position);
405
+
406
+ return is.object(item) && item.locked;
407
+ }
408
+
389
409
  /**
390
410
  * Performs a batch update of both position quotes and forex quotes,
391
411
  * triggering updates to position(s) and data aggregation(s).
@@ -70,7 +70,7 @@ 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
+ this._data.locked = getIsLocked(position);
74
74
 
75
75
  calculateStaticData(this);
76
76
  calculatePriceData(this, null);
@@ -242,18 +242,20 @@ module.exports = (() => {
242
242
  }
243
243
 
244
244
  /**
245
- * Sets position lock status.
245
+ * Sets a position's lock status.
246
246
  *
247
247
  * @public
248
- * @param {Boolean} value
248
+ * @param {Object} position
249
249
  */
250
- setPositionLock(value) {
251
- assert.argumentIsRequired(value, 'value', Boolean);
250
+ setPositionLock(position) {
251
+ assert.argumentIsRequired(position, 'position');
252
252
 
253
253
  if (this.getIsDisposed()) {
254
254
  return;
255
255
  }
256
256
 
257
+ const value = getIsLocked(position);
258
+
257
259
  if (this._data.locked !== value) {
258
260
  this._lockChangedEvent.fire(this._data.locked = value);
259
261
  }
@@ -525,5 +527,11 @@ module.exports = (() => {
525
527
  return summary;
526
528
  }
527
529
 
530
+ function getIsLocked(position) {
531
+ assert.argumentIsRequired(position, 'position');
532
+
533
+ return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
534
+ }
535
+
528
536
  return PositionItem;
529
537
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.79",
3
+ "version": "1.2.83",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1655,7 +1655,7 @@ module.exports = (() => {
1655
1655
 
1656
1656
  const existingBarchartSymbols = this.getPositionSymbols(false);
1657
1657
 
1658
- removePositionItem.call(this, this._items.find((item) => item.position.position === position.position));
1658
+ removePositionItem.call(this, this._items.find(item => item.position.position === position.position));
1659
1659
 
1660
1660
  summaries.forEach((summary) => {
1661
1661
  addSummaryCurrent(this._summariesCurrent, summary, this._currentSummaryFrame, this._currentSummaryRange);
@@ -1715,7 +1715,7 @@ module.exports = (() => {
1715
1715
  assert.argumentIsRequired(position, 'position', Object);
1716
1716
  assert.argumentIsRequired(position.position, 'position.position', String);
1717
1717
 
1718
- removePositionItem.call(this, this._items.find((item) => item.position.position === position.position));
1718
+ removePositionItem.call(this, this._items.find(item => item.position.position === position.position));
1719
1719
 
1720
1720
  recalculatePercentages.call(this);
1721
1721
  }
@@ -1750,21 +1750,41 @@ module.exports = (() => {
1750
1750
  return array.unique(symbols);
1751
1751
  }
1752
1752
 
1753
+ /**
1754
+ * Causes a position to be flagged as locked (for editing).
1755
+ *
1756
+ * @public
1757
+ * @param {Object} position
1758
+ */
1753
1759
  setPositionLock(position) {
1754
1760
  if (position) {
1755
1761
  assert.argumentIsRequired(position, 'position', Object);
1756
1762
  assert.argumentIsRequired(position.position, 'position.position', String);
1757
1763
 
1758
- const item = this._items.find((i) => i.position.position === position.position);
1764
+ const item = this._items.find(i => i.position.position === position.position);
1759
1765
 
1760
1766
  if (item) {
1761
- const locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
1762
-
1763
- item.setPositionLock(locked);
1767
+ item.setPositionLock(position);
1764
1768
  }
1765
1769
  }
1766
1770
  }
1767
1771
 
1772
+ /**
1773
+ * Returns a position's lock status.
1774
+ *
1775
+ * @public
1776
+ * @param {Object} position
1777
+ * @return {Boolean}
1778
+ */
1779
+ getPositionLock(portfolio, position) {
1780
+ assert.argumentIsRequired(position, 'position', Object);
1781
+ assert.argumentIsRequired(position.position, 'position.position', String);
1782
+
1783
+ const item = this._items.find(i => i.position.position === position.position);
1784
+
1785
+ return is.object(item) && item.locked;
1786
+ }
1787
+
1768
1788
  /**
1769
1789
  * Performs a batch update of both position quotes and forex quotes,
1770
1790
  * triggering updates to position(s) and data aggregation(s).
@@ -3278,7 +3298,7 @@ module.exports = (() => {
3278
3298
 
3279
3299
  this._data.newsExists = false;
3280
3300
  this._data.fundamental = { };
3281
- this._data.locked = is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
3301
+ this._data.locked = getIsLocked(position);
3282
3302
 
3283
3303
  calculateStaticData(this);
3284
3304
  calculatePriceData(this, null);
@@ -3450,18 +3470,20 @@ module.exports = (() => {
3450
3470
  }
3451
3471
 
3452
3472
  /**
3453
- * Sets position lock status.
3473
+ * Sets a position's lock status.
3454
3474
  *
3455
3475
  * @public
3456
- * @param {Boolean} value
3476
+ * @param {Object} position
3457
3477
  */
3458
- setPositionLock(value) {
3459
- assert.argumentIsRequired(value, 'value', Boolean);
3478
+ setPositionLock(position) {
3479
+ assert.argumentIsRequired(position, 'position');
3460
3480
 
3461
3481
  if (this.getIsDisposed()) {
3462
3482
  return;
3463
3483
  }
3464
3484
 
3485
+ const value = getIsLocked(position);
3486
+
3465
3487
  if (this._data.locked !== value) {
3466
3488
  this._lockChangedEvent.fire(this._data.locked = value);
3467
3489
  }
@@ -3733,6 +3755,12 @@ module.exports = (() => {
3733
3755
  return summary;
3734
3756
  }
3735
3757
 
3758
+ function getIsLocked(position) {
3759
+ assert.argumentIsRequired(position, 'position');
3760
+
3761
+ return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
3762
+ }
3763
+
3736
3764
  return PositionItem;
3737
3765
  })();
3738
3766