@riocrypto/common-server 1.0.832 → 1.0.833
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.
- package/build/helpers/calculate-weekly-volume-and-revenue.d.ts +6 -0
- package/build/helpers/calculate-weekly-volume-and-revenue.js +72 -0
- package/build/helpers/get-platform-and-partner-fees.js +3 -3
- package/build/index.d.ts +2 -1
- package/build/index.js +2 -1
- package/package.json +1 -1
- /package/build/helpers/{calculate-aggregate-volume.d.ts → calculate-aggregate-volume-and-revenue.d.ts} +0 -0
- /package/build/helpers/{calculate-aggregate-volume.js → calculate-aggregate-volume-and-revenue.js} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.calculateWeeklyVolumeAndRevenue = void 0;
|
|
13
|
+
const common_1 = require("@riocrypto/common");
|
|
14
|
+
const order_1 = require("../models/order");
|
|
15
|
+
const calculateWeeklyVolumeAndRevenue = (mongoose, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
17
|
+
const startDate = new Date();
|
|
18
|
+
startDate.setDate(startDate.getDate() - ((startDate.getDay() + 6) % 7));
|
|
19
|
+
startDate.setHours(12, 0, 0, 0);
|
|
20
|
+
const Order = (0, order_1.buildOrder)(mongoose);
|
|
21
|
+
let orders;
|
|
22
|
+
if (user) {
|
|
23
|
+
if ((_a = user.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.broker)) {
|
|
24
|
+
orders = yield Order.find({
|
|
25
|
+
$or: [{ userId: user.id }, { brokerId: user.id }],
|
|
26
|
+
status: common_1.OrderStatus.Complete,
|
|
27
|
+
createdAt: { $gte: startDate },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
orders = yield Order.find({
|
|
32
|
+
userId: user.id,
|
|
33
|
+
status: common_1.OrderStatus.Complete,
|
|
34
|
+
createdAt: { $gte: startDate },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
orders = yield Order.find({
|
|
40
|
+
status: common_1.OrderStatus.Complete,
|
|
41
|
+
createdAt: { $gte: startDate },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
let volume = 0;
|
|
45
|
+
let revenue = 0;
|
|
46
|
+
orders.forEach((order) => {
|
|
47
|
+
var _a;
|
|
48
|
+
const fiatAmount = order.amountFiat || 0;
|
|
49
|
+
const conversionRate = order.conversionRateUSD;
|
|
50
|
+
const platformFee = ((_a = order.fees) === null || _a === void 0 ? void 0 : _a.platformFeeFiat) || 0;
|
|
51
|
+
const price = order.price || 0;
|
|
52
|
+
const amountCrypto = order.amountCrypto || 0;
|
|
53
|
+
let orderVolume = 0;
|
|
54
|
+
let orderRevenue = 0;
|
|
55
|
+
if (order.side === common_1.Side.Sell) {
|
|
56
|
+
orderVolume = conversionRate
|
|
57
|
+
? amountCrypto * price * (1 / conversionRate)
|
|
58
|
+
: 0;
|
|
59
|
+
orderRevenue = conversionRate ? platformFee * (1 / conversionRate) : 0;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
orderVolume = conversionRate ? fiatAmount * conversionRate : 0;
|
|
63
|
+
orderRevenue += conversionRate ? platformFee * conversionRate : 0;
|
|
64
|
+
}
|
|
65
|
+
volume += orderVolume;
|
|
66
|
+
revenue += orderRevenue;
|
|
67
|
+
});
|
|
68
|
+
const volumeResult = volume || 0;
|
|
69
|
+
const revenueResult = revenue || 0;
|
|
70
|
+
return { volume: volumeResult, revenue: revenueResult };
|
|
71
|
+
});
|
|
72
|
+
exports.calculateWeeklyVolumeAndRevenue = calculateWeeklyVolumeAndRevenue;
|
|
@@ -14,7 +14,7 @@ const rio_settings_1 = require("../models/rio-settings");
|
|
|
14
14
|
const common_1 = require("@riocrypto/common");
|
|
15
15
|
const partner_1 = require("../models/partner");
|
|
16
16
|
const user_1 = require("../models/user");
|
|
17
|
-
const
|
|
17
|
+
const calculate_aggregate_volume_and_revenue_1 = require("./calculate-aggregate-volume-and-revenue");
|
|
18
18
|
const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fiat, processor, country, partnerId, brokerId, user, markup, discount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
var _a, _b;
|
|
20
20
|
let platformFeeFiat;
|
|
@@ -64,7 +64,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
|
|
|
64
64
|
}
|
|
65
65
|
let volume;
|
|
66
66
|
if ((_a = broker.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
67
|
-
const volumeAndRevenue = yield (0,
|
|
67
|
+
const volumeAndRevenue = yield (0, calculate_aggregate_volume_and_revenue_1.calculateAggregateVolumeAndRevenue)(mongoose, 14, user);
|
|
68
68
|
volume = volumeAndRevenue.volume;
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
@@ -97,7 +97,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
|
|
|
97
97
|
else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
|
|
98
98
|
let volume;
|
|
99
99
|
if ((_b = user === null || user === void 0 ? void 0 : user.attributes) === null || _b === void 0 ? void 0 : _b.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
100
|
-
const volumeAndRevenue = yield (0,
|
|
100
|
+
const volumeAndRevenue = yield (0, calculate_aggregate_volume_and_revenue_1.calculateAggregateVolumeAndRevenue)(mongoose, 14, user);
|
|
101
101
|
volume = volumeAndRevenue.volume;
|
|
102
102
|
}
|
|
103
103
|
else {
|
package/build/index.d.ts
CHANGED
|
@@ -46,5 +46,6 @@ export * from "./helpers/get-user-helper";
|
|
|
46
46
|
export * from "./helpers/get-platform-and-partner-fees";
|
|
47
47
|
export * from "./helpers/get-processor-fees";
|
|
48
48
|
export * from "./helpers/get-network-fees";
|
|
49
|
-
export * from "./helpers/calculate-aggregate-volume";
|
|
49
|
+
export * from "./helpers/calculate-aggregate-volume-and-revenue";
|
|
50
|
+
export * from "./helpers/calculate-weekly-volume-and-revenue";
|
|
50
51
|
export * from "./helpers/get-exchange-rates";
|
package/build/index.js
CHANGED
|
@@ -62,5 +62,6 @@ __exportStar(require("./helpers/get-user-helper"), exports);
|
|
|
62
62
|
__exportStar(require("./helpers/get-platform-and-partner-fees"), exports);
|
|
63
63
|
__exportStar(require("./helpers/get-processor-fees"), exports);
|
|
64
64
|
__exportStar(require("./helpers/get-network-fees"), exports);
|
|
65
|
-
__exportStar(require("./helpers/calculate-aggregate-volume"), exports);
|
|
65
|
+
__exportStar(require("./helpers/calculate-aggregate-volume-and-revenue"), exports);
|
|
66
|
+
__exportStar(require("./helpers/calculate-weekly-volume-and-revenue"), exports);
|
|
66
67
|
__exportStar(require("./helpers/get-exchange-rates"), exports);
|
package/package.json
CHANGED
|
File without changes
|
/package/build/helpers/{calculate-aggregate-volume.js → calculate-aggregate-volume-and-revenue.js}
RENAMED
|
File without changes
|