Git Product home page Git Product logo

darwinex / dwxconnect Goto Github PK

View Code? Open in Web Editor NEW
159.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 Issues

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.

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

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

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

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.

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

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

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.

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.

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?

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

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

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?

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

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

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': ''}

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?

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?

Use builtin MT indicator

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

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.

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.

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?

It places several orders.

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

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 ?

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

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.

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.

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

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.

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?

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?

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.

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.