@cityofzion/blockchain-service 1.0.2 → 1.1.0
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/CryptoCompareEDS.d.ts +5 -4
- package/dist/CryptoCompareEDS.js +22 -28
- package/dist/interfaces.d.ts +16 -14
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, TokenPricesHistoryResponse, TokenPricesResponse } from './interfaces';
|
|
2
2
|
export declare class CryptoCompareEDS implements ExchangeDataService {
|
|
3
3
|
#private;
|
|
4
|
-
constructor(
|
|
5
|
-
getTokenPrices(
|
|
6
|
-
getTokenPriceHistory(params:
|
|
4
|
+
constructor();
|
|
5
|
+
getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
|
|
6
|
+
getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
|
|
7
|
+
getCurrencyRatio(currency: string): Promise<number>;
|
|
7
8
|
}
|
package/dist/CryptoCompareEDS.js
CHANGED
|
@@ -22,39 +22,31 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
22
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
|
-
var _CryptoCompareEDS_axiosInstance
|
|
25
|
+
var _CryptoCompareEDS_axiosInstance;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.CryptoCompareEDS = void 0;
|
|
28
28
|
const axios_1 = __importDefault(require("axios"));
|
|
29
29
|
class CryptoCompareEDS {
|
|
30
|
-
constructor(
|
|
30
|
+
constructor() {
|
|
31
31
|
_CryptoCompareEDS_axiosInstance.set(this, void 0);
|
|
32
|
-
_CryptoCompareEDS_tokens.set(this, void 0);
|
|
33
|
-
__classPrivateFieldSet(this, _CryptoCompareEDS_tokens, tokens, "f");
|
|
34
32
|
__classPrivateFieldSet(this, _CryptoCompareEDS_axiosInstance, axios_1.default.create({ baseURL: 'https://min-api.cryptocompare.com' }), "f");
|
|
35
33
|
}
|
|
36
|
-
getTokenPrices(
|
|
34
|
+
getTokenPrices(params) {
|
|
37
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const tokenSymbols = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").map(token => token.symbol);
|
|
39
36
|
const { data: prices } = yield __classPrivateFieldGet(this, _CryptoCompareEDS_axiosInstance, "f").get('/data/pricemultifull', {
|
|
40
37
|
params: {
|
|
41
|
-
fsyms:
|
|
42
|
-
tsyms:
|
|
38
|
+
fsyms: params.tokens.map(token => token.symbol).join(','),
|
|
39
|
+
tsyms: 'USD',
|
|
43
40
|
},
|
|
44
41
|
});
|
|
45
|
-
return Object.entries(prices.RAW)
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const token = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").find(token => token.symbol === symbol);
|
|
49
|
-
if (!token || !price)
|
|
50
|
-
return;
|
|
42
|
+
return Object.entries(prices.RAW).map(([symbol, priceObject]) => {
|
|
43
|
+
const usdPrice = priceObject.USD.PRICE;
|
|
44
|
+
const token = params.tokens.find(token => token.symbol === symbol);
|
|
51
45
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
hash: token === null || token === void 0 ? void 0 : token.hash,
|
|
46
|
+
usdPrice,
|
|
47
|
+
token,
|
|
55
48
|
};
|
|
56
|
-
})
|
|
57
|
-
.filter((price) => price !== undefined);
|
|
49
|
+
});
|
|
58
50
|
});
|
|
59
51
|
}
|
|
60
52
|
getTokenPriceHistory(params) {
|
|
@@ -62,26 +54,28 @@ class CryptoCompareEDS {
|
|
|
62
54
|
const path = `/data/${params.type === 'hour' ? 'histohour' : 'histoday'}`;
|
|
63
55
|
const response = yield __classPrivateFieldGet(this, _CryptoCompareEDS_axiosInstance, "f").get(path, {
|
|
64
56
|
params: {
|
|
65
|
-
fsym: params.
|
|
66
|
-
tsym:
|
|
57
|
+
fsym: params.token.symbol,
|
|
58
|
+
tsym: 'USD',
|
|
67
59
|
limit: params.limit,
|
|
68
60
|
},
|
|
69
61
|
});
|
|
70
62
|
const history = [];
|
|
71
63
|
response.data.Data.forEach(data => {
|
|
72
|
-
const token = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").find(token => token.symbol === params.tokenSymbol);
|
|
73
|
-
if (!token)
|
|
74
|
-
return;
|
|
75
64
|
history.push({
|
|
76
|
-
|
|
65
|
+
usdPrice: data.close,
|
|
77
66
|
timestamp: data.time,
|
|
78
|
-
|
|
79
|
-
hash: token.hash,
|
|
67
|
+
token: params.token,
|
|
80
68
|
});
|
|
81
69
|
});
|
|
82
70
|
return history;
|
|
83
71
|
});
|
|
84
72
|
}
|
|
73
|
+
getCurrencyRatio(currency) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const { data } = yield axios_1.default.get(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`);
|
|
76
|
+
return data;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
85
79
|
}
|
|
86
80
|
exports.CryptoCompareEDS = CryptoCompareEDS;
|
|
87
|
-
_CryptoCompareEDS_axiosInstance = new WeakMap()
|
|
81
|
+
_CryptoCompareEDS_axiosInstance = new WeakMap();
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -109,13 +109,15 @@ export type ContractParameter = {
|
|
|
109
109
|
type: string;
|
|
110
110
|
};
|
|
111
111
|
export type TransactionsByAddressResponse = {
|
|
112
|
-
totalCount
|
|
113
|
-
limit
|
|
112
|
+
totalCount?: number;
|
|
113
|
+
limit?: number;
|
|
114
|
+
nextCursor?: string;
|
|
114
115
|
transactions: TransactionResponse[];
|
|
115
116
|
};
|
|
116
117
|
export type TransactionsByAddressParams = {
|
|
117
118
|
address: string;
|
|
118
119
|
page?: number;
|
|
120
|
+
cursor?: string;
|
|
119
121
|
};
|
|
120
122
|
export type ContractMethod = {
|
|
121
123
|
name: string;
|
|
@@ -149,26 +151,26 @@ export interface BDSClaimable {
|
|
|
149
151
|
getUnclaimed(address: string): Promise<string>;
|
|
150
152
|
}
|
|
151
153
|
export type TokenPricesResponse = {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
hash: string;
|
|
154
|
+
usdPrice: number;
|
|
155
|
+
token: Token;
|
|
155
156
|
};
|
|
156
157
|
export type TokenPricesHistoryResponse = {
|
|
157
|
-
|
|
158
|
+
usdPrice: number;
|
|
158
159
|
timestamp: number;
|
|
159
|
-
|
|
160
|
-
hash: string;
|
|
160
|
+
token: Token;
|
|
161
161
|
};
|
|
162
|
-
export type
|
|
163
|
-
|
|
164
|
-
tokenSymbol: string;
|
|
165
|
-
currency: Currency;
|
|
162
|
+
export type GetTokenPriceHistoryParams = {
|
|
163
|
+
token: Token;
|
|
166
164
|
type: 'hour' | 'day';
|
|
167
165
|
limit: number;
|
|
168
166
|
};
|
|
167
|
+
export type GetTokenPricesParams = {
|
|
168
|
+
tokens: Token[];
|
|
169
|
+
};
|
|
169
170
|
export interface ExchangeDataService {
|
|
170
|
-
getTokenPrices(
|
|
171
|
-
getTokenPriceHistory(params:
|
|
171
|
+
getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
|
|
172
|
+
getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
|
|
173
|
+
getCurrencyRatio(currency: string): Promise<number>;
|
|
172
174
|
}
|
|
173
175
|
export interface NftResponse {
|
|
174
176
|
id: string;
|