darwinex / dwxconnect

Seamlessly link any Trading Strategy in ANY programming language to Darwinex liquidity via MetaTrader 4 or 5. DWX Connect is your very own, fully customizable Trading API!
BSD 3-Clause "New" or "Revised" License
175 stars 89 forks source link
algorithmic-trading asset-management capital-raising csharp java python trading-strategies

DWX Connect - Seamlessly Link Any Trading Strategy to Darwinex

Need help? Join the Darwinex Collective Slack for code updates, Q&A and more.

About Darwinex

Darwinex is a UK FCA-Regulated FinTech, Broker & Asset Manager. We provide cost-effective access to Stocks, Futures, FX and CFDs via Trader Workstation (TWS), TWS API, FIX API, MetaTrader 4 and 5, and empower talented traders with the fastest route to attract investor capital and charge performance fees.

Please take a moment to read our Risk Disclosure here

Click here to visit our Trader Hall of Fame * ranked by Performance Fees earned (over €3 million paid to date)

Click here to Open a Darwinex Trading Account

Table of Contents

Introduction

DWX Connect enables anyone to write trading strategies in any programming language and trade them at Darwinex. It provides functionality to subscribe to Tick and Bar data, as well as to Trade via MetaTrader 4 or 5 without having to code algorithms in MQL.

Its simple, file-based communication mechanism also provides an easy starting point for implementations in other programming languages.

For simplicity, we will refer to the non-MQL side of this project as the "Python side" in this README.

One-off Installation Steps

  1. Please download the code from this GitHub repository.

  2. Download the MT4/MT5 Server EA (dwx_server_mt4.mq4 or dwx_server_mt5.mq5, depending on whether you're using MT4 or MT5) and copy it into the /MQL4/Experts or /MQL5/Experts directory (File -> Open Data Folder).

  3. Double click on the MT4/MT5 EA file to open it in MetaEditor. Press F7 to compile the file. Restart MT4/MT5 or Right-Click -> Refresh in the Navigator window.

  4. Attach the EA to any chart. Change the input parameters if needed, for example, MaximumOrders and MaximumLotSize if you want to trade larger sizes.

  5. Copy the python folder to your working directory.

  6. Open the file dwx_client_example.py and change the MT4_files_dir variable to the full path of the /MQL4/Files or /MQL5/Files directory. On Windows the path usually looks similar to this (<username> is your username):
    C:/Users/<username>/AppData/Roaming/MetaQuotes/Terminal/3B534B10135CFEDF8CD1AAB8BD994B13/MQL4/Files

    However, on macOS it could look like this:
    /Users/<username>/Library/Application Support/MetaTrader 4/Bottles/metatrader4/drive_c/Program Files/MetaTrader 4/MQL4/Files

    And on Linux like this:
    /home/<username>/.wine/drive_c/Program Files (x86)/Darwinex MT4/MQL4/Files

  7. The example script will just try to subscribe to EURUSD and GBPUSD, and print some information on every tick. You can run the script with:

    python dwx_client_example.py

    If you set open_test_trades=True, it will also open multiple test trades.

    Don't do this on a live account! It is best to open a Darwinex demo account for testing.

Configuration

MQL side: For most applications it is only necessary to modify the two input parameters MaximumOrders and MaximumLotSize.

The full list of input parameters for the MetaTrader Server EA (MT4 or MT5) is as follows:

MetaTrader Settings

Python side:

Example Usage

The best way to get started is to use the example DWX_Connect client.

It defines various functions which can be used to react to data changes from MetaTrader:

Video Tutorials

Click the image below to watch a live demonstration of DWX Connect:

DWX Connect: Seamlessly Link Any Trading Strategy to Darwinex

Available Functions:

Stored Information:

The following dictionaries can be used to access the available information directly (e.g. through self.dwx.open_orders):

Data Functions:

Order Functions:

In MT4 the term 'order' refers to both, pending orders and filled positions.

To keep the functionality consistent between Python/MT4/MT5, we also do not differentiate between pending orders and positions on the Python side.

Filled positions are just orders with type 'buy' or 'sell'.

License

BSD 3-Clause License

Copyright (c) 2019, Darwinex. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.