@barchart/portfolio-api-common 1.0.122 → 1.0.126
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
|
|
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
|
-
|
|
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,14 @@ module.exports = (() => {
|
|
|
259
275
|
} else {
|
|
260
276
|
this._forexQuotes[index] = rate;
|
|
261
277
|
}
|
|
278
|
+
|
|
279
|
+
this._trees.forEach((tree) => {
|
|
280
|
+
tree.walk(group => group.setForexRate(rate), true, false);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
setPositionFundamentals(data) {
|
|
285
|
+
return;
|
|
262
286
|
}
|
|
263
287
|
|
|
264
288
|
getGroup(name, keys) {
|
|
@@ -301,5 +325,22 @@ module.exports = (() => {
|
|
|
301
325
|
return ranges.map(range => null);
|
|
302
326
|
}
|
|
303
327
|
|
|
328
|
+
function extractSymbolForBarchart(position) {
|
|
329
|
+
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
330
|
+
return position.instrument.symbol.barchart;
|
|
331
|
+
} else {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function extractSymbolForDisplay(position) {
|
|
337
|
+
if (position.instrument && position.instrument.symbol && position.instrument.symbol.display) {
|
|
338
|
+
return position.instrument.symbol.display;
|
|
339
|
+
} else {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
|
|
304
345
|
return PositionContainer;
|
|
305
346
|
})();
|
|
@@ -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
|
-
|
|
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
|
|
|
@@ -413,7 +418,7 @@ module.exports = (() => {
|
|
|
413
418
|
let numerator;
|
|
414
419
|
|
|
415
420
|
if (group.currency !== parent.currency) {
|
|
416
|
-
numerator = Rate.convert(
|
|
421
|
+
numerator = Rate.convert(actual.market, group.currency, parent.currency, ...rates);
|
|
417
422
|
} else {
|
|
418
423
|
numerator = actual.market;
|
|
419
424
|
}
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -811,11 +811,9 @@ module.exports = (() => {
|
|
|
811
811
|
}, [ ]);
|
|
812
812
|
|
|
813
813
|
this._symbols = this._items.reduce((map, item) => {
|
|
814
|
-
const
|
|
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
|
-
|
|
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,14 @@ module.exports = (() => {
|
|
|
975
991
|
} else {
|
|
976
992
|
this._forexQuotes[index] = rate;
|
|
977
993
|
}
|
|
994
|
+
|
|
995
|
+
this._trees.forEach((tree) => {
|
|
996
|
+
tree.walk(group => group.setForexRate(rate), true, false);
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
setPositionFundamentals(data) {
|
|
1001
|
+
return;
|
|
978
1002
|
}
|
|
979
1003
|
|
|
980
1004
|
getGroup(name, keys) {
|
|
@@ -1017,6 +1041,23 @@ module.exports = (() => {
|
|
|
1017
1041
|
return ranges.map(range => null);
|
|
1018
1042
|
}
|
|
1019
1043
|
|
|
1044
|
+
function extractSymbolForBarchart(position) {
|
|
1045
|
+
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
1046
|
+
return position.instrument.symbol.barchart;
|
|
1047
|
+
} else {
|
|
1048
|
+
return null;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function extractSymbolForDisplay(position) {
|
|
1053
|
+
if (position.instrument && position.instrument.symbol && position.instrument.symbol.display) {
|
|
1054
|
+
return position.instrument.symbol.display;
|
|
1055
|
+
} else {
|
|
1056
|
+
return null;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
|
|
1020
1061
|
return PositionContainer;
|
|
1021
1062
|
})();
|
|
1022
1063
|
|
|
@@ -1042,6 +1083,7 @@ module.exports = (() => {
|
|
|
1042
1083
|
|
|
1043
1084
|
this._items = items;
|
|
1044
1085
|
this._currency = currency || Currency.CAD;
|
|
1086
|
+
this._bypassCurrencyTranslation = false;
|
|
1045
1087
|
|
|
1046
1088
|
this._key = key;
|
|
1047
1089
|
this._description = description;
|
|
@@ -1179,8 +1221,10 @@ module.exports = (() => {
|
|
|
1179
1221
|
return this._excluded;
|
|
1180
1222
|
}
|
|
1181
1223
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1224
|
+
setForexRate(rate) {
|
|
1225
|
+
if (!this._bypassCurrencyTranslation) {
|
|
1226
|
+
this.refresh();
|
|
1227
|
+
}
|
|
1184
1228
|
}
|
|
1185
1229
|
|
|
1186
1230
|
setExcluded(value) {
|
|
@@ -1265,6 +1309,8 @@ module.exports = (() => {
|
|
|
1265
1309
|
|
|
1266
1310
|
const items = group._items;
|
|
1267
1311
|
|
|
1312
|
+
group._bypassCurrencyTranslation = items.some(item => item.currency !== currency);
|
|
1313
|
+
|
|
1268
1314
|
const translate = (item, value) => {
|
|
1269
1315
|
let translated;
|
|
1270
1316
|
|
|
@@ -1436,7 +1482,7 @@ module.exports = (() => {
|
|
|
1436
1482
|
let numerator;
|
|
1437
1483
|
|
|
1438
1484
|
if (group.currency !== parent.currency) {
|
|
1439
|
-
numerator = Rate.convert(
|
|
1485
|
+
numerator = Rate.convert(actual.market, group.currency, parent.currency, ...rates);
|
|
1440
1486
|
} else {
|
|
1441
1487
|
numerator = actual.market;
|
|
1442
1488
|
}
|