- Installing Python and the MetaTrader5 package
- Overview of functions of the MetaTrader5 package for Python
- Connecting a Python script to the terminal and account
- Error checking: last_error
- Getting information about a trading account
- Getting information about the terminal
- Getting information about financial instruments
- Subscribing to order book changes
- Reading quotes
- Reading tick history
- Calculating margin requirements and evaluating profits
- Checking and sending a trade order
- Getting the number and list of active orders
- Getting the number and list of open positions
- Reading the history of orders and deals
Getting information about a trading account
The account_info function obtains full information about the current trading account.
namedtuple account_info()
The function returns information as a structure of named tuples (namedtuple). In case of an error, the result is None.
Using this function, you can use one call to get all the information that is provided by AccountInfoInteger, AccountInfoDouble, and AccountInfoString in MQL5, with all variants of supported properties. The names of the fields in the tuple correspond to the names of the enumeration elements without the "ACCOUNT_" prefix, reduced to lowercase.
The following script MQL5/Scripts/MQL5Book/Python/accountinfo.py is included with the book.
import MetaTrader5 as mt5
|
The result should be something like this.
AccountInfo(login=25115284, trade_mode=0, leverage=100, limit_orders=200, margin_so_mode=0, ... Show account_info()._asdict(): login=25115284 trade_mode=0 leverage=100 limit_orders=200 margin_so_mode=0 trade_allowed=True trade_expert=True margin_mode=2 currency_digits=2 fifo_close=False balance=99511.4 credit=0.0 profit=41.82 equity=99553.22 margin=98.18 margin_free=99455.04 margin_level=101398.67590140559 margin_so_call=50.0 margin_so_so=30.0 margin_initial=0.0 margin_maintenance=0.0 assets=0.0 liabilities=0.0 commission_blocked=0.0 name=MetaQuotes Dev Demo server=MetaQuotes-Demo currency=USD company=MetaQuotes Software Corp. |