Broker API HubMenu

MT5 Python market_book_add()

functionmarket_book_add()MetaTrader5 Python packageMarket depth

Subscribes the terminal to changes in the depth of market for one instrument, which is what makes market_book_get() return data.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialmql5.comchecked

This is a Python function, not an HTTP endpoint. It has no method, no path and no address to send a request to: the package talks to a MetaTrader 5 terminal running on the same computer.

This subscribes the terminal, not the Python program: nothing is pushed to Python. The program still has to call market_book_get() to read the book.

Signature

The form of the call on the vendor's page, with the vendor's comments taken out.

market_book_add(
  symbol
)

Arguments

NameTypeDescription
symbolrequiredNot statedThe instrument's name. Given without a parameter name.

Return value

Type
bool
What comes back
True on success, False otherwise.

Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. No credential is typed into it: where one is needed it is read from an environment variable on your own machine. Nothing is entered on this site.

import MetaTrader5 as mt5

if not mt5.initialize():
    raise SystemExit(f"initialize() failed: {mt5.last_error()}")

if mt5.market_book_add("EURUSD"):
    print(mt5.market_book_get("EURUSD"))
    mt5.market_book_release("EURUSD")

mt5.shutdown()