Skip to main content
This hook requires the OrderbookProvider to be present in your component tree and history recording must be enabled (via historyEnabled). The number of snapshots available depends on maxHistoryLength.

Import

import { useOrderbookHistory } from '@krono/hooks'

Usage

import { useOrderbookHistory } from '@krono/hooks'

function HistoryList() {
  const { getAll, size } = useOrderbookHistory();
  const history = getAll();

  return (
    <ul>
      <li>Total Snapshots: {size}</li>
      {history.map((snap) => (
        <li key={snap.timestamp}>Spread at {snap.timestamp}: {snap.spread}</li>
      ))}
    </ul>
  );
}

Return Type

State

size
number
The current number of items in the buffer.
isEmpty
boolean
Helper indicating if the buffer contains zero snapshots.

Actions

get
(index: number) => OrderbookData | undefined
Retrieves a specific snapshot by index.
getAll
() => OrderbookData[]
Returns the entire array of snapshots currently in the buffer.
getLatest
() => OrderbookData | undefined
Returns the most recent snapshot in the history.