@barchart/portfolio-api-common 1.3.23 → 1.4.2

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.
@@ -253,7 +253,7 @@ module.exports = (() => {
253
253
  }
254
254
 
255
255
  toString() {
256
- return '[InstrumentType]';
256
+ return `[InstrumentType (code=${this.code})]`;
257
257
  }
258
258
  }
259
259
 
@@ -393,6 +393,10 @@ module.exports = (() => {
393
393
  return even;
394
394
  }
395
395
  }
396
+
397
+ toString() {
398
+ return `[PositionDirection (code=${this.code})]`;
399
+ }
396
400
  }
397
401
 
398
402
  const long = new PositionDirection('LONG', 'Long', 'positive');
@@ -580,7 +584,7 @@ module.exports = (() => {
580
584
  }
581
585
 
582
586
  toString() {
583
- return '[PositionSummaryFrame]';
587
+ return `[PositionSummaryFrame (code=${this.code})]`;
584
588
  }
585
589
  }
586
590
 
@@ -1247,7 +1251,7 @@ module.exports = (() => {
1247
1251
  }
1248
1252
 
1249
1253
  toString() {
1250
- return '[TransactionType]';
1254
+ return `[TransactionType (code=${this.code})]`;
1251
1255
  }
1252
1256
  }
1253
1257
 
