Skip to content

Book

Module for managing a market book for a financial instrument.

Provides the Book class for accessing market depth information.

Book #

Book(symbol)

Represents a market book for a financial instrument.

Parameters:

Name Type Description Default
symbol str

The financial instrument symbol.

required

Returns:

Type Description
None

None

Source code in mqpy\book.py
def __init__(self, symbol: str) -> None:
    """Initialize a Book object.

    Args:
        symbol (str): The financial instrument symbol.

    Returns:
        None
    """
    self.symbol: str = symbol
    if Mt5.market_book_add(self.symbol):
        logger.info(f"The symbol {self.symbol} was successfully added to the market book.")
    else:
        logger.error(f"Error adding {self.symbol} to the market book. Error: {Mt5.last_error()}")

get #

get()

Get the market book for the financial instrument.

Returns:

Type Description
dict[str, Any] | None

dict[str, Any] | None: The market book data if successful, None otherwise.

Source code in mqpy\book.py
def get(self) -> dict[str, Any] | None:
    """Get the market book for the financial instrument.

    Returns:
        dict[str, Any] | None: The market book data if successful, None otherwise.
    """
    return Mt5.market_book_get(self.symbol)

release #

release()

Release the market book for the financial instrument.

Returns:

Name Type Description
bool bool

True if successful, False otherwise.

Source code in mqpy\book.py
def release(self) -> bool:
    """Release the market book for the financial instrument.

    Returns:
        bool: True if successful, False otherwise.
    """
    return Mt5.market_book_release(self.symbol)