@barchart/portfolio-api-common 1.2.2 → 1.2.6

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.
@@ -155,8 +155,8 @@ module.exports = (() => {
155
155
  /**
156
156
  * Generates an identifier for the instrument.
157
157
  *
158
- * @static
159
158
  * @public
159
+ * @static
160
160
  * @param {Object} instrument
161
161
  * @returns {String}
162
162
  */
@@ -164,6 +164,25 @@ module.exports = (() => {
164
164
  return map[instrument.type.code].generateIdentifier(instrument);
165
165
  }
166
166
 
167
+ /**
168
+ *
169
+ * @public
170
+ * @static
171
+ * @param code
172
+ * @return {InstrumentType}
173
+ */
174
+ static fromSymbolType(code) {
175
+ assert.argumentIsRequired(code, 'code', Number);
176
+
177
+ if (code === 1 || code === 6) {
178
+ return InstrumentType.EQUITY;
179
+ } else if (code === 5 || code == 15) {
180
+ return InstrumentType.FUND;
181
+ } else {
182
+ throw new Error('Unable to determine InstrumentType for [', code, ']');
183
+ }
184
+ }
185
+
167
186
  toString() {
168
187
  return '[InstrumentType]';
169
188
  }
@@ -71,6 +71,7 @@ module.exports = (() => {
71
71
  this._dataFormat.key = this._key;
72
72
  this._dataFormat.description = this._description;
73
73
  this._dataFormat.hide = false;
74
+ this._dataFormat.invalid = false;
74
75
  this._dataFormat.newsExists = false;
75
76
  this._dataFormat.quantity = null;
76
77
  this._dataFormat.basisPrice = null;
@@ -412,7 +413,7 @@ module.exports = (() => {
412
413
  * @public
413
414
  */
414
415
  refresh() {
415
- calculateStaticData(this, this._rates);
416
+ calculateStaticData(this, this._rates, this._definition);
416
417
  calculatePriceData(this, this._rates, null, true);
417
418
  }
418
419
 
@@ -614,7 +615,7 @@ module.exports = (() => {
614
615
  return formatDecimal(decimal, currency.precision);
615
616
  }
616
617
 
617
- function calculateStaticData(group, rates) {
618
+ function calculateStaticData(group, rates, definition) {
618
619
  const actual = group._dataActual;
619
620
  const format = group._dataFormat;
620
621
 
@@ -691,6 +692,8 @@ module.exports = (() => {
691
692
 
692
693
  format.quantity = formatDecimal(actual.quantity, 2);
693
694
  format.basisPrice = formatCurrency(actual.basisPrice, currency);
695
+
696
+ format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
694
697
  }
695
698
 
696
699
  const groupItems = group._items;
@@ -27,7 +27,11 @@ module.exports = (() => {
27
27
 
28
28
  this._portfolio = portfolio;
29
29
  this._position = position;
30
- this._currency = position.instrument.currency || Currency.CAD;
30
+
31
+ const instrument = position.instrument;
32
+
33
+ this._currency = instrument.currency || Currency.CAD;
34
+ this._invalid = instrument.type.usesSymbols && (!is.object(instrument.symbol) || !is.string(instrument.symbol.barchart));
31
35
 
32
36
  this._currentSummary = currentSummary || null;
33
37
  this._previousSummaries = previousSummaries || [ ];
@@ -107,6 +111,16 @@ module.exports = (() => {
107
111
  return this._currency;
108
112
  }
109
113
 
114
+ /**
115
+ * Indicates if the position's symbol is invalid.
116
+ *
117
+ * @public
118
+ * @returns {Boolean}
119
+ */
120
+ get invalid() {
121
+ return this._invalid;
122
+ }
123
+
110
124
  /**
111
125
  * The year-to-date position summary of the encapsulated position.
112
126
  *
@@ -138,6 +138,11 @@ module.exports = (() => {
138
138
  const update = new PositionSchema(SchemaBuilder.withName('update')
139
139
  .withField('portfolio', DataType.STRING)
140
140
  .withField('position', DataType.STRING)
141
+ .withField('mapping.name', DataType.STRING, true)
142
+ .withField('mapping.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
143
+ .withField('mapping.currency', DataType.forEnum(Currency, 'Currency'), true)
144
+ .withField('mapping.symbol.barchart', DataType.STRING, true)
145
+ .withField('mapping.symbol.display', DataType.STRING, true)
141
146
  .withField('reinvest', DataType.BOOLEAN, true)
142
147
  .schema
143
148
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.2",
3
+ "version": "1.2.6",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -156,8 +156,8 @@ module.exports = (() => {
156
156
  /**
157
157
  * Generates an identifier for the instrument.
158
158
  *
159
- * @static
160
159
  * @public
160
+ * @static
161
161
  * @param {Object} instrument
162
162
  * @returns {String}
163
163
  */
@@ -165,6 +165,25 @@ module.exports = (() => {
165
165
  return map[instrument.type.code].generateIdentifier(instrument);
166
166
  }
167
167
 
168
+ /**
169
+ *
170
+ * @public
171
+ * @static
172
+ * @param code
173
+ * @return {InstrumentType}
174
+ */
175
+ static fromSymbolType(code) {
176
+ assert.argumentIsRequired(code, 'code', Number);
177
+
178
+ if (code === 1 || code === 6) {
179
+ return InstrumentType.EQUITY;
180
+ } else if (code === 5 || code == 15) {
181
+ return InstrumentType.FUND;
182
+ } else {
183
+ throw new Error('Unable to determine InstrumentType for [', code, ']');
184
+ }
185
+ }
186
+
168
187
  toString() {
169
188
  return '[InstrumentType]';
170
189
  }
@@ -2173,6 +2192,7 @@ module.exports = (() => {
2173
2192
  this._dataFormat.key = this._key;
2174
2193
  this._dataFormat.description = this._description;
2175
2194
  this._dataFormat.hide = false;
2195
+ this._dataFormat.invalid = false;
2176
2196
  this._dataFormat.newsExists = false;
2177
2197
  this._dataFormat.quantity = null;
2178
2198
  this._dataFormat.basisPrice = null;
@@ -2514,7 +2534,7 @@ module.exports = (() => {
2514
2534
  * @public
2515
2535
  */
2516
2536
  refresh() {
2517
- calculateStaticData(this, this._rates);
2537
+ calculateStaticData(this, this._rates, this._definition);
2518
2538
  calculatePriceData(this, this._rates, null, true);
2519
2539
  }
2520
2540
 
@@ -2716,7 +2736,7 @@ module.exports = (() => {
2716
2736
  return formatDecimal(decimal, currency.precision);
2717
2737
  }
2718
2738
 
2719
- function calculateStaticData(group, rates) {
2739
+ function calculateStaticData(group, rates, definition) {
2720
2740
  const actual = group._dataActual;
2721
2741
  const format = group._dataFormat;
2722
2742
 
@@ -2793,6 +2813,8 @@ module.exports = (() => {
2793
2813
 
2794
2814
  format.quantity = formatDecimal(actual.quantity, 2);
2795
2815
  format.basisPrice = formatCurrency(actual.basisPrice, currency);
2816
+
2817
+ format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
2796
2818
  }
2797
2819
 
2798
2820
  const groupItems = group._items;
@@ -2988,7 +3010,11 @@ module.exports = (() => {
2988
3010
 
2989
3011
  this._portfolio = portfolio;
2990
3012
  this._position = position;
2991
- this._currency = position.instrument.currency || Currency.CAD;
3013
+
3014
+ const instrument = position.instrument;
3015
+
3016
+ this._currency = instrument.currency || Currency.CAD;
3017
+ this._invalid = instrument.type.usesSymbols && (!is.object(instrument.symbol) || !is.string(instrument.symbol.barchart));
2992
3018
 
2993
3019
  this._currentSummary = currentSummary || null;
2994
3020
  this._previousSummaries = previousSummaries || [ ];
@@ -3068,6 +3094,16 @@ module.exports = (() => {
3068
3094
  return this._currency;
3069
3095
  }
3070
3096
 
3097
+ /**
3098
+ * Indicates if the position's symbol is invalid.
3099
+ *
3100
+ * @public
3101
+ * @returns {Boolean}
3102
+ */
3103
+ get invalid() {
3104
+ return this._invalid;
3105
+ }
3106
+
3071
3107
  /**
3072
3108
  * The year-to-date position summary of the encapsulated position.
3073
3109
  *