Git Product home page Git Product logo

darwinex / dwxconnect Goto Github PK

View Code? Open in Web Editor NEW
158.0 9.0 84.0 712 KB

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!

License: BSD 3-Clause "New" or "Revised" License

C# 17.27% Java 15.91% MQL4 16.61% MQL5 33.67% Python 16.54%
algorithmic-trading trading-strategies python csharp java asset-management capital-raising

dwxconnect's Introduction

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:

  • MILLISECOND_TIMER - The interval in which the EA checks for new prices and changes in the open orders (in milliseconds).

  • numLastMessages - The number of messages that will be stored in the message file. If it is too small, it could happen that the Python side misses a message. If it is too large, it could lead to higher CPU demand. Messages are mostly used for feedback and debug purposes, so they are not critical.

  • openChartsForBarData - If true, it will open charts for symbol/timeframe combinations that are subscribed to bar data. MetaTrader does not automatically update all bar data in the background instantly. By having the charts open, we force MetaTrader to update the data more quickly reducing the delay on a new bar.

  • openChartsForHistoricData - Same as the last parameter, but for symbol/timeframe combinations for which a request for historic data was sent.

  • MaximumOrders - The maximum number of orders allowed. If the maximum number of orders is open and an order is sent from the Python side, it will not open the order, but return an error message.

  • MaximumLotSize - The maximum lot size allowed for a single order (not all orders together).

  • SlippagePoints - This value will be used in the OrderSend() function. This is usually ignored by the broker, but still available as a parameter for completeness.

  • lotSizeDigits - The digits to which the lot size should be rounded. The default is 2 for Forex symbols. But if you trade Stocks or Indices there could be symbols that do not allow lot sizes as small as 0.01.

MetaTrader Settings

Python side:

  • sleep_delay - The time interval in which the Python side will check the files (in seconds). The default value is0.005 (5 milliseconds).

  • max_retry_command_seconds - If you send multiple commands in a short time, it could happen that the Python side is not able to write to the command file when the mql side is just reading it. The parameter max_retry_command_seconds can be used to define the period in which the Python side will retry to send the commend.

  • load_orders_from_file - If true, it will load the orders from a file on initialization. Otherwise it would trigger the on_order_event() function after a restart of the Python program if there are any open orders because it would not know about them. However, it will only know the last state that was sent to the Python side. If the mql server EA is turned off during order operations, it would only notice them when both are turned on again.

  • verbose - If true, it will print more debug information.

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:

  • on_tick(symbol, bid, ask) - is triggered every time the Python side registers a change in the current bid/ask prices. For easier access the symbol and the current bid/ask prices are passed along. However, you can also always access them through self.dwx.market_data from any other function.

  • on_bar_data(symbol, time_frame, time, open_price, high, low, close_price, tick_volume) - is triggered when the Python side registers new bar data.

  • on_historic_data(symbol, time_frame, data) - is triggered when the Python side registers a response from a historic data request.

  • on_historic_trades() - is triggered when the Python side registers a response from a historic trades request. The historic trades can be accessed via self.dwx.historic_trades.

  • on_message(message) - is triggered when the Python side registers a new message from MetaTrader. The message is a dictionary with a 'type' that can either be 'INFO' or 'ERROR'. Error messages have an 'error_type' and a 'description' while info messages only contain a 'message'.

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):

  • open_orders - contains the open orders. The order ticket is used as the key for this dictionary.
  • account_info - contains the account information such as account name, number, equity, balance, leverage and free margin.
  • market_data - contain the current bid/ask prices for all subscribed symbols as well as the tick value.
  • bar_data - contains the latest bar data. This is updated continually if subscribed to specific bar data.
  • historic_data - contains the latest historic data, which is only updated after a request for historic data.
  • historic_trades - contains the requested trade history, which is only updated after a request for historic trades.

