@riocrypto/common-server 1.0.663 → 1.0.665

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(amount: number, crypto: Crypto, fiat: Fiat): Promise<{
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;
@@ -89,7 +89,7 @@ class CCXTClient {
89
89
  }
90
90
  });
91
91
  }
92
- getBuyQuote(amount, crypto, fiat) {
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
- return {
103
- price: ticker.vwap * (1 + exchangeFee),
104
- amountCrypto: amount / (ticker.vwap * (1 + exchangeFee)),
105
- amountFiat: amount,
106
- crypto,
107
- fiat,
108
- side: common_1.Side.Buy,
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: amount,
115
- amountFiat: amount,
132
+ amountCrypto: amountFiat,
133
+ amountFiat: amountFiat,
116
134
  crypto,
117
135
  fiat,
118
136
  side: common_1.Side.Buy,
@@ -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
  }>;
@@ -42,7 +42,7 @@ const getNetworkFees = (crypto, cryptoPrice, conversionRateToUSD) => __awaiter(v
42
42
  withdrawFeeInBaseCrypto = withdrawFeeUSDResponse.amountFiat;
43
43
  }
44
44
  else {
45
- const withdrawFeeCryptoResponse = yield ccxt_client_1.ccxtWrapper.getBuyQuote(Number(withdrawFeeUSDResponse.amountFiat), crypto, common_1.Fiat.USD);
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 =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.663",
3
+ "version": "1.0.665",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",