@riocrypto/common-server 1.0.2910 → 1.0.2911
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.
|
@@ -17,6 +17,16 @@ const common_1 = require("@riocrypto/common");
|
|
|
17
17
|
const https_1 = __importDefault(require("https"));
|
|
18
18
|
const axios_with_logging_1 = require("./axios-with-logging");
|
|
19
19
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
20
|
+
/**
|
|
21
|
+
* Deadline for one FX price report.
|
|
22
|
+
*
|
|
23
|
+
* Generous enough for a round trip through the public ingress, and short
|
|
24
|
+
* enough that a stalled path costs a gap in reports rather than a
|
|
25
|
+
* publisher that never sends again. Comfortably inside the staleness
|
|
26
|
+
* thresholds market-data judges these feeds by, so an abandoned report
|
|
27
|
+
* does not by itself make a source look dead.
|
|
28
|
+
*/
|
|
29
|
+
const FX_OBSERVATION_TIMEOUT_MS = 5000;
|
|
20
30
|
class ClusterClient {
|
|
21
31
|
constructor(baseUrl, clusterApiKey) {
|
|
22
32
|
this.baseUrl = baseUrl;
|
|
@@ -1013,7 +1023,17 @@ class ClusterClient {
|
|
|
1013
1023
|
// means the report was recorded while another source is active.
|
|
1014
1024
|
reportFXPriceObservation(params) {
|
|
1015
1025
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1016
|
-
const response = yield this.axios.post(`${this.baseUrl}/api/market/data/fx-observation`, params, {
|
|
1026
|
+
const response = yield this.axios.post(`${this.baseUrl}/api/market/data/fx-observation`, params, {
|
|
1027
|
+
headers: { "x-cluster-api-key": this.clusterApiKey },
|
|
1028
|
+
// The shared axios instance has no default timeout, which is fine
|
|
1029
|
+
// for the request/response calls on this client but not for one
|
|
1030
|
+
// published on a fixed interval. Without a deadline a stalled
|
|
1031
|
+
// ingest path leaves requests open indefinitely and the publisher
|
|
1032
|
+
// accumulates them. Scoped to this call rather than set as a
|
|
1033
|
+
// client default, because several endpoints here are legitimately
|
|
1034
|
+
// slow and would start failing.
|
|
1035
|
+
timeout: FX_OBSERVATION_TIMEOUT_MS,
|
|
1036
|
+
});
|
|
1017
1037
|
return response.data;
|
|
1018
1038
|
});
|
|
1019
1039
|
}
|
|
@@ -44,7 +44,11 @@ class CurrencyAPIClient {
|
|
|
44
44
|
if (!cachedResponse) {
|
|
45
45
|
throw new common_1.GenericInternalError(`Unable to get exchange rate from currencyAPI for ${from} to ${to}`);
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
// Assigns the outer binding deliberately. Declaring a local here
|
|
48
|
+
// shadowed it, so the cached rate was computed and thrown away and
|
|
49
|
+
// the zero check below then threw, which made this whole fallback
|
|
50
|
+
// unreachable on the one path it exists for.
|
|
51
|
+
exchangeRate = cachedResponse.data[to].value;
|
|
48
52
|
}
|
|
49
53
|
if (!exchangeRate) {
|
|
50
54
|
(_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.error("Unable to get exchange rate");
|