@riocrypto/common-server 1.0.714 → 1.0.715
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,2 +1,3 @@
|
|
|
1
1
|
import { User } from "@riocrypto/common";
|
|
2
|
-
|
|
2
|
+
import { Mongoose } from "mongoose";
|
|
3
|
+
export declare const calculateAggregateVolume: (mongoose: Mongoose, user: User, days: number) => Promise<number>;
|
|
@@ -8,47 +8,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.calculateAggregateVolume = void 0;
|
|
16
13
|
const common_1 = require("@riocrypto/common");
|
|
17
14
|
const order_1 = require("../models/order");
|
|
18
|
-
const
|
|
19
|
-
const calculateAggregateVolume = (user, days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
let volume;
|
|
15
|
+
const calculateAggregateVolume = (mongoose, user, days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
16
|
const startDate = new Date();
|
|
22
17
|
startDate.setDate(startDate.getDate() - days); // Subtract 14 days from current date
|
|
23
|
-
const Order = (0, order_1.buildOrder)(
|
|
24
|
-
const
|
|
25
|
-
userId: user.id,
|
|
26
|
-
type: common_1.Side.Buy,
|
|
27
|
-
status: common_1.OrderStatus.Complete,
|
|
28
|
-
createdAt: { $gte: startDate },
|
|
29
|
-
});
|
|
30
|
-
const sellOrders = yield Order.find({
|
|
18
|
+
const Order = (0, order_1.buildOrder)(mongoose);
|
|
19
|
+
const orders = yield Order.find({
|
|
31
20
|
userId: user.id,
|
|
32
|
-
type: common_1.Side.Sell,
|
|
33
21
|
status: common_1.OrderStatus.Complete,
|
|
34
22
|
createdAt: { $gte: startDate },
|
|
35
23
|
});
|
|
36
|
-
volume =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
24
|
+
const volume = orders.reduce((sum, order) => {
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
const fiatAmount = order.amountFiat || 0;
|
|
27
|
+
const conversionRate = order.conversionRateToUSD || 0;
|
|
28
|
+
const partnerFee = ((_a = order.fees) === null || _a === void 0 ? void 0 : _a.partnerFeeFiat) || 0;
|
|
29
|
+
const platformFee = ((_b = order.fees) === null || _b === void 0 ? void 0 : _b.platformFeeFiat) || 0;
|
|
30
|
+
const platformTax = ((_c = order.fees) === null || _c === void 0 ? void 0 : _c.platformFeeFiatTax) || 0;
|
|
31
|
+
const processingFee = ((_d = order.fees) === null || _d === void 0 ? void 0 : _d.processingFeeFiat) || 0;
|
|
32
|
+
const transferFee = ((_e = order.fees) === null || _e === void 0 ? void 0 : _e.transferFeeFiat) || 0;
|
|
33
|
+
const sellVolume = (fiatAmount +
|
|
34
|
+
partnerFee +
|
|
35
|
+
platformFee +
|
|
36
|
+
platformTax +
|
|
37
|
+
processingFee +
|
|
38
|
+
transferFee) *
|
|
39
|
+
conversionRate;
|
|
40
|
+
const buyVolume = fiatAmount * conversionRate;
|
|
41
|
+
return sum + sellVolume + buyVolume;
|
|
42
|
+
}, 0);
|
|
43
|
+
const volumeResult = volume || 0;
|
|
44
|
+
return volumeResult;
|
|
53
45
|
});
|
|
54
46
|
exports.calculateAggregateVolume = calculateAggregateVolume;
|
|
@@ -60,7 +60,7 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
|
|
|
60
60
|
else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
|
|
61
61
|
let volume;
|
|
62
62
|
if ((_a = user === null || user === void 0 ? void 0 : user.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
63
|
-
volume = yield (0, calculate_aggregate_volume_1.calculateAggregateVolume)(user, 14);
|
|
63
|
+
volume = yield (0, calculate_aggregate_volume_1.calculateAggregateVolume)(mongoose, user, 14);
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
66
|
volume = Number(amountUSD);
|