Data Functions:

  • subscribe_symbols(symbols) - subscribes to tick data for a list of symbols. Example format: symbols = ['EURUSD', 'GBPUSD']
  • subscribe_symbols_bar_data(symbols) - subscribes to bar data for a list of symbol/timeframe combinations. Example format: symbols=[['EURUSD', 'M15'], ['GBPUSD', 'H4']]
  • subscribe_symbols(symbols) - subscribes to tick data for a list of symbols. Example format: symbols = ['EURUSD', 'GBPUSD']
  • get_historic_data(symbol, time_frame, start, end) - requests historic bar data. The arguments start and end are given as timestamp.
  • get_historic_trades(lookback_days) - requests the trade history for the last x days. Keep in mind that in MetaTrader the complete trade history should be visible in the Account History tab.

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'.

  • open_order(symbol, order_type, lots, price, stop_loss, take_profit, magic, comment, expriation) - sends a request to open an order.
    • Order types: 'buy', 'sell', 'buylimit', 'selllimit', 'buystop', 'sellstop'
    • If the price is empty, it will use the current bid/ask price (only works for market buy/sell orders).
    • Most of the arguments are not strictly necessary. For example, open_order('EURUSD', 'buy', 0.01) would send a buy order without stop loss or take profit and magic number 0 if not specified.
  • modify_order(ticket, lots, price, stop_loss, take_profit, expriation) - modifies an order with a given ticket. Except price all arguments have to be present to not get deleted. For example, if stop_loss is not provided, it would set the stop loss to 0, thereby removing any existing stop loss.
  • close_order( ticket, lots) - closes an order with a given ticket. The lots argument can be used to partially close a position, whereas close_order(ticket) would close the complete position (or pending order).
  • close_all_orders() - closes all open orders.
  • close_orders_by_symbol(symbol) - closes all open orders with a given symbol.
  • close_orders_by_magic(magic) - closes all open orders with a given magic number.

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:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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.

dwxconnect's People

Contributors

darwinex avatar elvinex avatar integracore2 avatar piotryordanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dwxconnect's Issues

Expert Advisor insta closed

why when you install an Expert Advisor on a chart, after 5 seconds it turns itself off, closes and disappears from the chart ?

Missing install step? `ModuleNotFoundError: No module named 'api'`

I'm trying to run the example, but I'm getting this error:

D:\3rdparty\dwxconnect\python\examples> python dwx_client_example.py
Traceback (most recent call last):
  File "dwx_client_example.py", line 10, in <module>
    from api.dwx_client import dwx_client
ModuleNotFoundError: No module named 'api'

Is there an install step missing?

Passing market depth data and spread to the client

How would the code need to be extended in order to pass market depth / order book data to the client?
Which MQL functions should be called to fetch this data from MT?

And which MQL functions should be called to get the spread for a symbol?

missing in "market_data"

I believe that the "High" and "Low" price information is the most important piece of information in daily market data (current-day).

Only "Bid" and "Ask" are available as information "on_tick" at the moment.
We should have a function called "on_tick_daily", is what I propose. Open, High, Low, and Bid

Please point me in the right direction if I'm missing how to access those four bits of data using the on_tick method.

regards

"get_historic_data" optimization

Hello everybody, what would be the most correct way to optimize the response time of the "get_historic_data" function?

Every time I use it to fetch 300 ticks of 1 hour, the handle "on_historic_data" takes several minutes to get the information. If I want to get information for 28 pairs, sometimes it takes more than 1 hour and I'm already out of time.

What ways can I optimise this if possible?
Thank you very much :)

trouble with get_historic_data

Hi there
How can I access historical data after I call that function? It just tells us how many bars are there. I tried to read the historic_data_file in the DWX folder but it doesn't;t update when I change the currency. Also, sometimes It doesn't make any file in that directory.

Concerns about SSD wear leveling with DWX Connect

I just successfully set up DWX Connect and a Python client after watching the YouTube video on DWX Connect. Using the file system is a more simplistic approach than sockets/0MQ, BUT I have to ask if anyone has thought about the sheer number of writes to an SSD during 24/5 trading days when analyzing tick data. Likely, Windows will never commit every write as requested due to caching, but does anyone know this for sure? Perhaps it's late, and I'm not thinking straight, but I thought I'd ask as this "could" be an issue.

Lastly, with AntiVirus enabled, expect to get a CPU hit due to the large number of "hits" to the AV for checking. On the simple DWX Connect python example (reading ticks & quotes), my Ryzen 3700x CPU load increases 3% to 4% during Sydney trading (slow).