@@ -1755,7 +1759,7 @@ module.exports = (() => {
1755
1759
  const tree = new Tree();
1756
1760
 
1757
1761
  createGroups.call(this, tree, this._items, treeDefinition, treeDefinition.definitions);
1758
-
1762
+
1759
1763
  map[treeDefinition.name] = tree;
1760
1764
 
1761
1765
  return map;
@@ -2087,6 +2091,41 @@ module.exports = (() => {
2087
2091
  return is.object(item) && item.data.locked;
2088
2092
  }
2089
2093
 
2094
+ /**
2095
+ * Causes a position to be flagged as calculating.
2096
+ *
2097
+ * @public
2098
+ * @param {Object} position
2099
+ */
2100
+ setPositionCalculating(position) {
2101
+ if (position) {
2102
+ assert.argumentIsRequired(position, 'position', Object);
2103
+ assert.argumentIsRequired(position.position, 'position.position', String);
2104
+
2105
+ const item = this._items.find(i => i.position.position === position.position);
2106
+
2107
+ if (item) {
2108
+ item.setPositionCalculating(position);
2109
+ }
2110
+ }
2111
+ }
2112
+
2113
+ /**
2114
+ * Returns a position's calculating status.
2115
+ *
2116
+ * @public
2117
+ * @param {Object} position
2118
+ * @return {Boolean}
2119
+ */
2120
+ getPositionCalculating(position) {
2121
+ assert.argumentIsRequired(position, 'position', Object);
2122
+ assert.argumentIsRequired(position.position, 'position.position', String);
2123
+
2124
+ const item = this._items.find(i => i.position.position === position.position);
2125
+
2126
+ return is.object(item) && item.data.calculating;
2127
+ }
2128
+
2090
2129
  /**
2091
2130
  * Performs a batch update of both position quotes and forex quotes,
2092
2131
  * triggering updates to position(s) and data aggregation(s).
@@ -2139,6 +2178,26 @@ module.exports = (() => {
2139
2178
  }
2140
2179
  }
2141
2180
 
2181
+ /**
2182
+ * Returns current price for symbol provided.
2183
+ *
2184
+ * @param {String} symbol
2185
+ * @return {null|Number}
2186
+ */
2187
+ getCurrentPrice(symbol) {
2188
+ assert.argumentIsRequired(symbol, 'symbol', String);
2189
+
2190
+ let price;
2191
+
2192
+ if (this._symbols.hasOwnProperty(symbol) && this._symbols[symbol].length > 0) {
2193
+ price = this._symbols[symbol][0].currentPrice;
2194
+ } else {
2195
+ price = null;
2196
+ }
2197
+
2198
+ return price;
2199
+ }
2200
+
2142
2201
  /**
2143
2202
  * Sets a historical forex quote.
2144
2203
  *
@@ -2749,6 +2808,7 @@ module.exports = (() => {
2749
2808
  this._dataFormat.hide = false;
2750
2809
  this._dataFormat.invalid = false;
2751
2810
  this._dataFormat.locked = false;
2811
+ this._dataFormat.calculating = false;
2752
2812
  this._dataFormat.newsExists = false;
2753
2813
  this._dataFormat.quantity = null;
2754
2814
  this._dataFormat.quantityPrevious = null;
@@ -3256,6 +3316,7 @@ module.exports = (() => {
3256
3316
 
3257
3317
  let newsBinding = Disposable.getEmpty();
3258
3318
  let lockedBinding = Disposable.getEmpty();
3319
+ let calculatingBinding = Disposable.getEmpty();
3259
3320
 
3260
3321
  if (this._single) {
3261
3322
  newsBinding = item.registerNewsExistsChangeHandler((exists) => {
@@ -3266,6 +3327,10 @@ module.exports = (() => {
3266
3327
  lockedBinding = item.registerLockChangeHandler((locked) => {
3267
3328
  this._dataFormat.locked = locked;
3268
3329
  });
3330
+
3331
+ calculatingBinding = item.registerCalculatingChangeHandler((calculating) => {
3332
+ this._dataFormat.calculating = calculating;
3333
+ });
3269
3334
  }
3270
3335
 
3271
3336
  this._disposeStack.push(item.registerPortfolioChangeHandler((portfolio) => {
@@ -3280,6 +3345,7 @@ module.exports = (() => {
3280
3345
  this._disposeStack.push(fundamentalBinding);
3281
3346
  this._disposeStack.push(quoteBinding);
3282
3347
  this._disposeStack.push(lockedBinding);
3348
+ this._disposeStack.push(calculatingBinding);
3283
3349
  this._disposeStack.push(newsBinding);
3284
3350
 
3285
3351
  this._disposeStack.push(item.registerPositionItemDisposeHandler(() => {
@@ -3287,6 +3353,7 @@ module.exports = (() => {
3287
3353
  quoteBinding.dispose();
3288
3354
  newsBinding.dispose();
3289
3355
  lockedBinding.dispose();
3356
+ calculatingBinding.dispose();
3290
3357
 
3291
3358
  array.remove(this._items, i => i === item);
3292
3359
  array.remove(this._excludedItems, i => i === item);
@@ -3339,7 +3406,7 @@ module.exports = (() => {
3339
3406
  const format = group._dataFormat;
3340
3407
 
3341
3408
  const currency = group.currency;
3342
-
3409
+
3343
3410
  const items = group._consideredItems;
3344
3411
 
3345
3412
  group._bypassCurrencyTranslation = items.every(item => item.currency === currency);
@@ -3470,6 +3537,7 @@ module.exports = (() => {
3470
3537
 
3471
3538
  format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
3472
3539
  format.locked = definition.type === PositionLevelType.POSITION && item.data.locked;
3540
+ format.calculating = definition.type === PositionLevelType.POSITION && item.data.calculating;
3473
3541
  }
3474
3542
 
3475
3543
  let portfolioType = null;
@@ -3575,7 +3643,7 @@ module.exports = (() => {
3575
3643
  actual.marketChangePercent = marketChangePercent;
3576
3644
 
3577
3645
  format.market = formatCurrency(actual.market, currency);
3578
-
3646
+
3579
3647
  if (updates.marketDirection.up || updates.marketDirection.down) {
3580
3648
  format.marketDirection = unchanged;
3581
3649
  setTimeout(() => format.marketDirection = updates.marketDirection, 0);
@@ -3764,7 +3832,7 @@ module.exports = (() => {
3764
3832
 
3765
3833
  this._data.quantity = null;
3766
3834
  this._data.quantityPrevious = null;
3767
-
3835
+
3768
3836
  this._data.realized = null;
3769
3837
  this._data.income = null;
3770
3838
  this._data.basisPrice = null;
@@ -3796,12 +3864,14 @@ module.exports = (() => {
3796
3864
 
3797
3865
  this._data.newsExists = false;
3798
3866
  this._data.fundamental = { };
3867
+ this._data.calculating = getIsCalculating(position);
3799
3868
  this._data.locked = getIsLocked(position);
3800
3869
 
3801
3870
  this._quoteChangedEvent = new Event(this);
3802
3871
  this._newsExistsChangedEvent = new Event(this);
3803
3872
  this._fundamentalDataChangedEvent = new Event(this);
3804
3873
  this._lockChangedEvent = new Event(this);
3874
+ this._calculatingChangedEvent = new Event(this);
3805
3875
  this._portfolioChangedEvent = new Event(this);
3806
3876
  this._positionItemDisposeEvent = new Event(this);
3807
3877
 
@@ -3899,6 +3969,15 @@ module.exports = (() => {
3899
3969
  return this._previousQuote;
3900
3970
  }
3901
3971
 
3972
+ /**
3973
+ * The current price.
3974
+ *
3975
+ * @return {null|Number}
3976
+ */
3977
+ get currentPrice() {
3978
+ return this._currentPrice;
3979
+ }
3980
+
3902
3981
  updatePortfolio(portfolio) {
3903
3982
  assert.argumentIsRequired(portfolio, 'portfolio', Object);
3904
3983
  assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
@@ -3998,6 +4077,26 @@ module.exports = (() => {
3998
4077
  }
3999
4078
  }
4000
4079
 
4080
+ /**
4081
+ * Sets a position's calculating status.
4082
+ *
4083
+ * @public
4084
+ * @param {Object} position
4085
+ */
4086
+ setPositionCalculating(position) {
4087
+ assert.argumentIsRequired(position, 'position', Object);
4088
+
4089
+ if (this.getIsDisposed()) {
4090
+ return;
4091
+ }
4092
+
4093
+ const value = getIsCalculating(position);
4094
+
4095
+ if (this._data.calculating !== value) {
4096
+ this._calculatingChangedEvent.fire(this._data.calculating = value);
4097
+ }
4098
+ }
4099
+
4001
4100
  /**
4002
4101
  * Registers an observer for quote changes, which is fired after internal recalculations
4003
4102
  * of position data are complete.
@@ -4043,6 +4142,17 @@ module.exports = (() => {
4043
4142
  return this._lockChangedEvent.register(handler);
4044
4143
  }
4045
4144
 
4145
+ /**
4146
+ * Registers an observer for position calculating changes.
4147
+ *
4148
+ * @public
4149
+ * @param {Function} handler
4150
+ * @return {Disposable}
4151
+ */
4152
+ registerCalculatingChangeHandler(handler) {
4153
+ return this._calculatingChangedEvent.register(handler);
4154
+ }
4155
+
4046
4156
  /**
4047
4157
  * Registers an observer changes to portfolio metadata.
4048
4158
  *
@@ -4405,6 +4515,12 @@ module.exports = (() => {
4405
4515
  return is.object(position.system) && is.boolean(position.system.locked) && position.system.locked;
4406
4516
  }
4407
4517
 
4518
+ function getIsCalculating(position) {
4519
+ assert.argumentIsRequired(position, 'position', Object);
4520
+
4521
+ return is.object(position.system) && is.object(position.system.calculate) && is.number(position.system.calculate.processors) && position.system.calculate.processors > 0;
4522
+ }
4523
+
4408
4524
  function getSnapshot(position, currentSummary, reporting) {
4409
4525
  let snapshot;
4410
4526
 
@@ -4980,6 +5096,7 @@ module.exports = (() => {
4980
5096
  const complete = new TransactionSchema(SchemaBuilder.withName('complete')
4981
5097
  .withField('portfolio', DataType.STRING)
4982
5098
  .withField('position', DataType.STRING)
5099
+ .withField('transaction', DataType.STRING)
4983
5100
  .withField('sequence', DataType.NUMBER)
4984
5101
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
4985
5102
  .withField('date', DataType.DAY)
@@ -5029,6 +5146,7 @@ module.exports = (() => {
5029
5146
  const client = new TransactionSchema(SchemaBuilder.withName('client')
5030
5147
  .withField('portfolio', DataType.STRING)
5031
5148
  .withField('position', DataType.STRING)
5149
+ .withField('transaction', DataType.STRING)
5032
5150
  .withField('sequence', DataType.NUMBER)
5033
5151
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
5034
5152
  .withField('date', DataType.DAY)
package/jsdoc.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "source": {
3
- "include": [ "." ],
4
- "exclude": [ "./node_modules", "./test" ],
5
- "includePattern": ".+\\.js(doc|x)?$",
6
- "excludePattern": "(^|\\/|\\\\)_"
7
- }
8
- }