> ## Documentation Index
> Fetch the complete documentation index at: https://molelcule.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch Order Books and Trade History via Molecule API

> Retrieve order book snapshots, aggregated cross-venue books, recent trades, trade prints, and market statistics using the Molecule markets API.

The order book and trade history methods on `client.markets` give you the depth and execution data you need to price orders accurately and monitor market activity. Use `markets.book()` or `markets.orderbook()` for a snapshot of a single venue instrument, `markets.generic_asset_orderbook()` for a consolidated view across all venues carrying the same underlying asset, and `markets.trades()`, `markets.prints()`, and `markets.stats()` to access fill history and summary statistics.

***

## markets.book

Fetch a lightweight Level 2 order book snapshot for a specific venue instrument. Returns the current resting bids and asks with price and size at each level.

```python theme={"dark"}
import os
from molecule import Molecule

client = Molecule(
    base_url=os.environ["MOLECULE_BASE_URL"],
    key_id=os.environ["MOLECULE_KEY_ID"],
    private_key=os.environ["MOLECULE_PRIVATE_KEY"],
)

book = client.markets.book(instrument_id=42)

print("Bids:", book["bids"][:5])
print("Asks:", book["asks"][:5])
```

**Endpoint:** `GET /v1/markets/{id}/book`

<ParamField path="instrument_id" type="integer | string" required>
  The venue-specific instrument ID to retrieve the order book for.
</ParamField>

***

## markets.orderbook

Retrieve the full order book for a venue instrument from the `/v1/orderbooks` endpoint. Returns bids and asks with price and quantity at each level.

```python theme={"dark"}
book = client.markets.orderbook(instrument_id=42)

for level in book["bids"]:
    print(f"  {level['price']} x {level['qty']}")
```

**Endpoint:** `GET /v1/orderbooks/{id}`

<ParamField path="instrument_id" type="integer | string" required>
  The venue-specific instrument ID.
</ParamField>

<Note>
  `markets.book()` and `markets.orderbook()` both return order book data for a single venue instrument but hit different endpoints. Use `markets.book()` for a lightweight snapshot and `markets.orderbook()` when you need the full depth from the `/v1/orderbooks` service.
</Note>

***

## markets.generic\_asset\_orderbook

Retrieve an aggregated order book that consolidates depth across all venues carrying the same underlying generic asset. This is the correct endpoint to use when you intend to route using `BEST_PRICE` or `SPLIT` mode, since those routing modes operate on the generic asset level rather than on a specific venue instrument.

```python theme={"dark"}
book = client.markets.generic_asset_orderbook(
    generic_asset_id=100,
    subaccount_id=os.environ["MOLECULE_SUBACCOUNT_ID"],
)

print("Best bid:", book["bids"][0] if book["bids"] else "—")
print("Best ask:", book["asks"][0] if book["asks"] else "—")
```

**Endpoint:** `GET /v1/orderbooks/generic-asset/{id}`

<ParamField path="generic_asset_id" type="integer" required>
  The generic asset ID shared across venue-specific instruments that represent the same underlying market.
</ParamField>

<ParamField query="subaccount_id" type="string">
  Your subaccount identifier. Include this to receive fee-adjusted pricing relevant to your account tier.
</ParamField>

<Note>
  `markets.generic_asset_orderbook()` is also accessible as `markets.aggregated_book()` — both names call the same method and endpoint. Use whichever is clearer at your call site.
</Note>

***

## markets.trades

Retrieve the most recent exchange-confirmed trades for a specific venue instrument. Each record represents a completed fill at a given price and size.

```python theme={"dark"}
trades = client.markets.trades(instrument_id=42, limit=100)

for trade in trades:
    print(trade["price"], trade["qty"], trade["side"], trade["timestamp"])
```

**Endpoint:** `GET /v1/markets/{id}/trades`

<ParamField path="instrument_id" type="integer | string" required>
  The venue-specific instrument ID.
</ParamField>

<ParamField query="limit" type="integer" default="100">
  Maximum number of trade records to return.
</ParamField>

***

## markets.prints

Query the public trade-print stream for recent fills across all instruments or for a specific instrument. This endpoint serves the same data available over the `/v1/ws/tradeprints` WebSocket stream.

```python theme={"dark"}
prints = client.markets.prints(instrument_id=42, limit=100)

for p in prints:
    print(p["price"], p["qty"], p["timestamp"])
```

**Endpoint:** `GET /v1/tradeprints`

<ParamField query="instrument_id" type="integer | string">
  Filter trade prints to a specific instrument. Omit to retrieve prints across all instruments.
</ParamField>

<ParamField query="limit" type="integer" default="100">
  Maximum number of trade prints to return.
</ParamField>

<Info>
  Use `markets.prints()` for a historical snapshot of recent public fills. For a continuous real-time feed, subscribe to the `/v1/ws/tradeprints` WebSocket stream using `client.iter_ws("/v1/ws/tradeprints")`.
</Info>

***

## markets.stats

Fetch summary statistics for a venue instrument, including 24-hour volume, last traded price, and open interest.

```python theme={"dark"}
stats = client.markets.stats(instrument_id=42)

print("Volume 24h:", stats.get("volume_24h"))
print("Last price:", stats.get("last_price"))
print("Open interest:", stats.get("open_interest"))
```

**Endpoint:** `GET /v1/markets/{id}/stats`

<ParamField path="instrument_id" type="integer | string" required>
  The venue-specific instrument ID to retrieve statistics for.
</ParamField>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.