Skip to content

Market Book

Level 2 order book (Depth of Market) data.


Models

BookEntry

BookEntry

Bases: BaseModel

A single entry in the market depth (Depth of Market) for a symbol.

Wraps the raw BookInfo struct returned by mt5.market_book_get(). Each entry represents one price level in the order book, which may be a limit order or a market order on either the buy or sell side.

ATTRIBUTE DESCRIPTION
type

Whether this entry is a buy or sell order, and whether it is a limit or market order.

TYPE: BookType

price

Price level of this order book entry.

TYPE: float

volume

Volume available at this price level (integer lots).

TYPE: int

volume_real

Volume available at this price level (fractional lots).

TYPE: float

is_buy property

is_buy: bool

Whether this entry is on the buy side (limit or market).

is_sell property

is_sell: bool

Whether this entry is on the sell side (limit or market).

is_market property

is_market: bool

Whether this entry represents a market order rather than a limit order.


Service

MarketBookService

MarketBookService

Manages market depth (DOM) subscriptions and snapshots for the MT5 terminal.

Wraps mt5.market_book_add(), mt5.market_book_get(), and mt5.market_book_release() via call_mt5, parses raw BookInfo structs into BookEntry models, and returns Result[T].


Usage

# Subscribe to market book
add = mt5.market_book_add("EURUSD")
if add.success and add.data:
    # Read the book
    res = mt5.market_book_get("EURUSD")
    if res.success:
        for entry in res.data:
            side = "BUY" if entry.is_buy else "SELL"
            print(f"{side}: {entry.price} @ {entry.volume_real}")

    # Release when done
    mt5.market_book_release("EURUSD")