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.
# via npm
npm i kibokogetpricehook
# via yarn
yarn add kibokogetpricehook
getPairPrice: Fetches the current price of a specified cryptocurrency pair.
import { getPairPrice } from 'kibokogetpricehook'
const getTokenPairPrice = () => {
getPairPrice('ETH/USD').then((res: any) => {
console.log("Pair price: ", res)
}).catch((err: any) => {
console.error(err)
})
}
getExchangeRate: Retrieves the exchange rate for a specified token against a base currency, dynamically responding to user input changes.
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);
}
};
getCurrencyExchangeRate: Obtains the exchange rate for a specified token against a set of currencies, using additional data for calculations.
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);
}
};
This library is licensed under the MIT License.