UNPKG

bitpay-sdk

Version:

Complete version of the NodeJS library for the new cryptographically secure BitPay API

51 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RateClient = void 0; const Model_1 = require("../Model"); const BitPayExceptionProvider_1 = require("../Exceptions/BitPayExceptionProvider"); class RateClient { constructor(bitPayClient) { this.bitPayClient = bitPayClient; } /** * Retrieve the rate for a cryptocurrency / fiat pair * * @param baseCurrency The cryptocurrency for which you want to fetch the fiat-equivalent rate. * @param currency The fiat currency for which you want to fetch the baseCurrency rate * @returns Rate A Rate object populated with the currency rate for the requested baseCurrency. * @throws BitPayGenericException BitPayGenericException class * @throws BitPayApiException BitPayApiException class */ async getRate(baseCurrency, currency) { const uri = currency ? 'rates/' + baseCurrency + '/' + currency : '/' + baseCurrency; const result = await this.bitPayClient.get(uri, null, false); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Rate', e.message); throw new Error(); } } /** * Retrieve the exchange rate table maintained by BitPay. See https://bitpay.com/bitcoin-exchange-rates. * * @param currency * @returns Rates A Rates object populated with the currency rates for the requested baseCurrency. * @throws BitPayGenericException BitPayGenericException class * @throws BitPayApiException BitPayApiException class */ async getRates(currency) { const uri = currency ? 'rates/' + currency : 'rates'; const result = await this.bitPayClient.get(uri, null, false); try { return new Model_1.Rates(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Rate', e.message); throw new Error(); } } } exports.RateClient = RateClient; //# sourceMappingURL=RateClient.js.map