From 7f324dc125543ff7eb3e3fcb9704dac968febf71 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Mon, 17 Jun 2019 15:50:04 +0300 Subject: [PATCH 1/5] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6be2d27..c6c3e83 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Check out the available combinations of `action` and `actionType`: action | actionType | Description | -----------|----------------------|----------------------------| -CONFIG | None | Set script configuration | +CONFIG | None | Set script configuration | ACCOUNT | None | Get account settings | BALANCE | None | Get current balance | POSITIONS | None | Get current open positions | @@ -307,15 +307,15 @@ There are only two variants of `Live socket` data. When everything is ok, the sc {"status":"CONNECTED","data":[1560780120,1.12186,1.12194,1.12186,1.12191,15.00000]} ``` -If the terminal has lost connection to market: +If the terminal has lost connection to the market: ``` {"status":"DISCONNECTED"} ``` -When the terminal reconnects to market, it sends last closed candle again. So you should update historical data. Make the `action="HISTORY"` request with `fromDate` equal to your last candle timestamp. +When the terminal reconnects to the market, it sends the last closed candle again. So you should update the historical data. Make the `action="HISTORY"` request with `fromDate` equal to your last candle timestamp. -`OnTradeTransaction` function is called when the trade transaction event occurs. `Streaming socket` sends `TRADE_TRANSACTION_REQUEST` data every time it happens. You can create and modify orders/positions in terminal manually and check expert logging tub for better understanding. Also see [MQL5 docs](https://www.mql5.com/en/docs/event_handlers/ontradetransaction). +`OnTradeTransaction` function is called when the trade transaction event occurs. `Streaming socket` sends `TRADE_TRANSACTION_REQUEST` data every time it happens. You can create and modify orders/positions in the MQL5 terminal manually and check the expert logging tub for better understanding. Also see [MQL5 docs](https://www.mql5.com/en/docs/event_handlers/ontradetransaction). `TRADE_TRANSACTION_REQUEST` request data: @@ -357,4 +357,5 @@ When the terminal reconnects to market, it sends last closed candle again. So yo ## License This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See `LICENSE` for more information. \ No newline at end of file + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See `LICENSE` for more information. From eeb03f23a8023d57ace2f33def2fd4221ce49d89 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Mon, 17 Jun 2019 19:00:58 +0300 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6c3e83..6b9aba1 100644 --- a/README.md +++ b/README.md @@ -315,7 +315,7 @@ If the terminal has lost connection to the market: When the terminal reconnects to the market, it sends the last closed candle again. So you should update the historical data. Make the `action="HISTORY"` request with `fromDate` equal to your last candle timestamp. -`OnTradeTransaction` function is called when the trade transaction event occurs. `Streaming socket` sends `TRADE_TRANSACTION_REQUEST` data every time it happens. You can create and modify orders/positions in the MQL5 terminal manually and check the expert logging tub for better understanding. Also see [MQL5 docs](https://www.mql5.com/en/docs/event_handlers/ontradetransaction). +`OnTradeTransaction` function is called when the trade transaction event occurs. `Streaming socket` sends `TRADE_TRANSACTION_REQUEST` data every time it happens. Try to create and modify orders in the MQL5 terminal manually and check the expert logging tab for better understanding. Also see [MQL5 docs](https://www.mql5.com/en/docs/event_handlers/ontradetransaction). `TRADE_TRANSACTION_REQUEST` request data: From 2b8c1cf55e65e78074e455b4f421e546db662121 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Mon, 17 Jun 2019 23:21:14 +0300 Subject: [PATCH 3/5] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6b9aba1..7eea45e 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,10 @@ ## About the Project -This project was developed to work as a server for Backtrader Python trading framework. It is based on ZeroMQ sockets and uses JSON format to communicate. But now it has grown to the independent project. You can use it with any language that has [ZeroMQ binding](http://zeromq.org/bindings:_start). +This project was developed to work as a server for the Backtrader Python trading framework. It is based on ZeroMQ sockets and uses JSON format to communicate. But now it has grown to the independent project. You can use it with any language that has [ZeroMQ binding](http://zeromq.org/bindings:_start). -Backtrader Python client located here: [Python Backtrader - Metaquotes MQL5 ](https://github.com/khramkov/MQL5-Backtrader-API) +Backtrader Python client located here: [Python Backtrader - Metaquotes MQL5 ](https://github.com/khramkov/Backtrader-MQL5-API) In development: * Add error handling to docs @@ -42,11 +42,11 @@ Tested on macOS Mojave / Windows 10 in Parallels Desktop container. The script uses four ZeroMQ sockets: 1. `System socket` - recives requests from client and replies 'OK' -2. `Data socket` - pushes data to client depending on request via System socket. +2. `Data socket` - pushes data to client depending on the request via System socket. 3. `Live socket` - automatically pushes last candle when it closes. 4. `Streaming socket` - automatically pushes last transaction info every time it happens. -The idea is to send requests via `System socket` and recieve results/errors via `Data socket`. Event handlers should be created for `Live socket` and `Streaming socket` because server sends data to theese sockets automatically. See examples in [Live data and streaming events](#live-data-and-streaming-events) section. +The idea is to send requests via `System socket` and recieve results/errors via `Data socket`. Event handlers should be created for `Live socket` and `Streaming socket` because the server sends data to theese sockets automatically. See examples in [Live data and streaming events](#live-data-and-streaming-events) section. `System socket` request uses default JSON dictionary: @@ -223,7 +223,9 @@ rep = api.construct_and_send(action="ACCOUNT") print(rep) ``` -Get historical data. `fromDate` should be in timestamp format. If `toDate` is `None` There are some issues: +Get historical data. `fromDate` should be in timestamp format. The data will be loadet to the last candle if `toDate` is `None`. Notice, that the script sends the last unclosed candle too. You should delete it manually. + +There are some issues: - MetaTrader keeps historical data in cache. But when you make a request for the first time, MetaTrader downloads data from a broker. This operation can exceed `Data socket` timeout. It depends on your broker. Second request will be handeled quickly. - It takes 6-7 seconds to process `50000` M1 candles. It was tested on Windows 10 in Parallels Desktop container with 4 cores and 4GB RAM. So if you need more data there are three ways to handle it. 1) Increase `Data socket` timeout. 2) You can load data partially using `fromDate` and `toDate`. 3) You can use more powerfull hardware. From b708aac84667113ebf32d0002bfaac98c0990aa1 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Tue, 18 Jun 2019 22:21:39 +0300 Subject: [PATCH 4/5] Update README.md --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7eea45e..fdbb80f 100644 --- a/README.md +++ b/README.md @@ -52,32 +52,32 @@ The idea is to send requests via `System socket` and recieve results/errors via ``` { - "action": None, - "actionType": None, - "symbol": None, - "chartTF": None, - "fromDate": None, - "toDate": None, - "id": None, - "magic": None, - "volume": None, - "price": None, - "stoploss": None, - "takeprofit": None, - "expiration": None, - "deviation": None, - "comment": None + "action": null, + "actionType": null, + "symbol": null, + "chartTF": null, + "fromDate": null, + "toDate": null, + "id": null, + "magic": null, + "volume": null, + "price": null, + "stoploss": null, + "takeprofit": null, + "expiration": null, + "deviation": null, + "comment": null } ``` Check out the available combinations of `action` and `actionType`: action | actionType | Description | -----------|----------------------|----------------------------| -CONFIG | None | Set script configuration | -ACCOUNT | None | Get account settings | -BALANCE | None | Get current balance | -POSITIONS | None | Get current open positions | -ORDERS | None | Get current open orders | +CONFIG | null | Set script configuration | +ACCOUNT | null | Get account settings | +BALANCE | null | Get current balance | +POSITIONS | null | Get current open positions | +ORDERS | null | Get current open orders | HISTORY | DATA | Get data history | HISTORY | TRADES | Get trades history | TRADE | ORDER_TYPE_BUY | Buy market | From 5ca9a3f6f2963f5c3b758b8a843441251610e0c5 Mon Sep 17 00:00:00 2001 From: Nikolai Date: Tue, 18 Jun 2019 22:28:33 +0300 Subject: [PATCH 5/5] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fdbb80f..5056c17 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,7 @@ All examples will be on Python 3. Lets create an instance of MetaTrader API clas api = MTraderAPI() ``` -First of all we should configure script `symbol` and `timeframe`. Live data stream will be configured to the seme params. +First of all we should configure the script `symbol` and `timeframe`. Live data stream will be configured to the seme params. ``` python rep = api.construct_and_send(action="CONFIG", symbol="EURUSD", chartTF="M5") @@ -223,7 +223,7 @@ rep = api.construct_and_send(action="ACCOUNT") print(rep) ``` -Get historical data. `fromDate` should be in timestamp format. The data will be loadet to the last candle if `toDate` is `None`. Notice, that the script sends the last unclosed candle too. You should delete it manually. +Get historical data. `fromDate` should be in timestamp format. The data will be loaded to the last candle if `toDate` is `None`. Notice, that the script sends the last unclosed candle too. You should delete it manually. There are some issues: @@ -315,7 +315,7 @@ If the terminal has lost connection to the market: {"status":"DISCONNECTED"} ``` -When the terminal reconnects to the market, it sends the last closed candle again. So you should update the historical data. Make the `action="HISTORY"` request with `fromDate` equal to your last candle timestamp. +When the terminal reconnects to the market, it sends the last closed candle again. So you should update your historical data. Make the `action="HISTORY"` request with `fromDate` equal to your last candle timestamp before disconnect. `OnTradeTransaction` function is called when the trade transaction event occurs. `Streaming socket` sends `TRADE_TRANSACTION_REQUEST` data every time it happens. Try to create and modify orders in the MQL5 terminal manually and check the expert logging tab for better understanding. Also see [MQL5 docs](https://www.mql5.com/en/docs/event_handlers/ontradetransaction).