@riocrypto/common-server 1.0.795 → 1.0.798

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.
@@ -17,43 +17,20 @@ const QUOTE_DURATION_MINUTES = 10;
17
17
  const getExchangeRates = (from, to) => __awaiter(void 0, void 0, void 0, function* () {
18
18
  const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
19
19
  const { startDate, endDate } = getDateRange();
20
- console.log("from ", from);
21
- console.log("to ", to);
22
- console.log("Startdate ", startDate.toISOString());
23
- console.log("enddate ", endDate.toISOString());
24
20
  const data = yield currencyAPIClient.getHistoricalExchangeRates(from, to, startDate.toISOString(), endDate.toISOString());
25
- console.log("data ", data);
26
21
  const values = data.map((point) => point.currencies[to].value);
27
22
  const average = values.reduce((sum, value) => sum + value, 0) / values.length;
28
23
  const squaredDeviations = values.map((value) => (value - average) ** 2);
29
24
  const variance = squaredDeviations.reduce((sum, deviation) => sum + deviation, 0) /
30
25
  values.length;
31
26
  const volatility = Math.sqrt(variance);
32
- const currentPrice = values[values.length - 1];
33
- const previousPrice = values[values.length - 2];
34
- const priceChange = currentPrice - previousPrice;
35
- let priceDirection;
36
- if (Math.abs(priceChange) > volatility) {
37
- priceDirection = priceChange > 0 ? "increase" : "decrease";
38
- }
39
- else {
40
- priceDirection = "stable";
41
- }
42
27
  const maximumPriceChange = volatility * QUOTE_DURATION_MINUTES;
43
28
  const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
44
29
  const conversionRate = to === common_1.Fiat.BRL
45
30
  ? yield kapstarClient.getBRLExchangeRateUSD()
46
31
  : yield currencyAPIClient.convert(from, to);
47
32
  let conversionRateWithVolatilityMarkup;
48
- if (priceDirection === "increase") {
49
- conversionRateWithVolatilityMarkup = conversionRate + maximumPriceChange;
50
- }
51
- else if (priceDirection === "decrease") {
52
- conversionRateWithVolatilityMarkup = conversionRate - maximumPriceChange;
53
- }
54
- else {
55
- conversionRateWithVolatilityMarkup = conversionRate;
56
- }
33
+ conversionRateWithVolatilityMarkup = conversionRate + maximumPriceChange;
57
34
  let exchangeRateMultiplier = 0.999;
58
35
  if (from === common_1.Fiat.PEN || to === common_1.Fiat.PEN) {
59
36
  const now = new Date();
package/build/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export * from "./models/checked-address";
28
28
  export * from "./models/rio-settings";
29
29
  export * from "./models/partner-auth";
30
30
  export * from "./models/bank-account";
31
+ export * from "./models/quote";
31
32
  export * from "./clients/bitstamp-client";
32
33
  export * from "./clients/ccxt-client";
33
34
  export * from "./clients/kushki-client";
@@ -46,4 +47,4 @@ export * from "./helpers/get-platform-and-partner-fees";
46
47
  export * from "./helpers/get-processor-fees";
47
48
  export * from "./helpers/get-network-fees";
48
49
  export * from "./helpers/calculate-aggregate-volume";
49
- export * from "./helpers/getExchangeRates";
50
+ export * from "./helpers/get-exchange-rates";
package/build/index.js CHANGED
@@ -44,6 +44,7 @@ __exportStar(require("./models/checked-address"), exports);
44
44
  __exportStar(require("./models/rio-settings"), exports);
45
45
  __exportStar(require("./models/partner-auth"), exports);
46
46
  __exportStar(require("./models/bank-account"), exports);
47
+ __exportStar(require("./models/quote"), exports);
47
48
  __exportStar(require("./clients/bitstamp-client"), exports);
48
49
  __exportStar(require("./clients/ccxt-client"), exports);
49
50
  __exportStar(require("./clients/kushki-client"), exports);
@@ -62,4 +63,4 @@ __exportStar(require("./helpers/get-platform-and-partner-fees"), exports);
62
63
  __exportStar(require("./helpers/get-processor-fees"), exports);
63
64
  __exportStar(require("./helpers/get-network-fees"), exports);
64
65
  __exportStar(require("./helpers/calculate-aggregate-volume"), exports);
65
- __exportStar(require("./helpers/getExchangeRates"), exports);
66
+ __exportStar(require("./helpers/get-exchange-rates"), exports);
@@ -0,0 +1,57 @@
1
+ import { Country, Fees, Fiat, LiquidityProvider, PaymentMethod, PayoutMethod, Processor, Side, USState, Crypto } from "@riocrypto/common";
2
+ import { Mongoose, Model, Document } from "mongoose";
3
+ interface QuoteAttrs {
4
+ userId: string;
5
+ crypto: Crypto;
6
+ side: Side;
7
+ fiat: Fiat;
8
+ paymentMethod?: PaymentMethod;
9
+ payoutMethod?: PayoutMethod;
10
+ expiresAt: Date;
11
+ country: Country;
12
+ state: USState | string;
13
+ cryptoAddress: string;
14
+ amountFiat?: number;
15
+ amountCrypto?: number;
16
+ liquidityProvider: LiquidityProvider;
17
+ processor: Processor;
18
+ fees: Fees;
19
+ price: number;
20
+ partnerId?: string;
21
+ depositAddress?: string;
22
+ brokerId?: string;
23
+ conversionRateUSD?: number;
24
+ conversionRateUSDWithMarkups?: number;
25
+ discount?: number;
26
+ markup?: number;
27
+ }
28
+ interface QuoteDoc extends Document {
29
+ userId: string;
30
+ crypto: Crypto;
31
+ side: Side;
32
+ fiat: Fiat;
33
+ paymentMethod?: PaymentMethod;
34
+ payoutMethod?: PayoutMethod;
35
+ expiresAt: Date;
36
+ country: Country;
37
+ state: USState | string;
38
+ cryptoAddress: string;
39
+ amountFiat?: number;
40
+ amountCrypto?: number;
41
+ liquidityProvider: LiquidityProvider;
42
+ processor: Processor;
43
+ fees: Fees;
44
+ price: number;
45
+ partnerId?: string;
46
+ depositAddress?: string;
47
+ brokerId?: string;
48
+ conversionRateUSD?: number;
49
+ conversionRateUSDWithMarkups?: number;
50
+ discount?: number;
51
+ markup?: number;
52
+ }
53
+ interface QuoteModel extends Model<QuoteDoc> {
54
+ build(attrs: QuoteAttrs): QuoteDoc;
55
+ }
56
+ declare const buildQuote: (mongoose: Mongoose) => QuoteModel;
57
+ export { buildQuote, QuoteDoc };
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildQuote = void 0;
4
+ const buildQuote = (mongoose) => {
5
+ // if model is already defined, return it
6
+ if (mongoose.models.Quote) {
7
+ return mongoose.model("Quote");
8
+ }
9
+ const quoteSchema = new mongoose.Schema({
10
+ userId: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ status: {
15
+ type: String,
16
+ required: true,
17
+ },
18
+ crypto: {
19
+ type: String,
20
+ required: true,
21
+ },
22
+ side: {
23
+ type: String,
24
+ required: true,
25
+ },
26
+ fiat: {
27
+ type: String,
28
+ required: true,
29
+ },
30
+ paymentMethod: {
31
+ type: String,
32
+ },
33
+ payoutMethod: {
34
+ type: String,
35
+ },
36
+ expiresAt: {
37
+ type: mongoose.Schema.Types.Date,
38
+ required: true,
39
+ },
40
+ cryptoAddress: {
41
+ type: String,
42
+ required: true,
43
+ },
44
+ country: {
45
+ type: String,
46
+ required: true,
47
+ },
48
+ state: {
49
+ type: String,
50
+ },
51
+ amountFiat: {
52
+ type: Number,
53
+ },
54
+ amountCrypto: {
55
+ type: Number,
56
+ },
57
+ processor: {
58
+ type: String,
59
+ required: true,
60
+ },
61
+ liquidityProvider: {
62
+ type: String,
63
+ required: true,
64
+ },
65
+ depositAddress: {
66
+ type: String,
67
+ },
68
+ fees: {
69
+ processingFeeFiat: {
70
+ type: Number,
71
+ },
72
+ transferFeeFiat: {
73
+ type: Number,
74
+ },
75
+ platformFeeFiat: {
76
+ type: Number,
77
+ },
78
+ partnerFeeFiat: {
79
+ type: Number,
80
+ },
81
+ platformFeeFiatTax: {
82
+ type: Number,
83
+ },
84
+ },
85
+ price: {
86
+ type: Number,
87
+ },
88
+ partnerId: {
89
+ type: String,
90
+ },
91
+ brokerId: {
92
+ type: String,
93
+ },
94
+ conversionRateUSD: {
95
+ type: Number,
96
+ },
97
+ conversionRateUSDWithMarkups: {
98
+ type: Number,
99
+ },
100
+ discount: {
101
+ type: Number,
102
+ },
103
+ markup: {
104
+ type: Number,
105
+ },
106
+ }, {
107
+ toJSON: {
108
+ transform(doc, ret) {
109
+ ret.id = ret._id.valueOf();
110
+ delete ret._id;
111
+ delete ret.__v;
112
+ },
113
+ },
114
+ });
115
+ quoteSchema.statics.build = (attrs) => {
116
+ return new Quote(attrs);
117
+ };
118
+ const Quote = mongoose.model("Quote", quoteSchema);
119
+ return Quote;
120
+ };
121
+ exports.buildQuote = buildQuote;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.795",
3
+ "version": "1.0.798",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",