Skip to content

React context provider and accompanying hook for streaming real time crypto prices

License

Notifications You must be signed in to change notification settings

shed3/react-realtime-crypto-prices

Repository files navigation

Contributors MIT License top-languages-shield languages-count-shield package-version-shield npm-monthly-downloads-shield


React Real Time Crypto Prices

The easiest way to use live crypto prices in React

Report Bug · Request Feature

Table of Contents


About React Real Time Crypto Prices

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!

Built With

This library requires the following packages to be installed:

Getting Started

Getting started with React Real Time Crypto Prices is very simple! Just install using the node package manager of your choosing and voilà!

Prerequisites

  • 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.

Installation

Install React Crypto Icons from npm

npm install react-realtime-crypto-prices

Or with yarn

yarn add react-realtime-crypto-prices

Usage

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

Hooks

useCryptoPrices

  • Accepts array of symbols
  • returns data in format {symbol: price}

Example

{
    "btc": 40105.28,
    "eth": 2381.19,
    "ltc": 526.97
}

useCryptoTickers

  • 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
    }
}

Roadmap

  • 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).

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch
    git checkout -b feature/AmazingFeature
  3. Commit your Changes
    git commit -m 'Add some AmazingFeature'
  4. Push to the Branch
     git push origin feature/AmazingFeature
  5. Open a Pull Request

Or you can get started developing with the example project!

  1. Fork the Project
  2. Install Dependencies
     npm install
  3. Build Package:
    npm run build
  4. Create Package Link:
    npm link
  5. Install Example Project Dependencies:
    cd example/
    npm install
    npm link react-realtime-crypto-prices
  6. Resolve React versions between package and example project:
    cd ../
    npm link example/node_modules/react
  7. Run tests:
    npm run test

License

Distributed under the MIT License. See LICENSE.txt for more information. Houston we have...Free Software!

Contact

Riley Stephens - rileystephens@escalatorllc.com

back to top

About

React context provider and accompanying hook for streaming real time crypto prices

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published