@riocrypto/common-server 1.0.663 → 1.0.666
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.
|
@@ -21,10 +21,10 @@ declare class CCXTClient {
|
|
|
21
21
|
side: Side;
|
|
22
22
|
}>;
|
|
23
23
|
transfer(side: Side, amount: number, crypto: Crypto, cryptoAddress: string, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<void>;
|
|
24
|
-
getBuyQuote(
|
|
24
|
+
getBuyQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
|
|
25
25
|
price: number;
|
|
26
|
-
amountCrypto: number;
|
|
27
|
-
amountFiat: number;
|
|
26
|
+
amountCrypto: number | undefined;
|
|
27
|
+
amountFiat: number | undefined;
|
|
28
28
|
crypto: Crypto;
|
|
29
29
|
fiat: Fiat;
|
|
30
30
|
side: Side;
|
|
@@ -32,10 +32,10 @@ declare class CCXTClient {
|
|
|
32
32
|
private getOptimalExchange;
|
|
33
33
|
private round;
|
|
34
34
|
private getExchange;
|
|
35
|
-
getSellQuote(
|
|
35
|
+
getSellQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
|
|
36
36
|
price: number;
|
|
37
37
|
amountCrypto: number;
|
|
38
|
-
amountFiat: number;
|
|
38
|
+
amountFiat: number | undefined;
|
|
39
39
|
crypto: Crypto;
|
|
40
40
|
fiat: Fiat;
|
|
41
41
|
}>;
|
|
@@ -89,7 +89,7 @@ class CCXTClient {
|
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
-
getBuyQuote(
|
|
92
|
+
getBuyQuote(crypto, fiat, amountFiat, amountCrypto) {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
94
|
if (this.env === "production") {
|
|
95
95
|
const exchange = yield this.getOptimalExchange(crypto);
|
|
@@ -99,20 +99,38 @@ class CCXTClient {
|
|
|
99
99
|
if (!ticker.vwap)
|
|
100
100
|
throw new Error("Unable to get ticker vwap");
|
|
101
101
|
const exchangeFee = exchange.id === "bitstamp" ? 0.002 : 0.002;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
if (amountFiat && amountCrypto) {
|
|
103
|
+
throw new Error("Can only specify either amountFiat or amountCrypto");
|
|
104
|
+
}
|
|
105
|
+
if (!amountCrypto && !amountFiat) {
|
|
106
|
+
throw new Error("Must specify either amountFiat or amountCrypto");
|
|
107
|
+
}
|
|
108
|
+
if (amountFiat) {
|
|
109
|
+
return {
|
|
110
|
+
price: ticker.vwap * (1 + exchangeFee),
|
|
111
|
+
amountCrypto: amountFiat / (ticker.vwap * (1 + exchangeFee)),
|
|
112
|
+
amountFiat: amountFiat,
|
|
113
|
+
crypto,
|
|
114
|
+
fiat,
|
|
115
|
+
side: common_1.Side.Buy,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return {
|
|
120
|
+
price: ticker.vwap * (1 + exchangeFee),
|
|
121
|
+
amountCrypto: amountCrypto,
|
|
122
|
+
amountFiat: amountCrypto * ticker.vwap * (1 + exchangeFee),
|
|
123
|
+
crypto,
|
|
124
|
+
fiat,
|
|
125
|
+
side: common_1.Side.Buy,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
110
128
|
}
|
|
111
129
|
else {
|
|
112
130
|
return {
|
|
113
131
|
price: 0.5,
|
|
114
|
-
amountCrypto:
|
|
115
|
-
amountFiat:
|
|
132
|
+
amountCrypto: amountFiat,
|
|
133
|
+
amountFiat: amountFiat,
|
|
116
134
|
crypto,
|
|
117
135
|
fiat,
|
|
118
136
|
side: common_1.Side.Buy,
|
|
@@ -171,8 +189,14 @@ class CCXTClient {
|
|
|
171
189
|
return exchange;
|
|
172
190
|
});
|
|
173
191
|
}
|
|
174
|
-
getSellQuote(
|
|
192
|
+
getSellQuote(crypto, fiat, amountFiat, amountCrypto) {
|
|
175
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
if (amountFiat && amountCrypto) {
|
|
195
|
+
throw new Error("Can only specify either amountFiat or amountCrypto");
|
|
196
|
+
}
|
|
197
|
+
if (!amountCrypto && !amountFiat) {
|
|
198
|
+
throw new Error("Must specify either amountFiat or amountCrypto");
|
|
199
|
+
}
|
|
176
200
|
if (this.env === "production") {
|
|
177
201
|
const exchange = yield this.getOptimalExchange(crypto);
|
|
178
202
|
if (!exchange)
|
|
@@ -182,13 +206,24 @@ class CCXTClient {
|
|
|
182
206
|
if (!ticker.vwap)
|
|
183
207
|
throw new Error("Unable to get ticker vwap");
|
|
184
208
|
const exchangeFee = exchange.id === "bitstamp" ? 0.002 : 0.002;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
209
|
+
if (amountCrypto) {
|
|
210
|
+
return {
|
|
211
|
+
price: ticker.vwap * (1 - exchangeFee),
|
|
212
|
+
amountCrypto: amountCrypto,
|
|
213
|
+
amountFiat: amountCrypto * (ticker.vwap * (1 - exchangeFee)),
|
|
214
|
+
crypto,
|
|
215
|
+
fiat,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return {
|
|
220
|
+
price: ticker.vwap * (1 - exchangeFee),
|
|
221
|
+
amountCrypto: amountFiat / (ticker.vwap * (1 - exchangeFee)),
|
|
222
|
+
amountFiat,
|
|
223
|
+
crypto,
|
|
224
|
+
fiat,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
192
227
|
}
|
|
193
228
|
else {
|
|
194
229
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Crypto } from "@riocrypto/common";
|
|
2
2
|
export declare const getNetworkFees: (crypto: Crypto, cryptoPrice: number, conversionRateToUSD: number) => Promise<{
|
|
3
3
|
withdrawFeeInBaseFiat: number;
|
|
4
|
-
withdrawFeeInBaseCrypto: string | number;
|
|
4
|
+
withdrawFeeInBaseCrypto: string | number | undefined;
|
|
5
5
|
}>;
|
|
@@ -37,12 +37,12 @@ const getNetworkFees = (crypto, cryptoPrice, conversionRateToUSD) => __awaiter(v
|
|
|
37
37
|
let withdrawFeeInBaseFiat;
|
|
38
38
|
const cryptoAsset = new common_1.CryptoAsset(crypto);
|
|
39
39
|
if (cryptoAsset.getSymbol() !== cryptoAsset.getGasSymbol()) {
|
|
40
|
-
const withdrawFeeUSDResponse = yield ccxt_client_1.ccxtWrapper.getSellQuote(
|
|
40
|
+
const withdrawFeeUSDResponse = yield ccxt_client_1.ccxtWrapper.getSellQuote(new common_1.CryptoAsset(crypto).getGasSymbol(), common_1.Fiat.USD, undefined, Number(withdrawFee));
|
|
41
41
|
if (cryptoAsset.getSymbol().includes("USDC")) {
|
|
42
42
|
withdrawFeeInBaseCrypto = withdrawFeeUSDResponse.amountFiat;
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
const withdrawFeeCryptoResponse = yield ccxt_client_1.ccxtWrapper.getBuyQuote(
|
|
45
|
+
const withdrawFeeCryptoResponse = yield ccxt_client_1.ccxtWrapper.getBuyQuote(crypto, common_1.Fiat.USD, Number(withdrawFeeUSDResponse.amountFiat), undefined);
|
|
46
46
|
withdrawFeeInBaseCrypto = withdrawFeeCryptoResponse.amountCrypto;
|
|
47
47
|
}
|
|
48
48
|
withdrawFeeInBaseFiat =
|