@barchart/portfolio-api-common 7.3.0 → 7.4.1

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.
@@ -36,6 +36,8 @@ module.exports = (() => {
36
36
  this._portfolio = portfolio;
37
37
  this._position = position;
38
38
 
39
+ this._priceSelctor = getPriceSelector(this._portfolio, this._position);
40
+
39
41
  const instrument = position.instrument;
40
42
 
41
43
  this._currency = instrument.currency || Currency.CAD;
@@ -125,7 +127,7 @@ module.exports = (() => {
125
127
  this._portfolioChangedEvent = new Event(this);
126
128
  this._positionItemDisposeEvent = new Event(this);
127
129
 
128
- calculateStaticData(this, this._today);
130
+ calculateStaticData(this);
129
131
  calculatePriceData(this, null, null, this._today);
130
132
  }
131
133
 
@@ -241,6 +243,8 @@ module.exports = (() => {
241
243
  this._portfolioChangedEvent.fire(this._portfolio = portfolio);
242
244
  }
243
245
 
246
+ this._priceSelctor = getPriceSelector(this._portfolio, this._position);
247
+
244
248
  if (this._currentQuote) {
245
249
  this.setQuote(this._currentQuote, true);
246
250
  }
@@ -258,32 +262,28 @@ module.exports = (() => {
258
262
  assert.argumentIsRequired(quote, 'quote', Object);
259
263
  assert.argumentIsOptional(force, 'force', Boolean);
260
264
 
261
- if (this.getIsDisposed()) {
265
+ if (this.disposed) {
262
266
  return;
263
267
  }
264
268
 
265
- let priceToUse;
269
+ const priceToUse = this._priceSelctor(quote);
266
270
 
267
- if (this.portfolio.miscellany && this.portfolio.miscellany.data && this.portfolio.miscellany.data.optionsValuation === OptionsValuationType.MIDPOINT.code && quote.askPrice && quote.bidPrice) {
268
- priceToUse = (quote.askPrice + quote.bidPrice) / 2;
269
- } else {
270
- priceToUse = quote.lastPrice;
271
+ if (!(this._currentPrice !== priceToUse || force)) {
272
+ return;
271
273
  }
272
274
 
273
- if (this._currentPrice !== priceToUse || force) {
274
- if (quote.previousPrice) {
275
- this._data.previousPrice = quote.previousPrice;
276
- }
275
+ if (quote.previousPrice) {
276
+ this._data.previousPrice = quote.previousPrice;
277
+ }
277
278
 
278
- calculatePriceData(this, priceToUse, calculateQuoteDay(quote), this._today);
279
+ calculatePriceData(this, priceToUse, calculateQuoteDay(quote), this._today);
279
280
 
280
- this._currentPrice = priceToUse;
281
+ this._currentPrice = priceToUse;
281
282
 
282
- this._previousQuote = this._currentQuote;
283
- this._currentQuote = quote;
283
+ this._previousQuote = this._currentQuote;
284
+ this._currentQuote = quote;
284
285
 
285
- this._quoteChangedEvent.fire(this._currentQuote);
286
- }
286
+ this._quoteChangedEvent.fire(this._currentQuote);
287
287
  }
288
288
 
289
289
  /**
@@ -320,7 +320,7 @@ module.exports = (() => {
320
320
  setNewsArticleExists(value) {
321
321
  assert.argumentIsRequired(value, 'value', Boolean);
322
322
 
323
- if (this.getIsDisposed()) {
323
+ if (this.disposed) {
324
324
  return;
325
325
  }
326
326
 
@@ -338,7 +338,7 @@ module.exports = (() => {
338
338
  setPositionFundamentalData(data) {
339
339
  assert.argumentIsRequired(data, 'data', Object);
340
340
 
341
- if (this.getIsDisposed()) {
341
+ if (this.disposed) {
342
342
  return;
343
343
  }
344
344
 
@@ -354,7 +354,7 @@ module.exports = (() => {
354
354
  setPositionLock(position) {
355
355
  assert.argumentIsRequired(position, 'position');
356
356
 
357
- if (this.getIsDisposed()) {
357
+ if (this.disposed) {
358
358
  return;
359
359
  }
360
360
 
@@ -374,7 +374,7 @@ module.exports = (() => {
374
374
  setPositionCalculating(position) {
375
375
  assert.argumentIsRequired(position, 'position', Object);
376
376
 
377
- if (this.getIsDisposed()) {
377
+ if (this.disposed) {
378
378
  return;
379
379
  }
380
380
 
@@ -483,9 +483,8 @@ module.exports = (() => {
483
483
  /**
484
484
  * @private
485
485
  * @param {PositionItem} item
486
- * @param {Day|null} day
487
486
  */
488
- function calculateStaticData(item, day) {
487
+ function calculateStaticData(item) {
489
488
  const position = item.position;
490
489
 
491
490
  const currentSummary = item.currentSummary;
@@ -931,5 +930,41 @@ module.exports = (() => {
931
930
  return null;
932
931
  }
933
932
 
933
+ function selectPriceFromLastPrice(quote) {
934
+ return quote.lastPrice;
935
+ }
936
+
937
+ function selectPriceFromMidpoint(quote) {
938
+ let price = null;
939
+
940
+ if (is.number(quote.askPrice) && is.number(quote.bidPrice)) {
941
+ price = (quote.askPrice + quote.bidPrice) / 2;
942
+ }
943
+
944
+ if (price === null || price === 0) {
945
+ price = quote.lastPrice;
946
+ }
947
+
948
+ return price;
949
+ }
950
+
951
+ function getPriceSelector(portfolio, position) {
952
+ let type = null;
953
+
954
+ if (portfolio.miscellany && portfolio.miscellany.data && portfolio.miscellany.data.optionsValuation) {
955
+ type = OptionsValuationType.parse(portfolio.miscellany.data.optionsValuation);
956
+ }
957
+
958
+ if (type === null) {
959
+ type = OptionsValuationType.LAST_TRADE;
960
+ }
961
+
962
+ if (position.instrument.type.option && type === OptionsValuationType.MIDPOINT) {
963
+ return selectPriceFromMidpoint;
964
+ }
965
+
966
+ return selectPriceFromLastPrice;
967
+ }
968
+
934
969
  return PositionItem;
935
970
  })();
@@ -224,6 +224,7 @@ module.exports = (() => {
224
224
  .withField('position', DataType.STRING)
225
225
  .withField('sequence', DataType.NUMBER, true)
226
226
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
227
+ .withField('instrument.id', DataType.STRING, true)
227
228
  .withField('instrument.name', DataType.STRING, true)
228
229
  .withField('instrument.exchange', DataType.STRING, true)
229
230
  .withField('instrument.code', DataType.NUMBER, true) // Not intended to be the unit code. Same value as [profile] table [type] column. See `InstrumentType.fromSymbolType` function.
@@ -275,6 +276,7 @@ module.exports = (() => {
275
276
  .withField('position', DataType.STRING)
276
277
  .withField('sequence', DataType.NUMBER, true)
277
278
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
279
+ .withField('instrument.id', DataType.STRING, true)
278
280
  .withField('instrument.name', DataType.STRING, true)
279
281
  .withField('instrument.exchange', DataType.STRING, true)
280
282
  .withField('instrument.code', DataType.NUMBER, true) // Not intended to be the unit code. Same value as [profile] table [type] column. See `InstrumentType.fromSymbolType` function.
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "7.3.0",
3
+ "version": "7.4.1",
4
4
  "description": "Common JavaScript code used by Barchart's Portfolio Service",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
7
7
  "email": "bryan.ingle@barchart.com",
8
8
  "url": "https://www.barchart.com"
9
9
  },
10
+ "contributors": [
11
+ {
12
+ "name": "Luka Sotra",
13
+ "email": "luka.sotra@barchart.com",
14
+ "url": "https://www.barchart.com"
15
+ }
16
+ ],
10
17
  "scripts": {
11
18
  "test": "echo \"Error: Please use gulp to run tests\" && exit 1"
12
19
  },
@@ -15,9 +22,9 @@
15
22
  "url": "git+ssh://git@github.com/barchart/portfolio-api-common.git"
16
23
  },
17
24
  "dependencies": {
18
- "@barchart/common-js": "^4.51.0",
25
+ "@barchart/common-js": "^4.71.0",
19
26
  "@barchart/marketdata-api-js": "^6.2.1",
20
- "uuid": "9.0.1"
27
+ "uuid": "^9.0.1"
21
28
  },
22
29
  "devDependencies": {
23
30
  "@babel/core": "^7.6.2",