darwinex / dwx-zeromq-connector

Wrapper library for algorithmic trading in Python 3, providing DMA/STP access to Darwinex liquidity via a ZeroMQ-enabled MetaTrader Bridge EA.
https://blog.darwinex.com/zeromq-interface-python-r-metatrader4/
BSD 3-Clause "New" or "Revised" License
344 stars 228 forks source link

Coin flip trader #26

Closed AloftLab closed 5 years ago

AloftLab commented 5 years ago

HI!

The issue is that coin flip trader is not closing trades and is stoped to open new ones as well. It opens them randomly than stops working and I get:

_NoneException Type TypeError. Args: ("'bool' object is not iterable",) {'_action': 'OPEN_TRADES', '_trades': {3779123: {'_magic': 123456, '_symbol': 'AUDNZD', '_lots': 0.01, '_type': 1, '_open_price': 1.04874, '_open_time': '2019.07.10 15:23:04', '_SL': 1.04974, '_TP': 1.04774, '_pnl': -0.13, '_comment': 'AUDNZD_Trader'}, 3779122: {'_magic': 123456, '_symbol': 'EURUSD', '_lots': 0.01, '_type': 1, '_open_price': 1.12134, '_open_time': '2019.07.10 15:23:02', '_SL': 1.12234, '_TP': 1.12034, '_pnl': -0.04, '_comment': 'EURUSD_Trader'}}}Exception in thread EURUSD_Trader: Traceback (most recent call last): File "xxx\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner self.run() File "xxx\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "xxx/coin_flip_traders_v1.0.py", line 178, in trader 10) File "xxx\DWX_ZMQ_Reporting.py", line 55, in _get_opentrades index=_response['trades'].keys()) File "xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\frame.py", line 404, in init raise ValueError('DataFrame constructor not properly called!') ValueError: DataFrame constructor not properly called!

for example if I run _zmq._DWX_MTX_CLOSE_ALLTRADES() it will close all trades instant.

Any idea please what would solve the issue?

Tested in Jupyter notebook, ipython and PyCharm

integracore2 commented 5 years ago

Hi @matjazzh ,

Thank you for your query.

This script was put together as a very basic example to demonstrate the open/close order functionality implemented in the connector script.

As explained in the accompanying video on YouTube, very little in the way of validation and error checking was conducted in this trivial example, the errors above indicative of this as they are missing appropriate exception handling.

It is also advisable to run the script directly via a Python or IPython shell, not Jupyter as there are threading and timeout constraints that would be introduced as a result of bringing Jupyter into the equation, something that is not accommodated for by the project.

Hope this helps!

AloftLab commented 5 years ago

Ok tnx. Main thing is that communication with MT4 is working and these EA is only good for feeding broker with spread comission :) Thank you!

integracore2 commented 5 years ago

hehe.. exactly! The coin-flip trader example is NOT AT ALL an algorithm you should ever trade live.. its purpose is purely demonstration of the features available to algorithmic traders in this project.