@mintbase-js/data
Advanced tools
Comparing version 0.6.0-near-api-js-cec3fd5.0 to 0.6.0-near-price-update-a58f78f.0
import { ParsedDataReturn } from '../../types'; | ||
import { NearPriceData } from './nearPrice.types'; | ||
export declare const fetchPriceFromCoinGecko: () => Promise<NearPriceData>; | ||
export declare const fetchPriceFromBinance: () => Promise<NearPriceData>; | ||
export declare const nearPrice: () => Promise<ParsedDataReturn<string>>; | ||
//# sourceMappingURL=nearPrice.d.ts.map |
@@ -15,24 +15,20 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nearPrice = exports.fetchPriceFromBinance = exports.fetchPriceFromCoinGecko = void 0; | ||
exports.nearPrice = void 0; | ||
const cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
const constants_1 = require("../../constants"); | ||
const utils_1 = require("../../utils"); | ||
const fetchPriceFromCoinGecko = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const req = yield (0, cross_fetch_1.default)(constants_1.COIN_GECKO_API); | ||
const data = yield req.json(); | ||
return { price: data.near.usd }; | ||
}); | ||
exports.fetchPriceFromCoinGecko = fetchPriceFromCoinGecko; | ||
const fetchPriceFromBinance = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const req = yield (0, cross_fetch_1.default)(constants_1.BINANCE_API); | ||
const data = yield req.json(); | ||
return data; | ||
}); | ||
exports.fetchPriceFromBinance = fetchPriceFromBinance; | ||
function fetchPrice(url, tokenPrice) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const req = yield (0, cross_fetch_1.default)(url); | ||
const data = yield req.json(); | ||
return tokenPrice(data); | ||
}); | ||
} | ||
const nearPrice = () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const res = yield Promise.any([ | ||
(0, exports.fetchPriceFromCoinGecko)(), | ||
(0, exports.fetchPriceFromBinance)(), | ||
]); | ||
const res = yield fetchPrice(constants_1.BINANCE_API, data => data) | ||
.catch((err) => __awaiter(void 0, void 0, void 0, function* () { | ||
console.log('First API call failed, trying second API', err); | ||
return yield fetchPrice(constants_1.COIN_GECKO_API, data => ({ price: data.near.usd })); | ||
})); | ||
return (0, utils_1.parseData)(res.price); | ||
@@ -39,0 +35,0 @@ } |
{ | ||
"name": "@mintbase-js/data", | ||
"version": "0.6.0-near-api-js-cec3fd5.0", | ||
"version": "0.6.0-near-price-update-a58f78f.0", | ||
"description": "Query wrappers for Mintbase JS SDK", | ||
@@ -33,3 +33,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "7c91ba401680966ad1701ce77bb231f0a210034e" | ||
"gitHead": "d21f3207b2d066d4bb6dba415730744a5d160b60" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
970168
12574