swapped-commerce-sdk 1.0.2 → 1.0.3
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.
- package/dist/index.js +7 -2
- package/package.json +1 -1
- package/src/resources/quotes.ts +20 -8
- package/src/types/index.ts +3 -0
- package/src/types/quotes.ts +40 -8
package/dist/index.js
CHANGED
|
@@ -210,8 +210,13 @@ async function getBalance(httpConfig, currencyId) {
|
|
|
210
210
|
|
|
211
211
|
// src/resources/quotes.ts
|
|
212
212
|
async function getQuote(httpConfig, params) {
|
|
213
|
-
return request(httpConfig.config, "
|
|
214
|
-
|
|
213
|
+
return request(httpConfig.config, "GET", "/v1/quotes", {
|
|
214
|
+
params: {
|
|
215
|
+
fromAmount: String(params.fromAmount),
|
|
216
|
+
fromFiatCurrency: params.fromFiatCurrency,
|
|
217
|
+
toCurrency: params.toCurrency,
|
|
218
|
+
toBlockchain: params.toBlockchain
|
|
219
|
+
}
|
|
215
220
|
});
|
|
216
221
|
}
|
|
217
222
|
|
package/package.json
CHANGED
package/src/resources/quotes.ts
CHANGED
|
@@ -8,17 +8,29 @@ import { request } from '../utils/http'
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Get a quote for currency conversion
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const response = await client.quotes.get({
|
|
15
|
+
* fromAmount: 25,
|
|
16
|
+
* fromFiatCurrency: 'EUR',
|
|
17
|
+
* toCurrency: 'TRX',
|
|
18
|
+
* toBlockchain: 'tron',
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* console.log(response.data.toAmount.afterFees) // "103.802"
|
|
22
|
+
* ```
|
|
11
23
|
*/
|
|
12
24
|
export async function getQuote(
|
|
13
25
|
httpConfig: HttpConfig,
|
|
14
26
|
params: Readonly<GetQuoteParams>
|
|
15
27
|
): Promise<ApiResponse<QuoteResponse>> {
|
|
16
|
-
return request<QuoteResponse>(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
)
|
|
28
|
+
return request<QuoteResponse>(httpConfig.config, 'GET', '/v1/quotes', {
|
|
29
|
+
params: {
|
|
30
|
+
fromAmount: String(params.fromAmount),
|
|
31
|
+
fromFiatCurrency: params.fromFiatCurrency,
|
|
32
|
+
toCurrency: params.toCurrency,
|
|
33
|
+
toBlockchain: params.toBlockchain,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
24
36
|
}
|
package/src/types/index.ts
CHANGED
package/src/types/quotes.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
import type { Currency } from './currencies'
|
|
1
|
+
import type { Blockchain, Currency } from './currencies'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Simplified currency info returned in quote responses
|
|
5
|
+
*/
|
|
6
|
+
export interface QuoteCurrency {
|
|
7
|
+
readonly symbol: string
|
|
8
|
+
readonly precision: number
|
|
9
|
+
readonly type: 'FIAT' | 'CRYPTO'
|
|
10
|
+
readonly blockchain: { readonly name: string } | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Money amount with currency (used in orders and other contexts)
|
|
5
15
|
*/
|
|
6
16
|
export interface MoneyAmount {
|
|
7
17
|
readonly amount: string
|
|
8
18
|
readonly currency: Currency
|
|
9
19
|
}
|
|
10
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Quote from amount with currency
|
|
23
|
+
*/
|
|
24
|
+
export interface QuoteFromAmount {
|
|
25
|
+
readonly amount: string
|
|
26
|
+
readonly currency: QuoteCurrency
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Quote to amount with before/after fees
|
|
31
|
+
*/
|
|
32
|
+
export interface QuoteToAmount {
|
|
33
|
+
readonly beforeFees: string
|
|
34
|
+
readonly afterFees: string
|
|
35
|
+
readonly currency: QuoteCurrency
|
|
36
|
+
}
|
|
37
|
+
|
|
11
38
|
/**
|
|
12
39
|
* Fee information
|
|
13
40
|
*/
|
|
@@ -21,7 +48,7 @@ export interface Fee {
|
|
|
21
48
|
}
|
|
22
49
|
|
|
23
50
|
/**
|
|
24
|
-
* Exchange quote
|
|
51
|
+
* Exchange quote (used in orders)
|
|
25
52
|
*/
|
|
26
53
|
export interface Quote {
|
|
27
54
|
readonly fromAmount: MoneyAmount
|
|
@@ -34,16 +61,21 @@ export interface Quote {
|
|
|
34
61
|
* Parameters for getting a quote
|
|
35
62
|
*/
|
|
36
63
|
export interface GetQuoteParams {
|
|
37
|
-
|
|
64
|
+
/** Amount to convert from */
|
|
65
|
+
readonly fromAmount: string | number
|
|
66
|
+
/** Source fiat currency symbol (e.g., 'EUR', 'USD') */
|
|
67
|
+
readonly fromFiatCurrency: string
|
|
68
|
+
/** Target currency symbol (e.g., 'TRX', 'USDT') */
|
|
38
69
|
readonly toCurrency: string
|
|
39
|
-
|
|
40
|
-
readonly
|
|
70
|
+
/** Target blockchain name (e.g., 'tron', 'ethereum') */
|
|
71
|
+
readonly toBlockchain: string
|
|
41
72
|
}
|
|
42
73
|
|
|
43
74
|
/**
|
|
44
75
|
* Response for getting a quote
|
|
45
76
|
*/
|
|
46
77
|
export interface QuoteResponse {
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
78
|
+
readonly exchangeRateSnapshotId: string
|
|
79
|
+
readonly fromAmount: QuoteFromAmount
|
|
80
|
+
readonly toAmount: QuoteToAmount
|
|
49
81
|
}
|