1- from typing import Any , Dict , Optional
1+ """Module for managing a market book for a financial instrument.
2+
3+ Provides the Book class for accessing market depth information.
4+ """
5+
6+ from __future__ import annotations
7+
8+ import logging
9+ from typing import Any
210
311import MetaTrader5 as Mt5
412
13+ # Configure logging
14+ logger = logging .getLogger (__name__ )
15+ logger .setLevel (logging .INFO )
16+
17+ # Create console handler with formatting
18+ console_handler = logging .StreamHandler ()
19+ formatter = logging .Formatter ("%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
20+ console_handler .setFormatter (formatter )
21+ logger .addHandler (console_handler )
22+
523
624class Book :
725 """Represents a market book for a financial instrument."""
826
927 def __init__ (self , symbol : str ) -> None :
10- """Initialize the Book object.
28+ """Initialize a Book object.
1129
1230 Args:
1331 symbol (str): The financial instrument symbol.
@@ -17,15 +35,15 @@ def __init__(self, symbol: str) -> None:
1735 """
1836 self .symbol : str = symbol
1937 if Mt5 .market_book_add (self .symbol ):
20- print (f"The symbol { self .symbol } was successfully added to the market book." )
38+ logger . info (f"The symbol { self .symbol } was successfully added to the market book." )
2139 else :
22- print (f"Error adding { self .symbol } to the market book. Error: { Mt5 .last_error ()} " )
40+ logger . error (f"Error adding { self .symbol } to the market book. Error: { Mt5 .last_error ()} " )
2341
24- def get (self ) -> Optional [ Dict [ str , Any ]] :
42+ def get (self ) -> dict [ str , Any ] | None :
2543 """Get the market book for the financial instrument.
2644
2745 Returns:
28- Optional[Dict[ str, Any]]: A dictionary representing the market book, or None if unsuccessful .
46+ dict[ str, Any] | None: The market book data if successful, None otherwise .
2947 """
3048 return Mt5 .market_book_get (self .symbol )
3149
0 commit comments