kibokogetpricehook
v1.0.3
Published
Collection of functions to call to get price of various tokens on different blockchain networks using onchain feeds
Downloads
15
Maintainers
Readme
KibokoGetPriceHook
The kibokogetpricehook package provides utility functions to fetch real-time financial data, including pair prices, exchange rates, and currency-specific exchange rates. It's designed for seamless integration with financial applications.
Installation
# via npm
npm i kibokogetpricehook
# via yarn
yarn add kibokogetpricehook
1. Getting Token Pair Price
Description
getPairPrice: Fetches the current price of a specified cryptocurrency pair.
Usage
import { getPairPrice } from 'kibokogetpricehook'
const getTokenPairPrice = () => {
getPairPrice('ETH/USD').then((res: any) => {
console.log("Pair price: ", res)
}).catch((err: any) => {
console.error(err)
})
}
2. Getting Exchange Rate
Description
getExchangeRate: Retrieves the exchange rate for a specified token against a base currency, dynamically responding to user input changes.
Usage
import { getExchangeRate } from "kibokogetpricehook";
// Updates the selected token and fetches its exchange rate.
const handleTokenChangeForExchangeRate = (event: React.ChangeEvent<HTMLInputElement>) => {
const token = event.target.value;
setSelectedToken(token);
getExchangeRate(token, numberOfTokens);
};
// Updates the number of tokens and fetches the updated exchange rate.
const handleNumberOfTokensChangeForExchangeRate = async (event: React.ChangeEvent<HTMLInputElement>) => {
const tokens = event.target.value;
setNumberOfTokens(tokens);
try {
const amountInKesReceived = await getExchangeRate(selectedToken, tokens);
setAmountToReceive(String(amountInKesReceived));
console.log(amountInKesReceived);
} catch (error) {
console.error("Error fetching exchange rate", error);
}
};
3. Getting Currency-Specific Exchange Rate
Description
getCurrencyExchangeRate: Obtains the exchange rate for a specified token against a set of currencies, using additional data for calculations.
Usage
import { getCurrencyExchangeRate } from "kibokogetpricehook";
// Updates the selected token and fetches its currency-specific exchange rate.
const handleTokenChangeForExchangeRate = (event: React.ChangeEvent<HTMLInputElement>) => {
const token = event.target.value;
setSelectedToken(token);
getCurrencyExchangeRate(token, numberOfTokens, ratesData);
};
// Updates the number of tokens and fetches the updated currency-specific exchange rate.
const handleNumberOfTokensChangeForExchangeRate = async (event: React.ChangeEvent<HTMLInputElement>) => {
const tokens = event.target.value;
setNumberOfTokens(tokens);
try {
const amountInCurrencyReceived = await getCurrencyExchangeRate(selectedToken, tokens, ratesData);
setAmountToReceive(String(amountInCurrencyReceived));
console.log(amountInCurrencyReceived);
} catch (error) {
console.error("Error fetching exchange rate", error);
}
};
NPM Package Snapshot
License
This library is licensed under the MIT License.