@riocrypto/common-server 1.0.998 → 1.0.1002
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,26 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fiat, Side, Crypto } from "@riocrypto/common";
|
|
2
2
|
declare class CCXTClient {
|
|
3
3
|
private env;
|
|
4
4
|
constructor(env: "production" | "development");
|
|
5
|
-
createBuyOrder(amount: number, crypto: Crypto, fiat: Fiat, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<{
|
|
6
|
-
ccxtId: any;
|
|
7
|
-
price: any;
|
|
8
|
-
amountCrypto: any;
|
|
9
|
-
amountFiat: number;
|
|
10
|
-
crypto: Crypto;
|
|
11
|
-
fiat: Fiat;
|
|
12
|
-
side: Side;
|
|
13
|
-
}>;
|
|
14
|
-
createSellOrder(amount: number, crypto: Crypto, fiat: Fiat, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<{
|
|
15
|
-
ccxtId: any;
|
|
16
|
-
price: any;
|
|
17
|
-
amountCrypto: number;
|
|
18
|
-
amountFiat: number;
|
|
19
|
-
crypto: Crypto;
|
|
20
|
-
fiat: Fiat;
|
|
21
|
-
side: Side;
|
|
22
|
-
}>;
|
|
23
|
-
transfer(side: Side, amount: number, crypto: Crypto, cryptoAddress: string, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<void>;
|
|
24
5
|
getBuyQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
|
|
25
6
|
price: number;
|
|
26
7
|
amountCrypto: number | undefined;
|
|
@@ -31,7 +12,6 @@ declare class CCXTClient {
|
|
|
31
12
|
}>;
|
|
32
13
|
private getOptimalExchange;
|
|
33
14
|
private round;
|
|
34
|
-
private getExchange;
|
|
35
15
|
getSellQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
|
|
36
16
|
price: number;
|
|
37
17
|
amountCrypto: number;
|
|
@@ -20,75 +20,6 @@ class CCXTClient {
|
|
|
20
20
|
constructor(env) {
|
|
21
21
|
this.env = env;
|
|
22
22
|
}
|
|
23
|
-
createBuyOrder(amount, crypto, fiat, ccxtLiquidityProvider) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
if (this.env === "production") {
|
|
26
|
-
const exchange = yield this.getExchange(ccxtLiquidityProvider);
|
|
27
|
-
const order = yield exchange.createOrder(`${crypto}/${fiat}`, "market", "buy", amount);
|
|
28
|
-
return {
|
|
29
|
-
ccxtId: order.id,
|
|
30
|
-
price: order.price,
|
|
31
|
-
amountCrypto: order.amount,
|
|
32
|
-
amountFiat: amount,
|
|
33
|
-
crypto,
|
|
34
|
-
fiat,
|
|
35
|
-
side: common_1.Side.Buy,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return {
|
|
40
|
-
ccxtId: "1",
|
|
41
|
-
price: 1,
|
|
42
|
-
amountCrypto: amount,
|
|
43
|
-
amountFiat: amount,
|
|
44
|
-
crypto,
|
|
45
|
-
fiat,
|
|
46
|
-
side: common_1.Side.Buy,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
createSellOrder(amount, crypto, fiat, ccxtLiquidityProvider) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
if (this.env === "production") {
|
|
54
|
-
const exchange = yield this.getExchange(ccxtLiquidityProvider);
|
|
55
|
-
const order = yield exchange.createOrder(`${crypto}/${fiat}`, "market", "sell", amount);
|
|
56
|
-
return {
|
|
57
|
-
ccxtId: order.id,
|
|
58
|
-
price: order.price,
|
|
59
|
-
amountCrypto: amount,
|
|
60
|
-
amountFiat: order.amount * order.price,
|
|
61
|
-
crypto,
|
|
62
|
-
fiat,
|
|
63
|
-
side: common_1.Side.Sell,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return {
|
|
68
|
-
ccxtId: "1",
|
|
69
|
-
price: 1,
|
|
70
|
-
amountCrypto: amount,
|
|
71
|
-
amountFiat: amount,
|
|
72
|
-
crypto,
|
|
73
|
-
fiat,
|
|
74
|
-
side: common_1.Side.Sell,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
transfer(side, amount, crypto, cryptoAddress, ccxtLiquidityProvider) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
if (this.env === "production") {
|
|
82
|
-
const exchange = yield this.getExchange(ccxtLiquidityProvider);
|
|
83
|
-
const params = ccxtLiquidityProvider === common_1.CCXTLiquidityProvider.Kraken
|
|
84
|
-
? {
|
|
85
|
-
key: "Metamask",
|
|
86
|
-
}
|
|
87
|
-
: undefined;
|
|
88
|
-
yield exchange.withdraw(crypto, this.round(amount, 8), cryptoAddress, undefined, params);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
23
|
getBuyQuote(crypto, fiat, amountFiat, amountCrypto) {
|
|
93
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
25
|
if (this.env === "production") {
|
|
@@ -171,24 +102,6 @@ class CCXTClient {
|
|
|
171
102
|
return Math.round(value);
|
|
172
103
|
}
|
|
173
104
|
}
|
|
174
|
-
getExchange(ccxtLiquidityProvider) {
|
|
175
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue(`${ccxtLiquidityProvider.toLocaleUpperCase()}_SECRET`);
|
|
177
|
-
if (!SECRET) {
|
|
178
|
-
throw new Error("Unable to get SECRET");
|
|
179
|
-
}
|
|
180
|
-
const API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue(`${ccxtLiquidityProvider.toLocaleUpperCase()}_API_KEY`);
|
|
181
|
-
if (!API_KEY) {
|
|
182
|
-
throw new Error("Unable to get API_KEY");
|
|
183
|
-
}
|
|
184
|
-
// @ts-ignore
|
|
185
|
-
const exchangeClass = ccxt_1.default[ccxtLiquidityProvider], exchange = new exchangeClass({
|
|
186
|
-
apiKey: API_KEY,
|
|
187
|
-
secret: SECRET,
|
|
188
|
-
});
|
|
189
|
-
return exchange;
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
105
|
getSellQuote(crypto, fiat, amountFiat, amountCrypto) {
|
|
193
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
107
|
if (amountFiat && amountCrypto) {
|
package/build/models/order.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1002",
|
|
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.866",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|