Skip to content

Account

Account information models and services.


Models

AccountInfo

AccountInfo

Bases: BaseModel

Trading account details from MetaTrader 5.

Wraps the raw AccountInfo struct returned by mt5.account_info(). Contains both static account properties (leverage, currency) and live financial state (balance, equity, margin).

ATTRIBUTE DESCRIPTION
login

Account number.

TYPE: int

trade_mode

Account type (demo, contest, real) as an MT5 integer.

TYPE: int

leverage

Account leverage (e.g. 100 for 1:100).

TYPE: int

limit_orders

Maximum number of active pending orders allowed.

TYPE: int

margin_so_mode

Stop-out mode (percent or money) as an MT5 integer.

TYPE: int

trade_allowed

Whether trading is permitted on this account.

TYPE: bool

trade_expert

Whether Expert Advisors are permitted to trade.

TYPE: bool

margin_mode

Margin calculation mode as an MT5 integer.

TYPE: int

currency_digits

Number of decimal places for the account currency.

TYPE: int

fifo_close

Whether positions must be closed in FIFO order.

TYPE: bool

balance

Account balance in account currency.

TYPE: float

credit

Credit facility amount.

TYPE: float

profit

Current floating profit/loss across all open positions.

TYPE: float

equity

Effective account value (balance + profit + credit).

TYPE: float

margin

Margin currently in use.

TYPE: float

margin_free

Free margin available for new positions.

TYPE: float

margin_level

Margin level as a percentage (equity / margin * 100).

TYPE: float

margin_so_call

Margin call level (percent or money, per margin_so_mode).

TYPE: float

margin_so_so

Stop-out level (percent or money, per margin_so_mode).

TYPE: float

margin_initial

Initial margin requirement.

TYPE: float

margin_maintenance

Maintenance margin requirement.

TYPE: float

assets

Total assets.

TYPE: float

liabilities

Total liabilities.

TYPE: float

commission_blocked

Commission reserved for open positions.

TYPE: float

name

Account holder name.

TYPE: str

server

Broker server name.

TYPE: str

currency

Account currency code (e.g. "USD").

TYPE: str

company

Broker company name.

TYPE: str

margin_used_percent property

margin_used_percent: float

Margin in use as a percentage of equity.

Returns 0.0 when equity is zero to avoid division by zero.

RETURNS DESCRIPTION
float

Margin usage percentage (0โ€“100+).

equity_to_balance_ratio property

equity_to_balance_ratio: float

Ratio of equity to balance, indicating unrealised P&L impact.

A value above 1.0 means open positions are in profit; below 1.0 means they are in loss. Returns 0.0 when balance is zero.

RETURNS DESCRIPTION
float

Equity / balance ratio.


Service

AccountService

AccountService

Retrieves trading account information from the MT5 terminal.

Wraps mt5.account_info() via call_mt5, parses the raw AccountInfo struct into a typed model, and returns Result[AccountInfo].


Usage

res = mt5.account_info()

if res.success:
    acc = res.data
    print(f"Balance: {acc.balance} {acc.currency}")
    print(f"Equity: {acc.equity}")
    print(f"Margin used: {acc.margin_used_percent:.1f}%")