-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathbook.py
41 lines (31 loc) · 1.12 KB
/
book.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from typing import Optional
import MetaTrader5 as Mt5
class Book:
"""Represents a market book for a financial instrument."""
def __init__(self, symbol: str) -> None:
"""
Initialize the Book object.
Args:
symbol (str): The financial instrument symbol.
Returns:
None
"""
self.symbol: str = symbol
if Mt5.market_book_add(self.symbol):
print(f"The symbol {self.symbol} was successfully added to the market book.")
else:
print(f"Error adding {self.symbol} to the market book. Error: {Mt5.last_error()}")
def get(self) -> Optional[dict]:
"""
Get the market book for the financial instrument.
Returns:
Optional[dict]: A dictionary representing the market book, or None if unsuccessful.
"""
return Mt5.market_book_get(self.symbol)
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)