@riocrypto/common 1.0.437 → 1.0.440
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,8 +1,9 @@
|
|
|
1
1
|
import { CCXTLiquidityProvider } from "../types/ccxt-liquidity-provider";
|
|
2
2
|
import { Fiat } from "../types/fiat";
|
|
3
3
|
import { Side } from "../types/side";
|
|
4
|
-
declare class
|
|
5
|
-
|
|
4
|
+
export declare class ccxtClient {
|
|
5
|
+
private env;
|
|
6
|
+
constructor(env: "production" | "development");
|
|
6
7
|
createBuyOrder(amount: number, crypto: Crypto, fiat: Fiat, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<{
|
|
7
8
|
ccxtId: any;
|
|
8
9
|
price: any;
|
|
@@ -34,5 +35,3 @@ declare class CCXTWrapper {
|
|
|
34
35
|
private round;
|
|
35
36
|
private getExchange;
|
|
36
37
|
}
|
|
37
|
-
export declare const ccxtWrapper: CCXTWrapper;
|
|
38
|
-
export {};
|
|
@@ -12,52 +12,81 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.ccxtClient = void 0;
|
|
16
16
|
const ccxt_1 = __importDefault(require("ccxt"));
|
|
17
17
|
const ccxt_liquidity_provider_1 = require("../types/ccxt-liquidity-provider");
|
|
18
18
|
const side_1 = require("../types/side");
|
|
19
|
-
class
|
|
20
|
-
constructor() {
|
|
19
|
+
class ccxtClient {
|
|
20
|
+
constructor(env) {
|
|
21
|
+
this.env = env;
|
|
22
|
+
}
|
|
21
23
|
createBuyOrder(amount, crypto, fiat, ccxtLiquidityProvider) {
|
|
22
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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: side_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: side_1.Side.Buy,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
34
49
|
});
|
|
35
50
|
}
|
|
36
51
|
createSellOrder(amount, crypto, fiat, ccxtLiquidityProvider) {
|
|
37
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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: side_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: side_1.Side.Sell,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
50
77
|
});
|
|
51
78
|
}
|
|
52
79
|
transfer(side, amount, crypto, cryptoAddress, ccxtLiquidityProvider) {
|
|
53
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
if (this.env === "production") {
|
|
82
|
+
const exchange = yield this.getExchange(ccxtLiquidityProvider);
|
|
83
|
+
const params = ccxtLiquidityProvider === ccxt_liquidity_provider_1.CCXTLiquidityProvider.Kraken
|
|
84
|
+
? {
|
|
85
|
+
key: "Metamask",
|
|
86
|
+
}
|
|
87
|
+
: undefined;
|
|
88
|
+
yield exchange.withdraw(crypto, this.round(amount, 8), cryptoAddress, undefined, params);
|
|
89
|
+
}
|
|
61
90
|
});
|
|
62
91
|
}
|
|
63
92
|
getBuyQuote(amount, crypto, fiat) {
|
|
@@ -114,4 +143,4 @@ class CCXTWrapper {
|
|
|
114
143
|
});
|
|
115
144
|
}
|
|
116
145
|
}
|
|
117
|
-
exports.
|
|
146
|
+
exports.ccxtClient = ccxtClient;
|
package/build/index.d.ts
CHANGED
|
@@ -157,5 +157,5 @@ export * from "./models/partner";
|
|
|
157
157
|
export * from "./models/user";
|
|
158
158
|
export * from "./models/ccxt-order";
|
|
159
159
|
export * from "./clients/bitstamp-client";
|
|
160
|
-
export * from "./clients/ccxt-
|
|
160
|
+
export * from "./clients/ccxt-client";
|
|
161
161
|
export * from "./clients/fixer-client";
|
package/build/index.js
CHANGED
|
@@ -174,5 +174,5 @@ __exportStar(require("./models/partner"), exports);
|
|
|
174
174
|
__exportStar(require("./models/user"), exports);
|
|
175
175
|
__exportStar(require("./models/ccxt-order"), exports);
|
|
176
176
|
__exportStar(require("./clients/bitstamp-client"), exports);
|
|
177
|
-
__exportStar(require("./clients/ccxt-
|
|
177
|
+
__exportStar(require("./clients/ccxt-client"), exports);
|
|
178
178
|
__exportStar(require("./clients/fixer-client"), exports);
|