Skip to main content

Dynamo MetaTrader API

Project description

DMTAPI

A comprehensive Python package for managing trading accounts and executing trades through a unified API interface. This package provides an asynchronous interface for interacting with trading platforms.

PyPI version Python versions

Features

  • Asynchronous API implementation
  • Comprehensive trading account management
  • Real-time symbol price information
  • Trade execution with multiple take-profit levels
  • Order and position tracking
  • Detailed account information retrieval

Installation

pip install dmtapi

Quick Start

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


async def main():
    # Initialize the API with your credentials
    api = DMTAPI(
        api_key="your_api_key",
        api_base_url="https://api.example.com"
    )

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

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

    result = await api.trade.open(
        setup=setup,
        access_token="your_access_token"
    )

API Structure

The DMTAPI is organized into several modules for different functionalities:

  • account: Account management and information
  • symbol: Symbol information and pricing
  • trade: Trade execution and management
  • order: Order history and position tracking

Account Management

# Get specific account information
account_info = await api.account.info(
    access_token="your_access_token"
)

# Get all accounts
all_accounts = await api.account.all()

Symbol Operations

# Get symbol price
price = await api.symbol.price(
    symbol="EURUSD",
    access_token="your_access_token"
)

# Get symbol information
symbol_info = await api.symbol.info(
    symbol="EURUSD",
    access_token="your_access_token"
)

Trade Operations

# Open a trade
result = await api.trade.open(
    setup=trade_setup,
    access_token="your_access_token"
)

# Close a position
result = await api.trade.close(
    ticket=12345,
    access_token="your_access_token"
)

Order Management

# Get position history
history = await api.order.history(
    access_token="your_access_token"
)

# Get pending orders
pending = await api.order.pending(
    access_token="your_access_token"
)

# Get open positions
positions = await api.order.positions(
    access_token="your_access_token"
)

Authentication

The API supports two authentication methods:

  1. Access Token Authentication:
api = DMTAPI(
    api_key="your_api_key",
    api_base_url="https://api.example.com",
    access_token="your_access_token"
)
  1. Login/Server Authentication:
# Use login and server for specific requests
account_info = await api.account.info(
    login=12345,
    server="trading_server",
    api_key="your_api_key"
)

Models

TradeSetup

from dmtapi.models.trade_model import TradeSetup, TakeProfit

setup = TradeSetup(
    symbol="EURUSD",  # Trading symbol
    volume=0.1,  # Trading volume
    direction="buy",  # Trade direction (buy/sell)
    stop_loss=1.0500,  # Stop loss price
    take_profits=[  # Multiple take profit levels
        TakeProfit(price=1.0600, close_pct=0.5),
        TakeProfit(price=1.0700, close_pct=0.5)
    ]
)

TraderInfo

Provides comprehensive account information including:

  • Account details (name, server, login)
  • Balance and equity
  • Margin information
  • Account status

Error Handling

The API uses standard Python exceptions for error handling:

try:
    result = await api.trade.open(
        setup=trade_setup,
        access_token="your_access_token"
    )
except ValueError as e:
    print(f"Invalid parameters: {e}")
except Exception as e:
    print(f"An error occurred: {e}")

Examples

For more detailed examples, check the examples directory in the repository.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: dmtapi-2025.3.dev0.tar.gz
  • Upload date:
  • Size: 12.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.3.dev0.tar.gz
Algorithm Hash digest
SHA256 2c3ae29d723dc34a087a8380b4c9c33109ee23d84b53b68a03fc41aa7ed73444
MD5 9e5cbdc9203e628c529e27b70c65e9ed
BLAKE2b-256 8c1320ebcd3ab7073b0ac797a6b8574c084e00e03710592d1dbef02247ca5719

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dmtapi-2025.3.dev0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 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.3.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b42b7ec5a9c716293875cbc48ed9088eaca2b61b24bf4e35561efa3c71d8809
MD5 0a66e618fd9e5589cfebcdded7d0f4c9
BLAKE2b-256 a724e10daa646f9dab51c3d68016605fd2516e46adc0040b7dc55f018f6d0d92

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