Just throwing these out as possible "issues" versus the 0MQ solution.

Strategy hedge mode

The API does not support hedge modes for multiple strategies to go long/short independently on the same symbol, like the Magic number concept in MT4. It is very important especially for integration with Interactive Brokers who provides net long or net short positions, but not parallel strategies.

Can you enable virtual hedging to this API please?

how to handle orders message

how to handle messages of INFO or OPEN ORDER or REMOVE ORDER that is printed to python,
I want to build a react algorithm every time an order is placed or removed etc...

New order: {'magic': 0, 'symbol': 'EURUSD', 'lots': 0.01, 'type': 'buy', 'open_price': 0.99455, 'open_time': '2022.09.01 17:57:12', 'SL': 0.0, 'TP': 0.0, 'pnl': -0.09, 'commission': 0.0, 'swap': 0.0, 'comment': ''}

Order removed: Order removed: {'magic': 0, 'symbol': 'EURUSD', 'lots': 0.01, 'type': 'buy', 'open_price': 0.99455, 'open_time': '2022.09.01 17:57:12', 'SL': 0.0, 'TP': 0.0, 'pnl': -0.09, 'commission': 0.0, 'swap': 0.0, 'comment': ''}

ideas

Hi guys,

have a request idea. I don't know where to post those other than here. sorry.

Is there a way to have a close all function that only closes certain types of positions? like close_all_sell, or close_all_buy?

thanks
Stuart

Message integrity / authenticity

CMIIW.
Right now, anyone/ program with access to DWX files can alter the file.
There should be mechanism (ex hmac) in mql5 & client side to securely exchange messages.

Error in dwx_client_example.py

Hi,

I am testing the new version of dwx_client in python but it does not work.

After running the example, I receive the next error:
on_bar_data: EURUSD H1 2023-01-24 11:27:07.282436 2023.01.24 12:00 1.08604 1.08664 1.0852 1.08638
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 3|SUBSCRIBE_SYMBOLS_BAR_DATA|EURUSD,H1
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 1|RESET_COMMAND_IDS|
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 2|OPEN_ORDER|EURUSD,buy,0.01,0,1.053,0,0,,0
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 1|RESET_COMMAND_IDS|
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 2|OPEN_ORDER|EURUSD,buy,0.01,0,1.053,0,0,,0
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 1|RESET_COMMAND_IDS|
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 2|OPEN_ORDER|EURUSD,buy,0.01,0,1.063,0,0,,0
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 1|RESET_COMMAND_IDS|
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: 2|SUBSCRIBE_SYMBOLS|EURUSD,GBPUSD

And does not open any order.

Is there any solution?

Thank you.

It places several orders.

Sometimes when open_order() gets triggered it places several orders at the same time. It also happens in the example.

Use builtin MT indicator

Hi
Is it possible to use/ run builtin indicator from client side (python/ java/ etc) ?
Thank you

Functions returns empty dict

Is it normal to get empty dict while invoking get_historic_data() method? I can read txt file inside mt4 dirs and access desired data, but I'm still getting some errors:

`Exception in thread Thread-5:
Traceback (most recent call last):
File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Python38\lib\threading.py", line 870, in run
self.run()
File "C:\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "D:\Code\Trading\Darwinex\dwx_client.py", line 320, in check_historic_data
self._target(*self._args, **self._kwargs)
File "D:\Code\Trading\Darwinex\dwx_client.py", line 222, in check_messages
self.event_handler.on_historic_data(
AttributeError: 'DWX' object has no attribute 'on_historic_data' self.event_handler.on_message(message)

AttributeError: 'DWX' object has no attribute 'on_message'`

datetime.utcnow being deprecated

Hi guys, through the code - this utcnow is referenced. But its going away.
Is it possible to provide the string code to replace with in the client example and api and mql if required?

thanks

Backtesting with commisions / execution costs, which settings for MT StrategyTester?

I want to backtest my EA in MT5 with real world conditions, by following these articles:
IMPORTING HIGH QUALITY TICK DATA TO METATRADER 5
CONFIGURING TRADING FEES IN THE MT5 STRATEGY TESTER WHEN BACKTESTING (CUSTOM SYMBOLS)

