npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

use-upbit-api

v2.0.9

Published

This is React Custom Hook for upbit api

Downloads

35

Readme

use-upbit-api

GitHub Workflow Status Weekly Downloads version types

The use-upbit-api, React custom hook for Upbit API (Korea crypto exchange).

In the previous, Upbit API's Websocket usage in React is difficult for developer who is unfamiliar with websocket in React, but this React Custom Hook solve the problem.

Let's use this awesome custom hooks!

npm

Git Repository

Coverage Status

View Demo

Demo Code

TOTALEXAMPLE

Install

npm install --save use-upbit-api

Hooks

REST API

useFetchMarketCode

WEBSOCKET API

useWsTicker

useWsOrderbook

useWsTrade

useFetchMarketCode

useFetchMarketCode hook is used to fetch market codes from upbit api

import {useFetchMarketCode} from 'use-upbit-api';

function Component() {
  const {isLoading, marketCodes} = useFetchMarketCode(
    (options = {debug: false}), // default option, can be modified.
  );

  //...
}

⚠️ CAUTIONs IN WEBSOCKET API

targetMarketCode should be state in react (useState, ...), if not, unexpectable error can occur.

Do not use just constant or variable.

useWsTicker

useWsTicker is a custom hook that connects to a WebSocket API and retrieves real-time ticker data for a given market code.

import { useWsTicker } from "use-upbit-api";

function Component() {
  const [targetMarketCode, _] = useState([
    {
      market: 'KRW-BTC',
      korean_name: '비트코인',
      english_name: 'Bitcoin',
    },
    ...
  ]);

  const {socket, isConnected, socketData} = useWsTicker(
    targetMarketCode, // should be array
    onError, // onError?: (error: Error) => void // optional, user for using ErrorBoundary
    (options = {throttle_time: 400, debug: false}), // default option, can be modified.
  );

  // ...
}

useWsOrderbook

useWsOrderbook is a custom hook that connects to a WebSocket API and retrieves real-time order book data for a given market code.

import {useWsOrderbook} from 'use-upbit-api';

function Component() {
  const [targetMarketCode, _] = useState({
    market: 'KRW-BTC',
    korean_name: '비트코인',
    english_name: 'Bitcoin',
  });

  const {socket, isConnected, socketData} = useWsOrderbook(
    targetMarketCode, // should be above form object
    onError, // onError?: (error: Error) => void // optional, user for using ErrorBoundary
    (options = {throttle_time: 400, debug: false}), // default option, can be modified.
  );

  // ...
}

useWsTrade

useWsTrade is a custom hook that connects to a WebSocket API and retrieves real-time trade data for a given market code.

import {useWsTrade} from 'use-upbit-api';

function Component() {
  const [targetMarketCode, _] = useState({
    market: 'KRW-BTC',
    korean_name: '비트코인',
    english_name: 'Bitcoin',
  });

  const {socket, isConnected, socketData} = useWsTrade(
    targetMarketCode, // should be above form object
    onError, // onError?: (error: Error) => void // optional, user for using ErrorBoundary
    (options = {throttle_time: 400, max_length_queue: 100, debug: false}), // default option, can be modified.
  );

  // ...
}

Flow

API Flow

api_flow

Websocket Hook Flow

ws_logic_flow

Contributing

Thank you for your interest in contributing to use-upbit-api. Before you begin writing code, it is important that you share your intention to contribute with the team, based on the type of contribution

  1. You want to propose a new feature and implement it.
    • Post about your intended feature in an issue, then implement it.
    • We suggest that the branch name that you implement is better to be {type}/{issue number}/{issue name}. ex) feature/118/githubAction, bugfix/120/typo
  2. You want to implement a feature or bug-fix for an outstanding issue.
    • Search for your issue in the use-upbit-api issue list.
    • Pick an issue and comment that you'd like to work on the feature or bug-fix.
    • If you need more context on a particular issue, please ask and we shall provide.
  3. Open pull request
    • You implement and test your feature or bug-fix, please submit a Pull Request to use-upbit-api PR with some test case.
    • Once a pull request is accepted and CI is passing, there is nothing else you need to do. we will check and merge the PR for you.

Always opening to join this project for developing this library.

❗️ISSUE

Pull Request

License

Licensed under the MIT License, Copyright © 2022-present MinHyeok Kang.