@riocrypto/common-server 1.0.1306 → 1.0.1307
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.
|
@@ -52,32 +52,15 @@ const getExchangeRates = (from, to, noMarkups) => __awaiter(void 0, void 0, void
|
|
|
52
52
|
conversionRateWithMarkups = conversionRate * 0.996;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
console.log("conversion rate with markups", conversionRateWithMarkups);
|
|
56
|
-
let safestPrice = conversionRateWithMarkups;
|
|
57
|
-
// Volatility based markups
|
|
58
|
-
const { startDate, endDate } = getDateRange();
|
|
59
|
-
const data = yield currencyAPIClient.getHistoricalExchangeRates(from, to, startDate.toISOString(), endDate.toISOString());
|
|
60
|
-
const values = data.map((point) => point.currencies[to].value);
|
|
61
|
-
const average = values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
62
|
-
const squaredDeviations = values.map((value) => (value - average) ** 2);
|
|
63
|
-
const variance = squaredDeviations.reduce((sum, deviation) => sum + deviation, 0) /
|
|
64
|
-
values.length;
|
|
65
|
-
const volatility = Math.sqrt(variance);
|
|
66
|
-
const maximumPriceChange = volatility * (QUOTE_DURATION_MINUTES / 2);
|
|
67
|
-
safestPrice = safestPrice - maximumPriceChange;
|
|
68
|
-
// Bank based markups
|
|
69
|
-
let exchangeRateMultiplier = from === common_1.Fiat.PEN ? 0.9987 : 0.9997;
|
|
70
|
-
safestPrice = safestPrice * exchangeRateMultiplier;
|
|
71
55
|
return {
|
|
72
56
|
conversionRate,
|
|
73
57
|
conversionRateWithMarkups,
|
|
74
|
-
safestPrice,
|
|
75
58
|
};
|
|
76
59
|
});
|
|
77
60
|
exports.getExchangeRates = getExchangeRates;
|
|
78
|
-
function getDateRange() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
61
|
+
// function getDateRange(): { startDate: Date; endDate: Date } {
|
|
62
|
+
// const endDate = new Date(); // Current time
|
|
63
|
+
// // Subtract 10 minutes from the end_date
|
|
64
|
+
// const startDate = new Date(endDate.getTime() - 10 * 60 * 1000);
|
|
65
|
+
// return { startDate, endDate };
|
|
66
|
+
// }
|