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.dev0.tar.gz (7.9 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.dev0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dmtapi-2025.2.dev0.tar.gz
  • Upload date:
  • Size: 7.9 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.dev0.tar.gz
Algorithm Hash digest
SHA256 25de3ecae93df3e2482e0ddd7c2344d5e575d077ebf4585a5e69c1e0662df724
MD5 542b27f3bd1041b5d06e0f1a1a60913b
BLAKE2b-256 e2a740053ea35ae666f5355d04b2ce4580f7f6d04ae5a0802d38113afb7fb05c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dmtapi-2025.2.dev0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fe756f8d2f33d90d306165d5ecdcbe6428de436cbf1472f5f796d7f6d716029
MD5 e724f97078ca233b45da468a110895d7
BLAKE2b-256 516140ae9574e2fd4a9e52d2d9b9a4c19b886576c4b46bf81cbc667ba55b1fa8

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