@riocrypto/common-server 1.0.1030 → 1.0.1032
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.
|
@@ -47,7 +47,7 @@ class InvopopClient {
|
|
|
47
47
|
},
|
|
48
48
|
customer: {
|
|
49
49
|
name: user.mexicoFiscalName
|
|
50
|
-
? user.mexicoFiscalName
|
|
50
|
+
? user.mexicoFiscalName.toLocaleUpperCase()
|
|
51
51
|
: user.type === common_1.UserType.Business
|
|
52
52
|
? user.companyName.toLocaleUpperCase()
|
|
53
53
|
: `${user.firstName.toLocaleUpperCase()} ${user.lastName.toLocaleUpperCase()}`,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Fiat } from "@riocrypto/common";
|
|
2
|
-
export declare const getExchangeRates: (from: Fiat, to: Fiat,
|
|
2
|
+
export declare const getExchangeRates: (from: Fiat, to: Fiat, noMarkups: boolean) => Promise<{
|
|
3
3
|
conversionRate: number;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
conversionRateWithAllMarkups: number;
|
|
4
|
+
conversionRateWithMarkups?: number | undefined;
|
|
5
|
+
safestPrice?: number | undefined;
|
|
7
6
|
}>;
|
|
@@ -14,20 +14,47 @@ const common_1 = require("@riocrypto/common");
|
|
|
14
14
|
const currency_api_client_1 = require("../clients/currency-api-client");
|
|
15
15
|
const kapstar_client_1 = require("../clients/kapstar-client");
|
|
16
16
|
const QUOTE_DURATION_MINUTES = 10;
|
|
17
|
-
const getExchangeRates = (from, to,
|
|
17
|
+
const getExchangeRates = (from, to, noMarkups) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
|
|
19
19
|
const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
|
|
20
20
|
const conversionRate = to === common_1.Fiat.BRL
|
|
21
21
|
? yield kapstarClient.getBRLExchangeRateUSD()
|
|
22
22
|
: yield currencyAPIClient.convert(from, to);
|
|
23
|
-
if (
|
|
23
|
+
if (noMarkups) {
|
|
24
24
|
return {
|
|
25
25
|
conversionRate,
|
|
26
|
-
conversionRateWithVolatilityMarkup: conversionRate,
|
|
27
|
-
conversionRateWithRioMarkup: conversionRate,
|
|
28
|
-
conversionRateWithAllMarkups: conversionRate,
|
|
29
26
|
};
|
|
30
27
|
}
|
|
28
|
+
let conversionRateWithMarkups = conversionRate;
|
|
29
|
+
// Time based markups
|
|
30
|
+
if (from === common_1.Fiat.PEN || to === common_1.Fiat.PEN) {
|
|
31
|
+
const now = new Date();
|
|
32
|
+
const peruTime = new Date(now.toLocaleString("en-US", { timeZone: "America/Lima" }));
|
|
33
|
+
const hours = peruTime.getHours();
|
|
34
|
+
const minutes = peruTime.getMinutes();
|
|
35
|
+
// Check if it's between 2:10 PM and 12:00 AM
|
|
36
|
+
if ((hours === 14 && minutes >= 10) || hours > 14 || hours === 0) {
|
|
37
|
+
conversionRateWithMarkups = conversionRate * 0.997;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if ((from === common_1.Fiat.MXN && to === common_1.Fiat.USD) ||
|
|
41
|
+
(from === common_1.Fiat.USD && to === common_1.Fiat.MXN)) {
|
|
42
|
+
const now = new Date();
|
|
43
|
+
const mexicoCityTime = new Date(now.toLocaleString("en-US", { timeZone: "America/Mexico_City" }));
|
|
44
|
+
const hours = mexicoCityTime.getHours();
|
|
45
|
+
const minutes = mexicoCityTime.getMinutes();
|
|
46
|
+
// Check if it's between 2:30 PM and 6:00 PM
|
|
47
|
+
if ((hours === 14 && minutes >= 30) ||
|
|
48
|
+
(hours > 14 && hours < 18) ||
|
|
49
|
+
(hours === 18 && minutes === 0)) {
|
|
50
|
+
conversionRateWithMarkups = conversionRate * 0.997;
|
|
51
|
+
}
|
|
52
|
+
else if (hours >= 0 && hours < 8) {
|
|
53
|
+
conversionRateWithMarkups = conversionRate * 0.996;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let safestPrice = conversionRateWithMarkups;
|
|
57
|
+
// Volatility based markups
|
|
31
58
|
const { startDate, endDate } = getDateRange();
|
|
32
59
|
const data = yield currencyAPIClient.getHistoricalExchangeRates(from, to, startDate.toISOString(), endDate.toISOString());
|
|
33
60
|
const values = data.map((point) => point.currencies[to].value);
|
|
@@ -37,33 +64,14 @@ const getExchangeRates = (from, to, volatilitySafeguard) => __awaiter(void 0, vo
|
|
|
37
64
|
values.length;
|
|
38
65
|
const volatility = Math.sqrt(variance);
|
|
39
66
|
const maximumPriceChange = volatility * QUOTE_DURATION_MINUTES;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let exchangeRateMultiplier = 0.9997;
|
|
43
|
-
|
|
44
|
-
exchangeRateMultiplier = 0.9987;
|
|
45
|
-
}
|
|
46
|
-
if (from === common_1.Fiat.PEN || to === common_1.Fiat.PEN) {
|
|
47
|
-
const now = new Date();
|
|
48
|
-
const peruTimezoneOffset = -5; // Peru is in the UTC-5 time zone
|
|
49
|
-
const peruTime = new Date(now.getTime() + peruTimezoneOffset * 60 * 60 * 1000);
|
|
50
|
-
const isPastSixPmInPeru = peruTime.getHours() >= 18;
|
|
51
|
-
if (isPastSixPmInPeru) {
|
|
52
|
-
exchangeRateMultiplier = 0.997;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (from === common_1.Fiat.USD) {
|
|
56
|
-
exchangeRateMultiplier = 0.999;
|
|
57
|
-
}
|
|
58
|
-
const conversionRateWithRioMarkup = to === from ? conversionRate : conversionRate * exchangeRateMultiplier;
|
|
59
|
-
const conversionRateWithAllMarkups = to === from
|
|
60
|
-
? conversionRateWithVolatilityMarkup
|
|
61
|
-
: conversionRateWithVolatilityMarkup * exchangeRateMultiplier;
|
|
67
|
+
safestPrice = safestPrice - maximumPriceChange;
|
|
68
|
+
// Bank based markups
|
|
69
|
+
let exchangeRateMultiplier = from === common_1.Fiat.PEN ? 0.9987 : 0.9997;
|
|
70
|
+
safestPrice = safestPrice * exchangeRateMultiplier;
|
|
62
71
|
return {
|
|
63
72
|
conversionRate,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
conversionRateWithAllMarkups,
|
|
73
|
+
conversionRateWithMarkups,
|
|
74
|
+
safestPrice,
|
|
67
75
|
};
|
|
68
76
|
});
|
|
69
77
|
exports.getExchangeRates = getExchangeRates;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1032",
|
|
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.889",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|