Skip to content

Inverted account_type mapping in get_account_type.py (all three trade_mode values swapped) #41

Description

@rbramwell

Description

get_account_type() in metatrader_client/account/get_account_type.py has
all three trade_modeaccount_type mappings inverted.

Current code (v0.5.1)

# metatrader_client/account/get_account_type.py
def get_account_type(connection) -> str:
    account_info = get_account_info(connection)
    trade_mode = account_info["trade_mode"]
    if trade_mode == 0:
        return "real"
    elif trade_mode == 1:
        return "demo"
    elif trade_mode == 2:
        return "contest"
    else:
        return f"unknown ({trade_mode})"

Expected behavior

MT5 Python API defines ACCOUNT_TRADE_MODE as:

  • 0 = ACCOUNT_TRADE_MODE_DEMO
  • 1 = ACCOUNT_TRADE_MODE_CONTEST
  • 2 = ACCOUNT_TRADE_MODE_REAL

(Source: MetaTrader5 Python docs)

Observed vs expected

trade_mode MT5 meaning Package returns Correct
0 DEMO \real\ \demo\
1 CONTEST \demo\ \contest\
2 REAL \contest\ \real\

Impact

  • Demo accounts are reported as "real" in get_trade_statistics() / get_account_info() MCP tool responses
  • Real accounts would be reported as "contest"
  • All downstream consumers using account_type to make decisions get the wrong signal

Fix

def get_account_type(connection) -> str:
    account_info = get_account_info(connection)
    trade_mode = account_info["trade_mode"]
    if trade_mode == 0:
        return "demo"
    elif trade_mode == 1:
        return "contest"
    elif trade_mode == 2:
        return "real"
    else:
        return f"unknown ({trade_mode})"

Also note: the docstring in get_account_info.py line 12 also has a wrong mapping:

- trade_mode: Account trade mode (0-real, 1-demo, 2-contest)

This should be 0-demo, 1-contest, 2-real.

Discovered while running metatrader-mcp-server against a MetaQuotes-Demo
account — get_account_info returned "account_type": "real" despite
the account being demo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions