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

@lab49/react-order-book

v0.1.4

Published

Render an order book for any asset class. Flexible and customizable.

Downloads

428

Readme

@lab49/react-order-book

codecov .github/workflows/cicd.yaml npm version Contributor Covenant

react-order-book

react-order-book is a simple, flexible order book component. Pass in an order book as a prop, and cutomize the look and feel with plenty of configuration options, plus numerous styling hooks for visual customization.

react-order-book tries to be extremely unopinionated about styling, and as such, includes very little actual style rules. There's plenty of examples in the included demo website that show how you can use the rendered class names to create your own beautiful experiences.

This component is perfect for:

  • Trading platforms
  • Order entry systems
  • Dashboards

Features

  • Written in TypeScript
  • Small, simple, configurable, performant
  • Maintained by a team of finance industry professionals

Table of contents

Demo

Hosted demo: Hosted demo: https://master--5f4988473b6fd20022f12dcc.chromatic.com/

You can also run the demo locally. To get started:

git clone [email protected]:lab49/react-order-book.git
npm install
npm run storybook
⇡ Top

Installation

npm install @lab49/react-order-book
⇡ Top

Usage

import { OrderBook } from '@lab49/react-order-book';

// This is a simple order book structure. There's an array
// of asks, and array of bids. Each entry in the array is
// an array where the first index represents the price,
// and the second index represents the "size", or the total
// number of units of an asset offered at that price.
const book = {
  asks: [
    ['1.01', '2'],
    ['1.02', '3'],
  ],
  bids: [
    ['0.99', '5'],
    ['0.98', '3'],
  ],
};

<OrderBook book={book} />

As discussed above, there are a number of classnames you can use to add your own styles. There is an example of doing exactly that in the included Storybook. There's too many to list out, but by default, all DOM nodes have a classname prefixed with rob_OrderBook. As an example:

<OrderBook book={book} />

// Will render...

<div class="rob_OrderBook">
  <div class="rob_OrderBook__side rob_OrderBook__side--asks">
    // ...more content
  </div>

  <div class="rob_OrderBook__side rob_OrderBook__side--bids">
    // ...more content
  </div>
</div>
⇡ Top

API

OrderBook

<OrderBook /> is a (props: Props) => JSX.Element. See Props below for a description of the avilable props.

import { OrderBook } from '@lab49/react-order-book';

const MyComponent = () => <OrderBook book={book} />;

Props

interface Props {
  /**
   * For the internaly calculated colors, apply a background-color in the DOM.
   */
  applyBackgroundColor?: boolean;
  /**
   * Base color for the asks list.
   */
  askColor?: RgbColor;
  /**
   * Base color for the bids list.
   */
  bidColor?: RgbColor;
  /**
   * Order book object.
   */
  book: OrderBook;
  /**
   * Use a value of 1 for the opacity of each row's generated color.
   */
  fullOpacity?: boolean;
  /**
   * Color interpolator function.
   */
  interpolateColor?: Interpolator;
  /**
   * Various layout options.
   */
  layout?: Layout;
  /**
   * Limit the length of the rendered bids and asks.
   */
  listLength?: number;
  /**
   * Show column headers.
   */
  showHeaders?: boolean;
  /**
   * Show the spread.
   */
  showSpread?: boolean;
  /**
   * Provide a custom spread value instead of letting OrderBook calculate it.
   */
  spread?: string;
  /**
   * Prefix for the CSS class name in the DOM.
   */
  stylePrefix?: string;
}

Layout

Available layout modes. See the demo website for an example of what this looks like.

enum Layout {
  Row = 'row'
}
⇡ Top

License

MIT @ Lab49

⇡ Top

Sponsored by Lab49