@barchart/portfolio-api-common 1.27.0 → 1.27.2
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.
|
@@ -583,7 +583,14 @@ module.exports = (() => {
|
|
|
583
583
|
|
|
584
584
|
if (symbol) {
|
|
585
585
|
const rate = Rate.fromPair(quote.lastPrice, symbol);
|
|
586
|
-
|
|
586
|
+
|
|
587
|
+
let index = this._forexQuotes.findIndex(existing => existing.formatPair() === rate.formatPair());
|
|
588
|
+
|
|
589
|
+
if (index < 0) {
|
|
590
|
+
const inverted = rate.invert();
|
|
591
|
+
|
|
592
|
+
index = this._forexQuotes.findIndex(existing => existing.formatPair() === inverted.formatPair());
|
|
593
|
+
}
|
|
587
594
|
|
|
588
595
|
if (index < 0) {
|
|
589
596
|
this._forexQuotes.push(rate);
|
|
@@ -591,13 +598,13 @@ module.exports = (() => {
|
|
|
591
598
|
this._forexQuotes[index] = rate;
|
|
592
599
|
}
|
|
593
600
|
|
|
594
|
-
Object.keys(this._trees).forEach((key) => {
|
|
595
|
-
this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false);
|
|
596
|
-
});
|
|
597
|
-
|
|
598
601
|
recalculatePercentages.call(this);
|
|
599
602
|
}
|
|
600
603
|
});
|
|
604
|
+
|
|
605
|
+
Object.keys(this._trees).forEach((key) => {
|
|
606
|
+
this._trees[key].walk(group => group.setForexRates(this._forexQuotes), true, false);
|
|
607
|
+
});
|
|
601
608
|
}
|
|
602
609
|
|
|
603
610
|
if (positionQuotes.length !== 0 || forexQuotes.length !== 0) {
|
|
@@ -292,7 +292,7 @@ module.exports = (() => {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
/**
|
|
295
|
-
* Indicates if the group will only contain one {@link PositionItem}
|
|
295
|
+
* Indicates if the group will only contain one {@link PositionItem} — that is,
|
|
296
296
|
* indicates if the group represents a single position.
|
|
297
297
|
*
|
|
298
298
|
* @public
|
|
@@ -585,7 +585,7 @@ module.exports = (() => {
|
|
|
585
585
|
if (summary.count > 0) {
|
|
586
586
|
averageFormat = formatPercent(new Decimal(summary.total / summary.count), 2, true);
|
|
587
587
|
} else {
|
|
588
|
-
averageFormat = '
|
|
588
|
+
averageFormat = '—';
|
|
589
589
|
}
|
|
590
590
|
|
|
591
591
|
summary.averageFormat = averageFormat;
|
|
@@ -595,7 +595,7 @@ module.exports = (() => {
|
|
|
595
595
|
|
|
596
596
|
return sums;
|
|
597
597
|
}, fundamentalFields.reduce((sums, fieldName) => {
|
|
598
|
-
sums[fieldName] = { total: 0, count: 0, averageFormat: '
|
|
598
|
+
sums[fieldName] = { total: 0, count: 0, averageFormat: '—' };
|
|
599
599
|
|
|
600
600
|
return sums;
|
|
601
601
|
}, { }));
|
|
@@ -14,8 +14,6 @@ module.exports = (() => {
|
|
|
14
14
|
|
|
15
15
|
const MAXIMUM_WAIT_BEFORE_TIMEOUT_IN_MILLISECONDS = 3 * 1000;
|
|
16
16
|
|
|
17
|
-
const cache = { };
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* A utility that downloads instrument metadata (i.e. instrument "profile" data).
|
|
21
19
|
*
|
|
@@ -39,10 +37,8 @@ module.exports = (() => {
|
|
|
39
37
|
.then(() => {
|
|
40
38
|
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
41
39
|
|
|
42
|
-
return promise.timeout(Gateway.invoke(
|
|
40
|
+
return promise.timeout(Gateway.invoke(instrumentLookupEndpoint, { symbol }), MAXIMUM_WAIT_BEFORE_TIMEOUT_IN_MILLISECONDS, 'instrument lookup')
|
|
43
41
|
.catch((e) => {
|
|
44
|
-
delete cache[symbol];
|
|
45
|
-
|
|
46
42
|
let message;
|
|
47
43
|
|
|
48
44
|
if (is.string(e) && e === 'timeout') {
|
|
@@ -67,32 +63,18 @@ module.exports = (() => {
|
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
.endpoint;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const instrumentLookupEndpoints = new Map();
|
|
86
|
-
|
|
87
|
-
function getInstrumentLookupEndpoint() {
|
|
88
|
-
const host = 'instruments-prod.aws.barchart.com';
|
|
89
|
-
|
|
90
|
-
if (!instrumentLookupEndpoints.has(host)) {
|
|
91
|
-
instrumentLookupEndpoints.set(host, buildInstrumentLookupEndpoint(host));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return instrumentLookupEndpoints.get(host);
|
|
95
|
-
}
|
|
66
|
+
const instrumentLookupEndpoint = EndpointBuilder.for('query-instrument', 'query instrument')
|
|
67
|
+
.withVerb(VerbType.GET)
|
|
68
|
+
.withProtocol(ProtocolType.HTTPS)
|
|
69
|
+
.withHost('instruments-prod.aws.barchart.com')
|
|
70
|
+
.withPort(443)
|
|
71
|
+
.withPathBuilder((pb) => {
|
|
72
|
+
pb.withLiteralParameter('instruments', 'instruments')
|
|
73
|
+
.withVariableParameter('symbol', 'symbol', 'symbol');
|
|
74
|
+
})
|
|
75
|
+
.withResponseInterceptor(ResponseInterceptor.DATA)
|
|
76
|
+
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
77
|
+
.endpoint;
|
|
96
78
|
|
|
97
79
|
return InstrumentProvider;
|
|
98
80
|
})();
|
|
@@ -13,7 +13,7 @@ module.exports = (() => {
|
|
|
13
13
|
*
|
|
14
14
|
* @public
|
|
15
15
|
* @param {InstrumentProvider} provider
|
|
16
|
-
* @param {Number} cacheDuration - The maximum number of milliseconds to cache an instrument.
|
|
16
|
+
* @param {Number=} cacheDuration - The maximum number of milliseconds to cache an instrument.
|
|
17
17
|
*/
|
|
18
18
|
class InstrumentProviderCache {
|
|
19
19
|
constructor(provider, cacheDuration) {
|