@barchart/portfolio-api-common 1.2.3 → 1.2.7

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 || code === 7) {
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
 
@@ -458,9 +459,6 @@ module.exports = (() => {
458
459
  if (this._single) {
459
460
  const precision = sender.position.instrument.currency.precision;
460
461
 
461
- this._dataActual.invalid = this._definition.type === PositionLevelType.POSITION && item.invalid;
462
- this._dataFormat.invalid = this._dataActual.invalid;
463
-
464
462
  this._dataActual.currentPrice = quote.lastPrice;
465
463
  this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
466
464
 
@@ -617,7 +615,7 @@ module.exports = (() => {
617
615
  return formatDecimal(decimal, currency.precision);
618
616
  }
619
617
 
620
- function calculateStaticData(group, rates) {
618
+ function calculateStaticData(group, rates, definition) {
621
619
  const actual = group._dataActual;
622
620
  const format = group._dataFormat;
623
621
 
@@ -694,6 +692,8 @@ module.exports = (() => {
694
692
 
695
693
  format.quantity = formatDecimal(actual.quantity, 2);
696
694
  format.basisPrice = formatCurrency(actual.basisPrice, currency);
695
+
696
+ format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
697
697
  }
698
698
 
699
699
  const groupItems = group._items;
@@ -111,6 +111,16 @@ module.exports = (() => {
111
111
  return this._currency;
112
112
  }
113
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
+
114
124
  /**
115
125
  * The year-to-date position summary of the encapsulated position.
116
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.3",
3
+ "version": "1.2.7",
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 || code === 7) {
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
 
@@ -2560,9 +2580,6 @@ module.exports = (() => {
2560
2580
  if (this._single) {
2561
2581
  const precision = sender.position.instrument.currency.precision;
2562
2582
 
2563
- this._dataActual.invalid = this._definition.type === PositionLevelType.POSITION && item.invalid;
2564
- this._dataFormat.invalid = this._dataActual.invalid;
2565
-
2566
2583
  this._dataActual.currentPrice = quote.lastPrice;
2567
2584
  this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
2568
2585
 
@@ -2719,7 +2736,7 @@ module.exports = (() => {
2719
2736
  return formatDecimal(decimal, currency.precision);
2720
2737
  }
2721
2738
 
2722
- function calculateStaticData(group, rates) {
2739
+ function calculateStaticData(group, rates, definition) {
2723
2740
  const actual = group._dataActual;
2724
2741
  const format = group._dataFormat;
2725
2742
 
@@ -2796,6 +2813,8 @@ module.exports = (() => {
2796
2813
 
2797
2814
  format.quantity = formatDecimal(actual.quantity, 2);
2798
2815
  format.basisPrice = formatCurrency(actual.basisPrice, currency);
2816
+
2817
+ format.invalid = definition.type === PositionLevelType.POSITION && item.invalid;
2799
2818
  }
2800
2819
 
2801
2820
  const groupItems = group._items;
@@ -3075,6 +3094,16 @@ module.exports = (() => {
3075
3094
  return this._currency;
3076
3095
  }
3077
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
+
3078
3107
  /**
3079
3108
  * The year-to-date position summary of the encapsulated position.
3080
3109
  *