Skip to content

Package containing a bunch of functions that can be called to perform varios functions includeing: get price of crypto in local currencies,fetch price feeds from Starknet's pragma contract among others

Notifications You must be signed in to change notification settings

KibokoDao-Africa/KibokoGetPriceHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KibokoGetPriceHook

npm version npm downloads MIT License Build Status Coverage Status

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

Alt text

License

This library is licensed under the MIT License.

About

Package containing a bunch of functions that can be called to perform varios functions includeing: get price of crypto in local currencies,fetch price feeds from Starknet's pragma contract among others

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published