import { OrderBook } from '../types';
import { cn } from '../lib/utils';
interface OrderBookViewProps {
orderBook: OrderBook;
className?: string;
}
export const OrderBookView = ({ orderBook, className }: OrderBookViewProps) => {
const maxTotal = Math.max(
...orderBook.bids.map(b => b.total),
...orderBook.asks.map(a => a.total)
);
const getDepthWidth = (total: number) => {
return (total / maxTotal) * 100;
};
return (
Order Book
{/* Bids */}
{orderBook.bids.map((bid, index) => (
{bid.price.toLocaleString()}
{bid.amount.toFixed(4)}
{bid.total.toFixed(2)}
))}
{/* Asks */}
{orderBook.asks.map((ask, index) => (
{ask.price.toLocaleString()}
{ask.amount.toFixed(4)}
{ask.total.toFixed(2)}
))}
{/* Spread */}
Spread
{orderBook.asks[0] && orderBook.bids[0]
? ((orderBook.asks[0].price - orderBook.bids[0].price) / orderBook.bids[0].price * 100).toFixed(3)
: '0.000'}%
);
};