https://help.darwinex.com/execution-costs

In the case of both Forex and commodities, the gross commission always equals 0.005% of the nominal value of the base currency.
For instance, should you want to buy 1 lot on the EURUSD, that is 100.000 €, the total round-trip cost would be 5 €.

https://help.darwinex.com/calculate-the-pl-and-the-cost-of-a-forex-trade

For currency pairs we charge 0.0025% of nominal value traded or a competitive 0.005% round trip.
In MT4, the entire round trip commission gets charged at the opening of the trade and no additional commission is charged afterwards.
However, in MT5 the commission is charged "per-side", half at the opening, half at the exit of the trade.

image

I want to enter the execution costs / commisions, which values should I enter?

Charge: Instant by deal volume or Instant by deal value?
Entry: In/out deals?
From: ?
To: ?
Commission: ?
Minimal: ?
Maximal: ?
Mode: ?
Type: per trade or per volume?

image

image

image

image


On that dialog, there's an Import button. It would be nice if the Darwinex Team could add a file to this repo that can be imported, that contains the right settings for Darwinex's execution costs.


Btw, how high is the quality of the tick data that comes from Darwinex (when I don't import external tick data)?

How to handle concurrent requests ?

Hi so i am getting parallel alerts from trading view like same time buy signal and it is placing 4 orders is there any way to place only one order when having concurrent requests ?

Could not open order: trade is not allowed in the expert properties

Hi, I'm testing your solution but I often receive the error in the object. Check out the following log:

open_order BTCUSD. buy 44182.04
ERROR | OPEN_ORDER | Could not open order: trade is not allowed in the expert properties
open_order BTCUSD. buy 44175.0
INFO | Successfully sent order 20360199: BTCUSD., buy, 0.01, 44175.00
New order:  {'magic': 0, 'symbol': 'BTCUSD.', 'lots': 0.01, 'type': 'buy', 'open_price': 44175.0, 'open_time': '2022.04.06 17:01:58', 'SL': 0.0, 'TP': 0.0, 'pnl': -0.48, 'commission': 0.0, 'swap': 0.0, 'comment': ''}
on_order_event. open_orders: 1 open orders
open_order BTCUSD. sell 44094.47
ERROR | OPEN_ORDER_MAXIMUM_NUMBER | Number of orders (1) larger than or equal to MaximumOrders (1).
ERROR | CLOSE_ORDER_TICKET | Could not close position 20360199: trade is not allowed in the expert properties
open_order BTCUSD. buy 44150.46
ERROR | OPEN_ORDER | Could not open order: trade is not allowed in the expert properties

Obviously I've triple checked that trade is allowed for the EA and generally for the platform...as you can see sometimes the position gets opened. Am I missing something? What can I check?

Question: Performance problems

Hello.

I studied your code and I am unsure, whether the solution of communication with Metatrader through creating and deleting files is fast enough.

There must be made serialization by OS when changing folder, the OS must maintain the filesystem integrity,... and there are many other overheads of this solution. I am worried, whether this overhead might take too much ms to be done.

Did you make any benchmarks, when you migrated from ZeroMQ? Is my intuition about the slowness of the solution correct?

Thanks.

OPEN_ORDER_LOTSIZE_OUT_OF_RANGE and OPEN_ORDER_PRICE_ZERO for usa500

I am using python for communication with DWX Server and I got strange errors when I want to work with usa500 symbol. I got error OPEN_ORDER_LOTSIZE_OUT_OF_RANGE , but when i disable this check in code i got error OPEN_ORDER_PRICE_ZERO. It looks like that function MarketInfo doesn't work as expectet for this symbol.
Also I have noticed that for symbol ger40 I got error OPEN_ORDER_PRICE_ZERO .

By the way, there is typo error in lines

SendError("OPEN_ORDER_LOTSIZE_OUT_OF_RANGE", StringFormat("Lot size out of range (min: %f, max: %s): %f", MarketInfo(symbol, MODE_MINLOT), MarketInfo(symbol, MODE_MAXLOT), lots));

SendError("MODIFY_ORDER_LOTSIZE_OUT_OF_RANGE", StringFormat("Lot size out of range (min: %f, max: %s): %f", MarketInfo(OrderSymbol(), MODE_MINLOT), MarketInfo(OrderSymbol(), MODE_MAXLOT), lots));

it should be Lot size out of range (min: %f, max: %f): %f instead Lot size out of range (min: %f, max: %s): %f

Error when converting text files to JSON

Inside the DWX_Client.py file, in the functions "check_messages" and "check_historic_data" sometimes there are errors due to failure to convert the text of the file to json.

This happens because sometimes the text of the file is incomplete, so it cannot be transformed into a json. An example of "check_historic_data":

{"GBPJPY_H1": "2022.07.08 01:00": {"open": 163.50900, "high": 163.64800, "low": 163.44100, "close": 163.56500, "tick_volume": 1983.00000}, "2022"

Best regards.

Error WRONG_FORMAT_START_IDENTIFIER

Hi,

Thanks for the great project. I have used some connectors before (Metatrader 5, dwx-zeromq-connector), but now I have used dwxconnect for my project, because easy to use and removes zeromq dependency.
When start using, I also worried about latency when using file to communicate between python and mql, but now I don't see any difference.
Recently sometimes I got the error :
WRONG_FORMAT_START_IDENTIFIER | Start identifier not found for command:
I have checked code on file DCWX_Server_MT4.mq4 it seems this error was logged by following code:
if (StringSubstr(text, 0, 2) != startIdentifier) { SendError("WRONG_FORMAT_START_IDENTIFIER", "Start identifier not found for command: " + text); return; }

I have set MILISECOND_TIMERS=5 in DWX_Server_MT4 expert.

Differentiate between orders and positions

The MQL script does not differentiate between orders and positions. It looks for all open orders and open positions but then reports them all in the same "orders" key. The command to close orders, actually closes orders and positions, etc.

However, they are quite different things. An open order is not the same as an open position.

I would propose to separate these two things:
Report from MQL orders and positions separately, and be able to manage orders and positions separately as well.

Getting Error everytime when order is placed.

on_order_event. open_orders: 1 open orders
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: MODIFY_ORDER|172088992,0.01,0,1838.02,0,0
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: MODIFY_ORDER|172088992,0.01,0,1838.02,0,0
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: MODIFY_ORDER|172088992,0.01,0,1838.02,0,0
ERROR | WRONG_FORMAT_COMMAND | Wrong format for command: MODIFY_ORDER|172088992,0.01,0,1838.02,0,0

Cannot perform trade

Hi, I m using demo account and I try running the example python file and I get this error message:

ERROR | OPEN_ORDER | Could not open order: trade is not allowed in the expert properties

May I know what could have been the problem?

Running on MacOS

Any guide to follow on running the connector on MacOS Metatrader 5?

Zero Max Lot Size?

I have gotten the following error more than once. What is the point of the maximum lot size being 0.000? Why does this happen?

('ERROR', '|', 'OPEN_ORDER_LOTSIZE_OUT_OF_RANGE', '|', 'Lot size out of range (min: 0.000000, max: 0.000000): 0.010000')

Thank you.

modify_order lots parameter ignored

Hi, i'm testing the modify_order call and it seems that lots parameter is ignored on the MQL side?

both mql5 and mql4

if (isPosition)
      res = trade.PositionModify(ticket, stopLoss, takeProfit);
   else
      res = trade.OrderModify(ticket, price, stopLoss, takeProfit, ORDER_TIME_GTC, expiration);

..

bool res = OrderModify(ticket, price, stopLoss, takeProfit, expiration);

i can only see usage of this parameter in logs
If it's not possible to change order size with lots should we remove this from modify_order?

Historical / Bar Data Reuse

Hello there!

I started using this api yesterday and everything worked fine but starting today, the historical data started acting weird. It doesn't bring the latest bar and the bar range of the output is more than requested. No matter what timeframe or range of dates requested, it brings this same constant output of M1 bars requested over a day. It was the last request I made yesterday:


historic_data: EURUSD M1 1434 bars

{'EURUSD_M1': {'2023.03.08 10:53': {'open': 1.05407, 'high': 1.05413, 'low': 1.05398, 'close': 1.05407, 'tick_volume': 73.0}, '2023.03.08 10:54': {'open': 1.05408, 'high': 1.05413, 'low': 1.05394, 'close': 1.05413, 'tick_volume': 76.0}, '2023.03.08 10:55': {'open': 1.05413, 'high': 1.05414, 'low': 1.05397, 'close': 1.05412, 'tick_volume': 62.0}, '2023.03.08 10:56': {'open': 1.05412, 'high': 1.05428, 'low': 1.05385, 'close': 1.05385, 'tick_volume': 79.0}, '2023.03.08 10:57': {'open': 1.05386, 'high': 1.05386, 'low': 1.05367, 'close': 1.05372, 'tick_volume': 43.0},

...                   ...      ...      ...      ...          ...

'2023.03.09 10:50': {'open': 1.0557, 'high': 1.0557, 'low': 1.05548, 'close': 1.05554, 'tick_volume': 55.0}, '2023.03.09 10:51': {'open': 1.05555, 'high': 1.05588, 'low': 1.05555, 'close': 1.05588, 'tick_volume': 32.0}, '2023.03.09 10:52': {'open': 1.0559, 'high': 1.05595, 'low': 1.0559, 'close': 1.05595, 'tick_volume': 12.0}}}

Time : 2023-03-10 13:43:49.481380

Here is a snap of the code:


class tick_processor():

    def __init__(self, MT4_directory_path, 
                 sleep_delay=0.005,             # 5 ms for time.sleep()
                 max_retry_command_seconds=10,  # retry to send the commend for 10 seconds if not successful. 
                 verbose=True
                 ):

        self.dwx = dwx_client(self, MT4_directory_path, sleep_delay, 
                              max_retry_command_seconds, verbose=verbose)
        sleep(1)

        self.dwx.start()

        # request historic data:
        end = datetime.utcnow()
        start = end - timedelta(hours=2)  
        self.dwx.get_historic_data('EURUSD', 'M15', start.timestamp(), end.timestamp())

    def on_historic_data(self, symbol, time_frame, data):
        data_ = self.dwx.historic_data
        print('historic_data:', symbol, time_frame, f'{len(data)} bars')
        print(data_)
        print(f"Time : {datetime.utcnow()}")

What am I doing wrong?

installation does not work on Mac

The path to Files directory on Mac vs other is really mixed up and there is actually no solution that would be working in this case for MT4_files_dir or MT5_files_dir.
Would be grateful for your support for Mac users.

Here's how to find the paths' on Mac:

  1. /Applications/MetaTrader4.app/Contents/SharedSupport/metatrader4/support/metatrader4/drive_c/Program Files/MT4 Client Terminal/MQL4/Files

  2. /Applications/MetaTrader 5.app/Contents/SharedSupport/metatrader5/support/metatrader5/drive_c/users/crossover/Application Data/MetaQuotes/Terminal/D0E8209F77C8CF37AD8BF550E51FF075

open limit buy order

hi kindly can you show me an example on how to open limit buy order with last bid price (python)
Thank you

Latency performance of dwxconnect vs dwz-zeromq-connector

Hi there,

I am planning on implementing a low-latency strategy where every millisecond counts. What I'd like to know is, whether dwxconnect or the old archived dwx-zeromq-connector has lower latency? My first instinct is that zeromq would be faster since it's literally designed as a low-latency protocol. If I'm correct, then the file-based system of dwxconnect would be slower. Am I right in this assumption? Specifically I'm interested in trade execution speed/latency. Price feed latency is also important but not as important.

I suppose the best thing to do would be test them side-by-side. I'll probably do this when I have the time, but would love to hear the opinion of the creators from Darwinex.

Thanks

check_historic_data() seems not happy when the json return from mt is too big (lots of candles)

Hi,

when I use the client i got :

dwx_client.py:397 - check_historic_data() -- An error occurred in the check_historic_data thread: Expecting ':' delimiter: line 1 column 40961 (char 40960)

It seems to happen when the dwn client asks more than 1000 candles.
This error come from partials data in the JSON response (unable to parse)
I write with more than one data feed, meaning that maybe it is related to lock and async of the bridge file.

Many tks for help. I will try to investigate more.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.