Skip to main content

Dynamo MetaTrader API

Project description

DMTAPI

A Python package for interacting with trading accounts and managing trades.

Installation

pip install dmtapi

Quick Start

from dmtapi import DMTAPI
from dmtapi.models.trade_model import TradeSetup, TradeDirection, TakeProfit

# Initialize the API
api = DMTAPI(api_key="your_api_key")

# Get account information
account_info = await api.get_account_info(
    access_token="your_access_token",
)

# alternatively use api key
# account_info = await api.get_account_info(
#     login=123
#     server="your_server
# )

# Create and execute a trade
setup = TradeSetup(
    symbol="EURUSD",
    volume=0.1,
    direction=TradeDirection.buy,
    stop_loss=1.0500,
    take_profits=[
        TakeProfit(price=1.0600, close_pct=1.0)
    ]
)

result = await api.open_trade(
    setup=setup,
    access_token="your_access_token",
    login=12345,
    server="your_server"
)

API Reference

DMTAPI Class

The main class for interacting with the trading API.

Methods

  • get_account_info(access_token=None, login=None, server=None, api_key=None) -> TraderInfo

    • Retrieves information about a specific trading account.
    • Returns a TraderInfo object containing account details.
  • get_all_accounts(api_key=None) -> list[TraderInfo]

    • Retrieves information about all available trading accounts.
    • Returns a list of TraderInfo objects.
  • open_trade(setup, access_token, login, server, api_key=None) -> dict

    • Opens a new trade based on the provided setup.
    • Returns a dictionary containing the trade result.

Models

TradeSetup

Represents a trade setup configuration.

Fields:

  • symbol: str - Trading symbol (e.g., "EURUSD")
  • volume: float - Trading volume (0-100)
  • direction: TradeDirection - Trade direction (buy/sell)
  • magic: int - Magic number for trade identification (optional)
  • entry_price: float - Entry price for the trade
  • stop_loss: float - Stop loss price
  • sl_as_pip: float - Stop loss in pips (takes priority over sl_as_pct)
  • sl_as_pct: float - Stop loss as percentage
  • take_profits: list[TakeProfit] - List of take profit levels
  • deviation: int - Maximum price deviation (0-100)

TakeProfit

Represents a take profit configuration.

Fields:

  • price: float - Take profit price level
  • close_pct: float - Percentage of position to close (0-1)
  • tp_as_pip: float - Take profit in pips
  • tp_as_pct: float - Take profit as percentage

TraderInfo

Represents trading account information.

Fields:

  • name: str - Account name
  • server: str - Trading server
  • login: int - Account login
  • server_type: str - Server type (default: "mt5")
  • access_token: str - Access token
  • inception_date: datetime - Account creation date
  • starting_balance: float - Initial account balance
  • currency: str - Account currency
  • leverage: int - Account leverage
  • balance: float - Current balance
  • equity: float - Current equity
  • margin: float - Used margin
  • margin_free: float - Free margin
  • status: AccountStatusEnum - Account connection status

Examples

Getting Account Information

api = DMTAPI(api_key="your_api_key")

# Using access token
account = await api.get_account_info(access_token="your_access_token")

# Using login and server
# account = await api.get_account_info(
#     login="your_login",
#     server="your_server"
# )

print(f"Account Balance: {account.balance}")
print(f"Account Equity: {account.equity}")

Opening a Trade

from dmtapi.models.trade_model import TradeSetup, TradeDirection, TakeProfit

# Create trade setup
setup = TradeSetup(
    symbol="EURUSD",
    volume=0.1,
    direction=TradeDirection.buy,
    stop_loss=1.0500,
    take_profits=[
        TakeProfit(price=1.0600, close_pct=0.5),
        TakeProfit(price=1.0700, close_pct=0.5)
    ]
)

# Open trade
result = await api.open_trade(
    setup=setup,
    access_token="your_access_token",
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dmtapi-2025.2.dev3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dmtapi-2025.2.dev3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file dmtapi-2025.2.dev3.tar.gz.

File metadata

  • Download URL: dmtapi-2025.2.dev3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for dmtapi-2025.2.dev3.tar.gz
Algorithm Hash digest
SHA256 dac5cd2345fe3521e2eb3405a4d818c2a974508896a084dfd76955a95148fef5
MD5 6183f99d5fa243633b26640cbea443f1
BLAKE2b-256 260cd94851bed115e93aaeb182820368337bc26d2823bda7b4666fe4e3aa227b

See more details on using hashes here.

File details

Details for the file dmtapi-2025.2.dev3-py3-none-any.whl.

File metadata

  • Download URL: dmtapi-2025.2.dev3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for dmtapi-2025.2.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 946a68748048effe656dab80f41743b61b26627d6508d533ff9d53ee01605f69
MD5 aabd6b904f24397b693fcd72ca2a4488
BLAKE2b-256 000c522de818c439ee9c9d2023616334febb0b2e77d7e2584f3a45c451a8d1be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page