@riocrypto/common-server 1.0.1010 → 1.0.1011
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.
|
@@ -16,15 +16,6 @@ const kapstar_client_1 = require("../clients/kapstar-client");
|
|
|
16
16
|
const QUOTE_DURATION_MINUTES = 10;
|
|
17
17
|
const getExchangeRates = (from, to, volatilitySafeguard = true) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
|
|
19
|
-
const { startDate, endDate } = getDateRange();
|
|
20
|
-
const data = yield currencyAPIClient.getHistoricalExchangeRates(from, to, startDate.toISOString(), endDate.toISOString());
|
|
21
|
-
const values = data.map((point) => point.currencies[to].value);
|
|
22
|
-
const average = values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
23
|
-
const squaredDeviations = values.map((value) => (value - average) ** 2);
|
|
24
|
-
const variance = squaredDeviations.reduce((sum, deviation) => sum + deviation, 0) /
|
|
25
|
-
values.length;
|
|
26
|
-
const volatility = Math.sqrt(variance);
|
|
27
|
-
const maximumPriceChange = volatility * QUOTE_DURATION_MINUTES;
|
|
28
19
|
const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
|
|
29
20
|
const conversionRate = to === common_1.Fiat.BRL
|
|
30
21
|
? yield kapstarClient.getBRLExchangeRateUSD()
|
|
@@ -37,6 +28,15 @@ const getExchangeRates = (from, to, volatilitySafeguard = true) => __awaiter(voi
|
|
|
37
28
|
conversionRateWithAllMarkups: conversionRate,
|
|
38
29
|
};
|
|
39
30
|
}
|
|
31
|
+
const { startDate, endDate } = getDateRange();
|
|
32
|
+
const data = yield currencyAPIClient.getHistoricalExchangeRates(from, to, startDate.toISOString(), endDate.toISOString());
|
|
33
|
+
const values = data.map((point) => point.currencies[to].value);
|
|
34
|
+
const average = values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
35
|
+
const squaredDeviations = values.map((value) => (value - average) ** 2);
|
|
36
|
+
const variance = squaredDeviations.reduce((sum, deviation) => sum + deviation, 0) /
|
|
37
|
+
values.length;
|
|
38
|
+
const volatility = Math.sqrt(variance);
|
|
39
|
+
const maximumPriceChange = volatility * QUOTE_DURATION_MINUTES;
|
|
40
40
|
let conversionRateWithVolatilityMarkup;
|
|
41
41
|
conversionRateWithVolatilityMarkup = conversionRate - maximumPriceChange;
|
|
42
42
|
let exchangeRateMultiplier = 0.9997;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1011",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
25
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
26
26
|
"@google-cloud/storage": "^6.9.5",
|
|
27
|
-
"@riocrypto/common": "^1.0.
|
|
27
|
+
"@riocrypto/common": "^1.0.872",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|