mt5.market_book_add() in MetaTrader5 Python: subscribe to market depth

Subscribes the terminal to market depth, the order book, for one symbol. You need it before market_book_get() returns anything. Returns True or False.

Signature

mt5.market_book_add(symbol)

What it does

Market depth shows the buy and sell levels the broker publishes, with a volume at each price. The terminal only collects it for symbols you subscribe to.

Subscribe once, read with market_book_get() as often as you need, and call market_book_release() when you are done.

Parameters

ParameterWhat it is
symbolThe symbol name. Required.

What it returns

  • True when the subscription worked.
  • False when it did not. Check mt5.last_error().

Example

import MetaTrader5 as mt5

if not mt5.initialize():
    raise SystemExit(mt5.last_error())

if not mt5.market_book_add("EURUSD"):
    raise SystemExit(f"no depth subscription: {mt5.last_error()}")
# ... read with mt5.market_book_get("EURUSD") ...
mt5.market_book_release("EURUSD")
mt5.shutdown()

Common mistakes

  • A subscription can work and still bring no data. Many brokers publish no depth for forex or CFDs.
  • Release the subscriptions you no longer need. Each one adds load to the terminal.

The same with Tickwire on Linux

The package needs a Windows terminal on the same machine. Tickwire runs the terminal for you and gives you a REST API, so the code below runs on Linux, macOS or a server.

Tickwire's current-book route reads the depth in one call, with no separate subscribe step. A symbol whose broker publishes no depth answers 404 depth_unavailable, never an empty book made to look real.

Market depth is MT5 only. On an MT4 account the route answers not_supported_on_mt4. Check features.marketDepth on the capabilities route first.

Related error codes

All MetaTrader5 Python functions

MT5 from Python, on any machine

One REST API for MT4 and MT5, with idempotent orders and an audit log. Read the MT5 Python API page or the quickstart.