@barchart/portfolio-api-common 1.0.123 → 1.0.127

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.
@@ -95,11 +95,9 @@ module.exports = (() => {
95
95
  }, [ ]);
96
96
 
97
97
  this._symbols = this._items.reduce((map, item) => {
98
- const position = item.position;
99
-
100
- if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
101
- const symbol = position.instrument.symbol.barchart;
98
+ const symbol = extractSymbolForBarchart(item.position);
102
99
 
100
+ if (symbol) {
103
101
  if (!map.hasOwnProperty(symbol)) {
104
102
  map[symbol] = [ ];
105
103
  }
@@ -225,8 +223,26 @@ module.exports = (() => {
225
223
  return this._defaultCurrency;
226
224
  }
227
225
 
228
- getPositionSymbols() {
229
- return Object.keys(this._symbols);
226
+ getPositionSymbols(display) {
227
+ const symbols = this._items.reduce((symbols, item) => {
228
+ const position = item.position;
229
+
230
+ let symbol;
231
+
232
+ if (display) {
233
+ symbol = extractSymbolForDisplay(position);
234
+ } else {
235
+ symbol = extractSymbolForBarchart(position);
236
+ }
237
+
238
+ if (symbol !== null) {
239
+ symbols.push(symbol);
240
+ }
241
+
242
+ return symbols;
243
+ }, [ ]);
244
+
245
+ return array.unique(symbols);
230
246
  }
231
247
 
232
248
  setPositionQuote(symbol, quote) {
@@ -259,6 +275,12 @@ module.exports = (() => {
259
275
  } else {
260
276
  this._forexQuotes[index] = rate;
261
277
  }
278
+
279
+ Object.keys(this._trees).forEach(key => this._trees[key].walk(group => group.setForexRate(rate), true, false));
280
+ }
281
+
282
+ setPositionFundamentals(data) {
283
+ return;
262
284
  }
263
285
 
264
286
  getGroup(name, keys) {
@@ -301,5 +323,22 @@ module.exports = (() => {
301
323
  return ranges.map(range => null);
302
324
  }
303
325
 
326
+ function extractSymbolForBarchart(position) {
327
+ if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
328
+ return position.instrument.symbol.barchart;
329
+ } else {
330
+ return null;
331
+ }
332
+ }
333
+
334
+ function extractSymbolForDisplay(position) {
335
+ if (position.instrument && position.instrument.symbol && position.instrument.symbol.display) {
336
+ return position.instrument.symbol.display;
337
+ } else {
338
+ return null;
339
+ }
340
+ }
341
+
342
+
304
343
  return PositionContainer;
305
344
  })();
@@ -19,6 +19,7 @@ module.exports = (() => {
19
19
 
20
20
  this._items = items;
21
21
  this._currency = currency || Currency.CAD;
22
+ this._bypassCurrencyTranslation = false;
22
23
 
23
24
  this._key = key;
24
25
  this._description = description;
@@ -156,8 +157,10 @@ module.exports = (() => {
156
157
  return this._excluded;
157
158
  }
158
159
 
159
- setForexQuote(quote) {
160
-
160
+ setForexRate(rate) {
161
+ if (!this._bypassCurrencyTranslation) {
162
+ this.refresh();
163
+ }
161
164
  }
162
165
 
163
166
  setExcluded(value) {
@@ -242,6 +245,8 @@ module.exports = (() => {
242
245
 
243
246
  const items = group._items;
244
247
 
248
+ group._bypassCurrencyTranslation = items.some(item => item.currency !== currency);
249
+
245
250
  const translate = (item, value) => {
246
251
  let translated;
247
252
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.123",
3
+ "version": "1.0.127",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -811,11 +811,9 @@ module.exports = (() => {
811
811
  }, [ ]);
812
812
 
813
813
  this._symbols = this._items.reduce((map, item) => {
814
- const position = item.position;
815
-
816
- if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
817
- const symbol = position.instrument.symbol.barchart;
814
+ const symbol = extractSymbolForBarchart(item.position);
818
815
 
816
+ if (symbol) {
819
817
  if (!map.hasOwnProperty(symbol)) {
820
818
  map[symbol] = [ ];
821
819
  }
@@ -941,8 +939,26 @@ module.exports = (() => {
941
939
  return this._defaultCurrency;
942
940
  }
943
941
 
944
- getPositionSymbols() {
945
- return Object.keys(this._symbols);
942
+ getPositionSymbols(display) {
943
+ const symbols = this._items.reduce((symbols, item) => {
944
+ const position = item.position;
945
+
946
+ let symbol;
947
+
948
+ if (display) {
949
+ symbol = extractSymbolForDisplay(position);
950
+ } else {
951
+ symbol = extractSymbolForBarchart(position);
952
+ }
953
+
954
+ if (symbol !== null) {
955
+ symbols.push(symbol);
956
+ }
957
+
958
+ return symbols;
959
+ }, [ ]);
960
+
961
+ return array.unique(symbols);
946
962
  }
947
963
 
948
964
  setPositionQuote(symbol, quote) {
@@ -975,6 +991,12 @@ module.exports = (() => {
975
991
  } else {
976
992
  this._forexQuotes[index] = rate;
977
993
  }
994
+
995
+ Object.keys(this._trees).forEach(key => this._trees[key].walk(group => group.setForexRate(rate), true, false));
996
+ }
997
+
998
+ setPositionFundamentals(data) {
999
+ return;
978
1000
  }
979
1001
 
980
1002
  getGroup(name, keys) {
@@ -1017,6 +1039,23 @@ module.exports = (() => {
1017
1039
  return ranges.map(range => null);
1018
1040
  }
1019
1041
 
1042
+ function extractSymbolForBarchart(position) {
1043
+ if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
1044
+ return position.instrument.symbol.barchart;
1045
+ } else {
1046
+ return null;
1047
+ }
1048
+ }
1049
+
1050
+ function extractSymbolForDisplay(position) {
1051
+ if (position.instrument && position.instrument.symbol && position.instrument.symbol.display) {
1052
+ return position.instrument.symbol.display;
1053
+ } else {
1054
+ return null;
1055
+ }
1056
+ }
1057
+
1058
+
1020
1059
  return PositionContainer;
1021
1060
  })();
1022
1061
 
@@ -1042,6 +1081,7 @@ module.exports = (() => {
1042
1081
 
1043
1082
  this._items = items;
1044
1083
  this._currency = currency || Currency.CAD;
1084
+ this._bypassCurrencyTranslation = false;
1045
1085
 
1046
1086
  this._key = key;
1047
1087
  this._description = description;
@@ -1179,8 +1219,10 @@ module.exports = (() => {
1179
1219
  return this._excluded;
1180
1220
  }
1181
1221
 
1182
- setForexQuote(quote) {
1183
-
1222
+ setForexRate(rate) {
1223
+ if (!this._bypassCurrencyTranslation) {
1224
+ this.refresh();
1225
+ }
1184
1226
  }
1185
1227
 
1186
1228
  setExcluded(value) {
@@ -1265,6 +1307,8 @@ module.exports = (() => {
1265
1307
 
1266
1308
  const items = group._items;
1267
1309
 
1310
+ group._bypassCurrencyTranslation = items.some(item => item.currency !== currency);
1311
+
1268
1312
  const translate = (item, value) => {
1269
1313
  let translated;
1270
1314