@riocrypto/common-server 1.0.787 → 1.0.789
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const calculateExchangeRateWithVolatilityMarkup: (conversionRateFromUSD: number, volatility: number, riskFactor: number, priceDirection: "increase" | "decrease" | "stable") => number;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
3
|
+
exports.calculateExchangeRateWithVolatilityMarkup = void 0;
|
|
4
|
+
const calculateExchangeRateWithVolatilityMarkup = (conversionRateFromUSD, volatility, riskFactor, priceDirection) => {
|
|
5
|
+
const maximumPriceChange = volatility * riskFactor;
|
|
6
|
+
let priceWithMarkup;
|
|
7
|
+
if (priceDirection === "increase") {
|
|
8
|
+
priceWithMarkup = conversionRateFromUSD + maximumPriceChange;
|
|
9
|
+
}
|
|
10
|
+
else if (priceDirection === "decrease") {
|
|
11
|
+
priceWithMarkup = conversionRateFromUSD - maximumPriceChange;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
priceWithMarkup = conversionRateFromUSD;
|
|
15
|
+
}
|
|
16
|
+
return priceWithMarkup;
|
|
7
17
|
};
|
|
8
|
-
exports.
|
|
18
|
+
exports.calculateExchangeRateWithVolatilityMarkup = calculateExchangeRateWithVolatilityMarkup;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { Fiat } from "@riocrypto/common";
|
|
2
|
-
|
|
2
|
+
interface VolatilityResult {
|
|
3
|
+
volatility: number;
|
|
4
|
+
priceDirection: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const calculateVolatility: (from: Fiat, to: Fiat, start: Date, end: Date) => Promise<VolatilityResult>;
|
|
7
|
+
export {};
|
|
@@ -20,6 +20,19 @@ const calculateVolatility = (from, to, start, end) => __awaiter(void 0, void 0,
|
|
|
20
20
|
const variance = squaredDeviations.reduce((sum, deviation) => sum + deviation, 0) /
|
|
21
21
|
values.length;
|
|
22
22
|
const volatility = Math.sqrt(variance);
|
|
23
|
-
|
|
23
|
+
const currentPrice = values[values.length - 1];
|
|
24
|
+
const previousPrice = values[values.length - 2];
|
|
25
|
+
const priceChange = currentPrice - previousPrice;
|
|
26
|
+
let priceDirection;
|
|
27
|
+
if (Math.abs(priceChange) > volatility) {
|
|
28
|
+
priceDirection = priceChange > 0 ? "increase" : "decrease";
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
priceDirection = "stable";
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
volatility,
|
|
35
|
+
priceDirection,
|
|
36
|
+
};
|
|
24
37
|
});
|
|
25
38
|
exports.calculateVolatility = calculateVolatility;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.789",
|
|
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.690",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|