The easiest way to use live crypto prices in React
Report Bug
·
Request Feature
- About React Real Time Crypto Prices
- Getting Started
- Usage
- Hooks
- Roadmap
- Contributing
- License
- Contact
React Real Time Crypto Prices provides a simple context provider and hooks for using live simple prices and candle data in your components. The package allows both realtime simple price (ex: $100) and candle tickers (includes values for open, high, low, close, volume).
HOWEVER, the CryptoPriceProvider requires a CryptoCompare API key in order to stream candle tickers (simple prices work out the box). You can get a free API key here!
This library requires the following packages to be installed:
Getting started with React Real Time Crypto Prices is very simple! Just install using the node package manager of your choosing and voilà!
-
React Crypto Icons requires Node.js v12+ to run.
-
Like we mentioned above you will need an API key from CryptoCompare. Grab one over here.
Install React Crypto Icons from npm
npm install react-realtime-crypto-prices
Or with yarn
yarn add react-realtime-crypto-prices
All symbols should be lowercase to avoid capitalization mismatching.
import React from "react";
import {
useCryptoPrices,
useCryptoTickers,
CryptoPriceProvider,
} from "react-realtime-crypto-prices";
const HookExample = () => {
const prices = useCryptoPrices(["btc", "eth"]);
const tickers = useCryptoTickers(["btc", "eth"]);
return (
<>
<div>Live Prices</div>
<div>{JSON.stringify(prices)}</div>
<div>Live Tickers</div>
<div>{JSON.stringify(tickers)}</div>
</>
);
};
const App = () => {
return (
<div className="App">
<CryptoPriceProvider cryptoCompareApiKey="<YOUR-API_KEY>">
<HookExample />
</CryptoPriceProvider>
</div>
);
};
export default App;
Ladies and gents we have live prices
*Note: cryptoCompareApiKey is an optional prop for CryptoPriceProvider, however, if not included, the library will be unable to stream ticker data
- Accepts array of symbols
- returns data in format {symbol: price}
Example
{
"btc": 40105.28,
"eth": 2381.19,
"ltc": 526.97
}
- Accepts array of symbols
- returns data in format {symbol: {timestamp, open, high, low, close, volume}
Example
{
"btc": {
"timestamp": 2021-07-29T15:55:00.000Z,
"open": 39961.26,
"high": 39978.48,
"low": 39955.29,
"close":39978.48,
"volume": 772926.41
},
"eth": {
"timestamp": 2021-07-29T15:55:00.000Z,
"open": 2322.47,
"high": 2323.23,
"low": 2321.54,
"close":2323.23,
"volume": 932626.37
}
}
- Add Changelog
- Add List of Supported Symbols to README
- Add Live Demo
- Define Types and Interfaces
See the open issues for a full list of proposed features (and known issues).
React Real Time Crypto Prices is written in TypeScript and will be tested using jest.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch
git checkout -b feature/AmazingFeature
- Commit your Changes
git commit -m 'Add some AmazingFeature'
- Push to the Branch
git push origin feature/AmazingFeature
- Open a Pull Request
Or you can get started developing with the example project!
- Fork the Project
- Install Dependencies
npm install
- Build Package:
npm run build
- Create Package Link:
npm link
- Install Example Project Dependencies:
cd example/ npm install npm link react-realtime-crypto-prices
- Resolve React versions between package and example project:
cd ../ npm link example/node_modules/react
- Run tests:
npm run test
Distributed under the MIT License. See LICENSE.txt
for more information.
Houston we have...Free Software!
Riley Stephens - rileystephens@escalatorllc.com