# `Bourse.OrderBook`
[🔗](https://github.com/ZenHive/bourse/blob/main/lib/bourse/order_book.ex#L1)

Unified order book (market depth) data.

Contains sorted bid and ask price levels, each as an exact `[price, amount]` pair.
Venue-specific level metadata remains available in `info`.
Bids are sorted highest-first, asks lowest-first.

## Fields

  * `symbol` - Unified symbol (e.g., "BTC/USDT")
  * `timestamp` - Exchange timestamp in milliseconds
  * `datetime` - ISO 8601 datetime string
  * `nonce` - Incremental update sequence number
  * `bids` - List of exact `[price, amount]` bid pairs, highest first
  * `asks` - List of exact `[price, amount]` ask pairs, lowest first
  * `info` - Raw exchange response

# `level`

```elixir
@type level() :: [number()]
```

An exact two-number `[price, amount]` pair.

# `t`

```elixir
@type t() :: %Bourse.OrderBook{
  asks: [level()],
  bids: [level()],
  datetime: String.t() | nil,
  info: map() | nil,
  nonce: integer() | nil,
  symbol: String.t() | nil,
  timestamp: integer() | nil
}
```

# `best_ask`

```elixir
@spec best_ask(t()) :: number() | nil
```

Returns the best (lowest) ask price, or nil if empty/malformed.

# `best_bid`

```elixir
@spec best_bid(t()) :: number() | nil
```

Returns the best (highest) bid price, or nil if empty/malformed.

# `schema`

```elixir
@spec schema() :: map()
```

JSON Schema for the OrderBook unified type.

# `spread`

```elixir
@spec spread(t()) :: number() | nil
```

Returns the spread (best ask price - best bid price), or nil if either side is empty/malformed.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
