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.1.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.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file dmtapi-2025.1.tar.gz.

File metadata

  • Download URL: dmtapi-2025.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for dmtapi-2025.1.tar.gz
Algorithm Hash digest
SHA256 692116278d35bf757174e5b09042d6d6a9921e7794f76b9d7fa2d9cfc4492970
MD5 07beee761fbe1f39bdf4bccaf8c1661a
BLAKE2b-256 6e8b3d9df9978442b3e052efe0b8a0f50cf2693919ee6b930ececeed6fa80776

See more details on using hashes here.

File details

Details for the file dmtapi-2025.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dmtapi-2025.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9038b27072d996f7ca9df8950668f1ed5151fd14e7f25d2986c1c4020356ae24
MD5 998cee10ac64fa7ff931051f06400897
BLAKE2b-256 4f4b139e6bf018b01641e32c577bff4cde851b03022d61ed4e21869643e781ff

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