![Pypi Publish](https://github.com/ejtraderLabs/ejtraderMT/actions/workflows/python-publish.yml/badge.svg)
[![Release](https://img.shields.io/github/v/release/ejtraderLabs/ejtraderMT)](https://github.com/ejtraderLabs/ejtraderMT/releases/latest) [![License](https://img.shields.io/github/license/ejtraderLabs/ejtraderMT)](https://github.com/ejtraderLabs/ejtraderMT/blob/master/LICENSE)
# EjtraderMT Python Metatrader 5 API
##### Install stable version using pip
```
pip install ejtraderMT -U
```
#### From source code
for developers attention may contain countless bugs
```
git clone https://github.com/ejtraderLabs/ejtraderMT
cd ejtraderMT
python setup.py install
or
pip install git+https://github.com/ejtraderLabs/ejtraderMT.git
```
## Runing Metatrader 5 on Docker or windows machine
#### Easy way is using docker make sure to have docker runing on your machine
```
docker volume create ejtraderMT
docker run -d --restart=always -p 5900:5900 -p 15555:15555 -p 15556:15556 -p 15557:15557 -p 15558:15558 --name ejtraderMT -v ejtraderMT:/data ejtrader/metatrader:5
```
or docker compose
```yml
version: '3.8'
services:
app:
container_name: metatrader
image: ejtrader/metatrader:5
restart: unless-stopped
ports:
- '5900:5900'
- '15555:15555'
- '15556:15556'
- '15557:15557'
- '15558:15558'
volumes:
- ejtraderMT:/data
volumes:
ejtraderMT: {}
```
Dockerfile and source for Docker wine vnc [github](https://github.com/ejtraderLabs/Metatrader5-Docker)
##### Access Metatrader 5 via VNC
download VNC VIEWER or any other vnc client of your preference: [Download](https://www.realvnc.com/connect/download/viewer/)
```
username: root
password: root
```
#### harder way installing direct to your Metatrader 5 on Windows Machine
First download MQL5 source code and install it on the Metatrader 5 [github](https://github.com/ejtraderLabs/MQL5-ejtraderMT)
second download and install Microsoft Visual C++ 2015 [Download](https://www.microsoft.com/pt-br/download/details.aspx?id=52685)
### import
```python
from ejtraderMT import Metatrader
```
### Connect Metatrader 5
make sure ejtraderMT expert are load on the chart
```python
'''
to change the host IP example Metatrader("192.168.1.100") ou
you can use doman example "metatraderserverdomain.com"
for you local time on the Dataframe Metatrader(tz_local=True)
attention utc time is the default for Dataframe index "date"
for real volume for active like WIN futures ou centralized market use Metatrader(real_volume=True)
attention tick volume is the default
to use more than one option just use , example Metatrader(host='hostIP',tz_local=True)
'''
api = Metatrader()
```
#### Account information
```python
accountInfo = api.accountInfo()
print(accountInfo)
print(accountInfo['broker'])
print(accountInfo['balance'])
```
#### Economic Calendar
```python
symbol = "EURUSD"
fromDate = "20/08/2021"
toDate = "24/08/2022"
calendar = api.calendar(symbol,fromDate,toDate)
print(calendar)
currency impact event country actual forecast previous
date
2021-08-20 06:00:00 EUR 2 PPI m/m(ppi-mm) Germany(DE) 1.9 0.9 1.3
2021-08-20 06:00:00 EUR 1 PPI y/y(ppi-yy) Germany(DE) 10.4 9.4 8.5
2021-08-20 17:00:00 USD 2 Baker Hughes US Oil Rig Count(baker-hughes-us-... United States(US) 405 None 397
2021-08-20 17:00:00 USD 2 Baker Hughes US Total Rig Count(baker-hughes-u... United States(US) 503 None 500
2021-08-20 19:30:00 EUR 1 CFTC EUR Non-Commercial Net Positions(cftc-eur... European Union(EU) 57.6 K None 33.9 K
... ... ... ... ... ... ... ...
2022-08-24 14:30:00 USD 1 EIA Heating Oil Stocks Change(eia-heating-oil-... United States(US) 0.845 M -0.013 M 0.249 M
2022-08-24 14:30:00 USD 1 EIA Gasoline Stocks Change(eia-gasoline-stocks... United States(US) -0.027 M -1.829 M -4.642 M
2022-08-24 14:30:00 USD 1 EIA Refinery Crude Oil Daily Inputs Change(eia... United States(US) -0.168 M None -0.158 M
2022-08-24 14:30:00 USD 1 EIA Refinery Utilization Rate Change(eia-refin... United States(US) 0.3 None -0.8
2022-08-24 17:00:00 USD 1 5-Year Note Auction(5-year-note-auction) United States(US) 3.23 None 2.86
```
# History Dataframe Ready
#### History from Date to Date
```python
# you can add unlimited actives to list ["EURUSD","GBPUSD","AUDUSD"]
symbol = "EURUSD"
timeframe = "M1"
fromDate = "20/02/2021"
toDate = "24/02/2021"
history = api.history(symbol,timeframe,fromDate,toDate)
print(history)
open high low close volume spread
date
2021-02-21 23:00:00 1.21135 1.21138 1.21131 1.21134 7.0 35
2021-02-21 23:01:00 1.21130 1.21135 1.21130 1.21135 6.0 43
2021-02-21 23:04:00 1.21150 1.21184 1.21134 1.21184 13.0 31
2021-02-21 23:05:00 1.21163 1.21207 1.21148 1.21181 39.0 42
2021-02-21 23:06:00 1.21189 1.21193 1.21182 1.21182 17.0 64
... ... ... ... ... ... ...
2021-02-24 02:56:00 1.21629 1.21629 1.21590 1.21594 51.0 5
2021-02-24 02:57:00 1.21592 1.21592 1.21574 1.21574 34.0 5
2021-02-24 02:58:00 1.21574 1.21579 1.21572 1.21575 35.0 5
2021-02-24 02:59:00 1.21576 1.21588 1.21573 1.21582 55.0 5
2021-02-24 03:00:00 1.21583 1.21601 1.21578 1.21598 80.0 5
[3104 rows x 6 columns]
```
#### History by period unit like 27 candles
```python
# you can add unlimited actives to list ["EURUSD","GBPUSD","AUDUSD"]
symbol = "EURUSD"
timeframe = "M1"
fromDate = 27
history = api.history(symbol,timeframe,fromDate)
print(history)
open high low close volume spread
date
2021-02-26 19:23:00 1.20846 1.20857 1.20837 1.20856 84.0 5
2021-02-26 19:24:00 1.20855 1.20858 1.20842 1.20847 71.0 5
2021-02-26 19:25:00 1.20846 1.20849 1.20832 1.20845 69.0 5
2021-02-26 19:26:00 1.20844 1.20845 1.20823 1.20833 64.0 5
2021-02-26 19:27:00 1.20833 1.20836 1.20821 1.20834 53.0 5
... ... ... ... ... ... ...
2021-02-26 22:55:00 1.20721 1.20730 1.20718 1.20719 46.0 13
2021-02-26 22:56:00 1.20718 1.20738 1.20718 1.20731 39.0 12
2021-02-26 22:57:00 1.20730 1.20731 1.20716 1.20717 45.0 18
2021-02-26 22:58:00 1.20716 1.20731 1.20694 1.20704 77.0 16
2021-02-26 22:59:00 1.20702 1.20705 1.20702 1.20704 16.0 37
```
#### History for lastest period gread for predict
```python
# you can add unlimited actives to list ["EURUSD","GBPUSD","AUDUSD"]
symbol = "EURUSD"
timeframe = "M1"
fromDate = 27
history = api.history(symbol,timeframe)
print(history)
open high low close volume spread
date
2021-02-26 19:23:00 1.20846 1.20857 1.20837 1.20856 84.0 5
2021-02-26 19:24:00 1.20855 1.20858 1.20842 1.20847 71.0 5
2021-02-26 19:25:00 1.20846 1.20849 1.20832 1.20845 69.0 5
2021-02-26 19:26:00 1.20844 1.20845 1.20823 1.20833 64.0 5
2021-02-26 19:27:00 1.20833 1.20836 1.20821 1.20834 53.0 5
```
#### History for multiple symbols merged dataframe
```python
# you can add unlimited actives to list ["EURUSD","GBPUSD","AUDUSD"] etc
symbol = ["EURUSD","GBPUSD"]
timeframe = "M1"
fromDate = "20/02/2021"
toDate = "24/02/2021"
history = api.history(symbol,timeframe,fromDate,toDate)
print(history)
open high low close volume spread gbpusd_open gbpusd_high gbpusd_low gbpusd_close gbpusd_volume gbpusd_spread
date
2021-02-21 23:00:00 1.21135 1.21138 1.21131 1.21134 7.0 35 1.40113 1.40113 1.40110 1.40110 2.0 130
2021-02-21 23:04:00 1.21150 1.21184 1.21134 1.21184 13.0 31 1.40119 1.40119 1.40119 1.40119 1.0 102
2021-02-21 23:05:00 1.21163 1.21207 1.21148 1.21181 39.0 42 1.40174 1.40174 1.40167 1.40168 11.0 61
2021-02-21 23:06:00 1.21189 1.21193 1.21182 1.21182 17.0 64 1.40156 1.40170 1.40132 1.40155 10.0 46
2021-02-21 23:07:00 1.21181 1.21182 1.21180 1.21182 4.0 82 1.40156 1.40156 1.40156 1.40156 1.0 63
... ... ... ... ... ... ... ... ... ... ... ... ...
2021-02-24 02:56:00 1.21629 1.21629 1.21590 1.21594 51.0 5 1.41833 1.41835 1.41786 1.41800 62.0 8
2021-02-24 02:57:00 1.21592 1.21592 1.21574 1.21574 34.0 5 1.41798 1.41801 1.41765 1.41766 54.0 8
2021-02-24 02:58:00 1.21574 1.21579 1.21572 1.21575 35.0 5 1.41767 1.41789 1.41767 1.41768 64.0 8
2021-02-24 02:59:00 1.21576 1.21588 1.21573 1.21582 55.0 5 1.41769 1.41782 1.41764 1.41769 42.0 9
2021-02-24 03:00:00 1.21583 1.21601 1.21578 1.21598 80.0 5 1.41770 1.41797 1.41746 1.41784 95.0 8
[3097 rows x 12 columns]
```
# Live streaming Price
```python
from ejtraderMT import Metatrader
api = Metatrader()
symbols = ["EURUSD","GBPUSD","AUDUSD"]
timeframe = "TICK"
# stream price
while True:
price = api.price(symbols,timeframe)
print(price)
```
# Live streaming events
```python
from ejtraderMT import Metatrader
api = Metatrader()
symbols = ["EURUSD","GBPUSD","AUDUSD"]
timeframe = "TICK"
# stream event
while True:
event = api.event(symbols,timeframe)
print(event)
```
# Trading and Orders Manipulation
### You can create market or pending order with the commands.
#### Market Orders
```python
# symbol, volume, stoploss, takeprofit, deviation
api.buy("EURUSD", 0.01, 1.18, 1.19, 5)
api.sell("EURUSD", 0.01, 1.18, 1.19, 5)
```
#### Limit Orders
```python
# symbol, volume, stoploss, takeprofit, price, deviation
api.buyLimit("EURUSD", 0.01, 1.17, 1.19, 1.18, 5)
api.sellLimit("EURUSD", 0.01, 1.20, 1.17, 1.19, 5)
```
#### Stop Orders
```python
#symbol, volume, stoploss, takeprofit, price, deviation
api.buyStop("EURUSD", 0.01, 1.18, 1.20, 1.19, 5)
api.sellStop("EURUSD", 0.01, 1.19, 1.17, 1.18, 5)
```
#### Positions & Manipulation
```python
positions = api.positions()
if 'positions' in positions:
for position in positions['positions']:
api.CloseById(position['id'])
```
#### Orders & Manipulation
```python
orders = api.orders()
if 'orders' in orders:
for order in orders['orders']:
api.CancelById(order['id'])
```
#### Modify possition
```python
api.positionModify( id, stoploss, takeprofit)
```
#### Modify order
```python
api.orderModify( id, stoploss, takeprofit, price)
```
#### close by symbol
```python
api.CloseBySymbol("EURUSD")
```
#### close particial
```python
# id , volume
api.ClosePartial( id, volume)
```
#### If you want to cancel all Orders
```python
api.cancel_all()
```
#### if you want to close all positions
```python
api.close_all()
```
```
# Project Based and reference thanks for
Ding Li @dingmaotu
https://github.com/dingmaotu/mql-zmq
Nikolai khramkov @khramkov
https://github.com/khramkov/MQL5-JSON-API
```
# New funcion persistent history Data on SQLite Multithrering
### for saving to database
```python
from ejtraderMT import Metatrader
api = Metatrader()
symbols = ["EURUSD"] # you can also use combind dataframe = ["EURUSD","GBPUSD","AUDUSD"]
timeframe = "M1"
# saving 20 years of OHLC
fromDate = "01/01/2001"
toDate = "01/01/2021"
api.history(symbol,timeframe,fromDate,toDate,database=True)
# or you could only pass from Date you want to start
"""
you can pull the history and save using only fromDate
its will pull history fromDate till now
api.history(symbol,timeframe,fromDate,database=True)
"""
# example of saving 20 years of M1 OHLC takes around 3 minutes on a 4 core CPU
30%|█████████████████████████████████▋ | 2174/7305 [01:10<02:28, 34.60it/s]
```
# Read from Database
```python
from ejtraderMT import Metatrader
api = Metatrader()
symbol = ["EURUSD"]
data = api.history(symbol)
# example reading 20 year of M1 OHLC takes around 2 seconds read more than 7 million canldes
Elapsed run time: 2.041501855 seconds
date open high low close volume spread
0 2001-01-01 04:02:00 0.94220 0.94220 0.94220 0.94220 1.0 50
1 2001-01-01 04:03:00 0.94240 0.94240 0.94240 0.94240 1.0 50
2 2001-01-01 10:47:00 0.94250 0.94250 0.94250 0.94250 1.0 50
3 2001-01-01 11:40:00 0.94190 0.94190 0.94190 0.94190 1.0 50
4 2001-01-01 14:45:00 0.93970 0.93990 0.93970 0.93990 3.0 50
... ... ... ... ... ... ... ...
7286195 2020-12-31 17:56:00 1.22147 1.22152 1.22147 1.22152 20.0 8
7286196 2020-12-31 17:57:00 1.22152 1.22162 1.22148 1.22157 58.0 8
7286197 2020-12-31 17:58:00 1.22157 1.22167 1.22152 1.22166 77.0 9
7286198 2020-12-31 17:59:00 1.22167 1.22177 1.22154 1.22154 129.0 8
7286199 2020-12-31 18:00:00 1.22156 1.22156 1.22155 1.22155 2.0 11
[7286200 rows x 7 columns]
```
### Future add comming soon
```
economic calendar
level 1 for futures only
level 2 for futures only
```
Raw data
{
"_id": null,
"home_page": "https://ejtraderMT.readthedocs.io/",
"name": "ejtraderMT",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": "",
"keywords": "metatrader,f-api,historical-data,financial-data,stocks,funds,etfs,indices,currency crosses,bonds,commodities,crypto currencies",
"author": "Emerson Pedroso",
"author_email": "support@ejtrader.com",
"download_url": "https://files.pythonhosted.org/packages/69/4c/b60174f104eec6624defb218ed5d8ee6ce5bc5ffa6df6dc7edbd3a415cf2/ejtraderMT-3.17.tar.gz",
"platform": null,
"description": "![Pypi Publish](https://github.com/ejtraderLabs/ejtraderMT/actions/workflows/python-publish.yml/badge.svg)\n[![Release](https://img.shields.io/github/v/release/ejtraderLabs/ejtraderMT)](https://github.com/ejtraderLabs/ejtraderMT/releases/latest) [![License](https://img.shields.io/github/license/ejtraderLabs/ejtraderMT)](https://github.com/ejtraderLabs/ejtraderMT/blob/master/LICENSE)\n\n# EjtraderMT Python Metatrader 5 API\n\n\n##### Install stable version using pip \n```\npip install ejtraderMT -U\n```\n#### From source code\n\nfor developers attention may contain countless bugs\n```\ngit clone https://github.com/ejtraderLabs/ejtraderMT\ncd ejtraderMT\npython setup.py install\n\nor \n\npip install git+https://github.com/ejtraderLabs/ejtraderMT.git\n```\n\n\n## Runing Metatrader 5 on Docker or windows machine\n\n\n#### Easy way is using docker make sure to have docker runing on your machine\n\n```\ndocker volume create ejtraderMT\ndocker run -d --restart=always -p 5900:5900 -p 15555:15555 -p 15556:15556 -p 15557:15557 -p 15558:15558 --name ejtraderMT -v ejtraderMT:/data ejtrader/metatrader:5\n\n```\nor docker compose\n\n```yml\nversion: '3.8'\nservices:\n app:\n container_name: metatrader\n image: ejtrader/metatrader:5\n restart: unless-stopped\n ports:\n - '5900:5900'\n - '15555:15555'\n - '15556:15556'\n - '15557:15557'\n - '15558:15558'\n volumes:\n - ejtraderMT:/data\n \n \nvolumes:\n ejtraderMT: {}\n```\n\nDockerfile and source for Docker wine vnc [github](https://github.com/ejtraderLabs/Metatrader5-Docker)\n\n\n\n##### Access Metatrader 5 via VNC\n\ndownload VNC VIEWER or any other vnc client of your preference: [Download](https://www.realvnc.com/connect/download/viewer/)\n\n```\nusername: root\npassword: root\n```\n\n\n#### harder way installing direct to your Metatrader 5 on Windows Machine\nFirst download MQL5 source code and install it on the Metatrader 5 [github](https://github.com/ejtraderLabs/MQL5-ejtraderMT)\n\nsecond download and install Microsoft Visual C++ 2015 [Download](https://www.microsoft.com/pt-br/download/details.aspx?id=52685)\n\n\n\n\n\n\n\n\n\n\n\n### import\n\n```python\nfrom ejtraderMT import Metatrader\n```\n\n### Connect Metatrader 5\n\nmake sure ejtraderMT expert are load on the chart\n\n```python\n'''\nto change the host IP example Metatrader(\"192.168.1.100\") ou\nyou can use doman example \"metatraderserverdomain.com\"\n\nfor you local time on the Dataframe Metatrader(tz_local=True)\nattention utc time is the default for Dataframe index \"date\"\n\n\nfor real volume for active like WIN futures ou centralized market use Metatrader(real_volume=True)\nattention tick volume is the default\n\n\nto use more than one option just use , example Metatrader(host='hostIP',tz_local=True)\n'''\napi = Metatrader()\n\n```\n\n#### Account information\n\n```python\naccountInfo = api.accountInfo()\nprint(accountInfo)\nprint(accountInfo['broker'])\nprint(accountInfo['balance'])\n```\n\n#### Economic Calendar\n\n```python\nsymbol = \"EURUSD\"\nfromDate = \"20/08/2021\"\ntoDate = \"24/08/2022\"\n\ncalendar = api.calendar(symbol,fromDate,toDate)\nprint(calendar)\n\n\t currency\timpact\tevent\tcountry\tactual\tforecast\tprevious\ndate\t\t\t\t\t\t\t\n2021-08-20 06:00:00\tEUR\t2\tPPI m/m(ppi-mm)\tGermany(DE)\t1.9\t0.9\t1.3\n2021-08-20 06:00:00\tEUR\t1\tPPI y/y(ppi-yy)\tGermany(DE)\t10.4\t9.4\t8.5\n2021-08-20 17:00:00\tUSD\t2\tBaker Hughes US Oil Rig Count(baker-hughes-us-...\tUnited States(US)\t405\tNone\t397\n2021-08-20 17:00:00\tUSD\t2\tBaker Hughes US Total Rig Count(baker-hughes-u...\tUnited States(US)\t503\tNone\t500\n2021-08-20 19:30:00\tEUR\t1\tCFTC EUR Non-Commercial Net Positions(cftc-eur...\tEuropean Union(EU)\t57.6 K\tNone\t33.9 K\n...\t...\t...\t...\t...\t...\t...\t...\n2022-08-24 14:30:00\tUSD\t1\tEIA Heating Oil Stocks Change(eia-heating-oil-...\tUnited States(US)\t0.845 M\t-0.013 M\t0.249 M\n2022-08-24 14:30:00\tUSD\t1\tEIA Gasoline Stocks Change(eia-gasoline-stocks...\tUnited States(US)\t-0.027 M\t-1.829 M\t-4.642 M\n2022-08-24 14:30:00\tUSD\t1\tEIA Refinery Crude Oil Daily Inputs Change(eia...\tUnited States(US)\t-0.168 M\tNone\t-0.158 M\n2022-08-24 14:30:00\tUSD\t1\tEIA Refinery Utilization Rate Change(eia-refin...\tUnited States(US)\t0.3\tNone\t-0.8\n2022-08-24 17:00:00\tUSD\t1\t5-Year Note Auction(5-year-note-auction)\tUnited States(US)\t3.23\tNone\t2.86\n\n```\n\n# History Dataframe Ready\n\n#### History from Date to Date\n\n```python\n# you can add unlimited actives to list [\"EURUSD\",\"GBPUSD\",\"AUDUSD\"]\nsymbol = \"EURUSD\"\ntimeframe = \"M1\"\nfromDate = \"20/02/2021\"\ntoDate = \"24/02/2021\"\n\nhistory = api.history(symbol,timeframe,fromDate,toDate)\nprint(history)\n open high low close volume spread\ndate\n2021-02-21 23:00:00 1.21135 1.21138 1.21131 1.21134 7.0 35\n2021-02-21 23:01:00 1.21130 1.21135 1.21130 1.21135 6.0 43\n2021-02-21 23:04:00 1.21150 1.21184 1.21134 1.21184 13.0 31\n2021-02-21 23:05:00 1.21163 1.21207 1.21148 1.21181 39.0 42\n2021-02-21 23:06:00 1.21189 1.21193 1.21182 1.21182 17.0 64\n... ... ... ... ... ... ...\n2021-02-24 02:56:00 1.21629 1.21629 1.21590 1.21594 51.0 5\n2021-02-24 02:57:00 1.21592 1.21592 1.21574 1.21574 34.0 5\n2021-02-24 02:58:00 1.21574 1.21579 1.21572 1.21575 35.0 5\n2021-02-24 02:59:00 1.21576 1.21588 1.21573 1.21582 55.0 5\n2021-02-24 03:00:00 1.21583 1.21601 1.21578 1.21598 80.0 5\n\n[3104 rows x 6 columns]\n\n```\n\n#### History by period unit like 27 candles\n\n```python\n# you can add unlimited actives to list [\"EURUSD\",\"GBPUSD\",\"AUDUSD\"]\nsymbol = \"EURUSD\"\ntimeframe = \"M1\"\nfromDate = 27\n\nhistory = api.history(symbol,timeframe,fromDate)\nprint(history)\n\n open high low close volume spread\ndate\n2021-02-26 19:23:00 1.20846 1.20857 1.20837 1.20856 84.0 5\n2021-02-26 19:24:00 1.20855 1.20858 1.20842 1.20847 71.0 5\n2021-02-26 19:25:00 1.20846 1.20849 1.20832 1.20845 69.0 5\n2021-02-26 19:26:00 1.20844 1.20845 1.20823 1.20833 64.0 5\n2021-02-26 19:27:00 1.20833 1.20836 1.20821 1.20834 53.0 5\n... ... ... ... ... ... ...\n2021-02-26 22:55:00 1.20721 1.20730 1.20718 1.20719 46.0 13\n2021-02-26 22:56:00 1.20718 1.20738 1.20718 1.20731 39.0 12\n2021-02-26 22:57:00 1.20730 1.20731 1.20716 1.20717 45.0 18\n2021-02-26 22:58:00 1.20716 1.20731 1.20694 1.20704 77.0 16\n2021-02-26 22:59:00 1.20702 1.20705 1.20702 1.20704 16.0 37\n```\n\n#### History for lastest period gread for predict\n\n```python\n# you can add unlimited actives to list [\"EURUSD\",\"GBPUSD\",\"AUDUSD\"]\nsymbol = \"EURUSD\"\ntimeframe = \"M1\"\nfromDate = 27\n\nhistory = api.history(symbol,timeframe)\nprint(history)\n\n open high low close volume spread\ndate\n2021-02-26 19:23:00 1.20846 1.20857 1.20837 1.20856 84.0 5\n2021-02-26 19:24:00 1.20855 1.20858 1.20842 1.20847 71.0 5\n2021-02-26 19:25:00 1.20846 1.20849 1.20832 1.20845 69.0 5\n2021-02-26 19:26:00 1.20844 1.20845 1.20823 1.20833 64.0 5\n2021-02-26 19:27:00 1.20833 1.20836 1.20821 1.20834 53.0 5\n\n```\n\n#### History for multiple symbols merged dataframe\n\n```python\n# you can add unlimited actives to list [\"EURUSD\",\"GBPUSD\",\"AUDUSD\"] etc\nsymbol = [\"EURUSD\",\"GBPUSD\"]\ntimeframe = \"M1\"\nfromDate = \"20/02/2021\"\ntoDate = \"24/02/2021\"\n\n\nhistory = api.history(symbol,timeframe,fromDate,toDate)\nprint(history)\n\n\n open high low close volume spread gbpusd_open gbpusd_high gbpusd_low gbpusd_close gbpusd_volume gbpusd_spread\ndate\n2021-02-21 23:00:00 1.21135 1.21138 1.21131 1.21134 7.0 35 1.40113 1.40113 1.40110 1.40110 2.0 130\n2021-02-21 23:04:00 1.21150 1.21184 1.21134 1.21184 13.0 31 1.40119 1.40119 1.40119 1.40119 1.0 102\n2021-02-21 23:05:00 1.21163 1.21207 1.21148 1.21181 39.0 42 1.40174 1.40174 1.40167 1.40168 11.0 61\n2021-02-21 23:06:00 1.21189 1.21193 1.21182 1.21182 17.0 64 1.40156 1.40170 1.40132 1.40155 10.0 46\n2021-02-21 23:07:00 1.21181 1.21182 1.21180 1.21182 4.0 82 1.40156 1.40156 1.40156 1.40156 1.0 63\n... ... ... ... ... ... ... ... ... ... ... ... ...\n2021-02-24 02:56:00 1.21629 1.21629 1.21590 1.21594 51.0 5 1.41833 1.41835 1.41786 1.41800 62.0 8\n2021-02-24 02:57:00 1.21592 1.21592 1.21574 1.21574 34.0 5 1.41798 1.41801 1.41765 1.41766 54.0 8\n2021-02-24 02:58:00 1.21574 1.21579 1.21572 1.21575 35.0 5 1.41767 1.41789 1.41767 1.41768 64.0 8\n2021-02-24 02:59:00 1.21576 1.21588 1.21573 1.21582 55.0 5 1.41769 1.41782 1.41764 1.41769 42.0 9\n2021-02-24 03:00:00 1.21583 1.21601 1.21578 1.21598 80.0 5 1.41770 1.41797 1.41746 1.41784 95.0 8\n\n[3097 rows x 12 columns]\n```\n\n# Live streaming Price\n\n```python\nfrom ejtraderMT import Metatrader\n\napi = Metatrader()\n\nsymbols = [\"EURUSD\",\"GBPUSD\",\"AUDUSD\"]\ntimeframe = \"TICK\"\n\n\n# stream price\nwhile True:\n price = api.price(symbols,timeframe)\n print(price)\n\n```\n\n# Live streaming events\n\n```python\nfrom ejtraderMT import Metatrader\n\n\napi = Metatrader()\n\nsymbols = [\"EURUSD\",\"GBPUSD\",\"AUDUSD\"]\ntimeframe = \"TICK\"\n\n\n# stream event\nwhile True:\n event = api.event(symbols,timeframe)\n print(event)\n\n```\n\n# Trading and Orders Manipulation\n\n### You can create market or pending order with the commands.\n\n#### Market Orders\n\n```python\n# symbol, volume, stoploss, takeprofit, deviation\napi.buy(\"EURUSD\", 0.01, 1.18, 1.19, 5)\napi.sell(\"EURUSD\", 0.01, 1.18, 1.19, 5)\n```\n\n#### Limit Orders\n\n```python\n# symbol, volume, stoploss, takeprofit, price, deviation\napi.buyLimit(\"EURUSD\", 0.01, 1.17, 1.19, 1.18, 5)\napi.sellLimit(\"EURUSD\", 0.01, 1.20, 1.17, 1.19, 5)\n```\n\n#### Stop Orders\n\n```python\n#symbol, volume, stoploss, takeprofit, price, deviation\napi.buyStop(\"EURUSD\", 0.01, 1.18, 1.20, 1.19, 5)\napi.sellStop(\"EURUSD\", 0.01, 1.19, 1.17, 1.18, 5)\n```\n\n#### Positions & Manipulation\n\n```python\npositions = api.positions()\n\n\nif 'positions' in positions:\n for position in positions['positions']:\n api.CloseById(position['id'])\n\n\n```\n\n#### Orders & Manipulation\n\n```python\norders = api.orders()\n\nif 'orders' in orders:\n for order in orders['orders']:\n api.CancelById(order['id'])\n\n```\n\n#### Modify possition\n\n```python\n\napi.positionModify( id, stoploss, takeprofit)\n\n```\n\n#### Modify order\n\n```python\napi.orderModify( id, stoploss, takeprofit, price)\n\n```\n\n#### close by symbol\n\n```python\napi.CloseBySymbol(\"EURUSD\")\n\n```\n\n#### close particial\n\n```python\n# id , volume\napi.ClosePartial( id, volume)\n\n```\n\n#### If you want to cancel all Orders\n\n```python\napi.cancel_all()\n```\n\n#### if you want to close all positions\n\n```python\napi.close_all()\n```\n\n```\n\n# Project Based and reference thanks for\n\nDing Li @dingmaotu\nhttps://github.com/dingmaotu/mql-zmq\n\nNikolai khramkov @khramkov\nhttps://github.com/khramkov/MQL5-JSON-API\n\n\n```\n\n# New funcion persistent history Data on SQLite Multithrering\n\n### for saving to database\n\n```python\nfrom ejtraderMT import Metatrader\n\napi = Metatrader()\n\nsymbols = [\"EURUSD\"] # you can also use combind dataframe = [\"EURUSD\",\"GBPUSD\",\"AUDUSD\"]\ntimeframe = \"M1\"\n# saving 20 years of OHLC\nfromDate = \"01/01/2001\"\ntoDate = \"01/01/2021\"\n\n\napi.history(symbol,timeframe,fromDate,toDate,database=True)\n\n# or you could only pass from Date you want to start\n\n\n\"\"\"\nyou can pull the history and save using only fromDate\nits will pull history fromDate till now\n\napi.history(symbol,timeframe,fromDate,database=True)\n\"\"\"\n\n# example of saving 20 years of M1 OHLC takes around 3 minutes on a 4 core CPU\n\n 30%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258b | 2174/7305 [01:10<02:28, 34.60it/s]\n```\n\n# Read from Database\n\n```python\nfrom ejtraderMT import Metatrader\n\napi = Metatrader()\n\nsymbol = [\"EURUSD\"]\n\n\n\ndata = api.history(symbol)\n\n# example reading 20 year of M1 OHLC takes around 2 seconds read more than 7 million canldes\nElapsed run time: 2.041501855 seconds\n date open high low close volume spread\n0 2001-01-01 04:02:00 0.94220 0.94220 0.94220 0.94220 1.0 50\n1 2001-01-01 04:03:00 0.94240 0.94240 0.94240 0.94240 1.0 50\n2 2001-01-01 10:47:00 0.94250 0.94250 0.94250 0.94250 1.0 50\n3 2001-01-01 11:40:00 0.94190 0.94190 0.94190 0.94190 1.0 50\n4 2001-01-01 14:45:00 0.93970 0.93990 0.93970 0.93990 3.0 50\n... ... ... ... ... ... ... ...\n7286195 2020-12-31 17:56:00 1.22147 1.22152 1.22147 1.22152 20.0 8\n7286196 2020-12-31 17:57:00 1.22152 1.22162 1.22148 1.22157 58.0 8\n7286197 2020-12-31 17:58:00 1.22157 1.22167 1.22152 1.22166 77.0 9\n7286198 2020-12-31 17:59:00 1.22167 1.22177 1.22154 1.22154 129.0 8\n7286199 2020-12-31 18:00:00 1.22156 1.22156 1.22155 1.22155 2.0 11\n\n[7286200 rows x 7 columns]\n\n```\n\n### Future add comming soon\n\n```\neconomic calendar\nlevel 1 for futures only\nlevel 2 for futures only\n\n\n```\n",
"bugtrack_url": null,
"license": "GPL-3.0",
"summary": "Metatrader API",
"version": "3.17",
"project_urls": {
"Bug Reports": "https://github.com/traderpedroso/ejtraderMT/issues",
"Documentation": "https://ejtrader.readthedocs.io/",
"Download": "https://ejtrader.com",
"Homepage": "https://ejtraderMT.readthedocs.io/",
"Source": "https://github.com/traderpedroso/ejtraderMT"
},
"split_keywords": [
"metatrader",
"f-api",
"historical-data",
"financial-data",
"stocks",
"funds",
"etfs",
"indices",
"currency crosses",
"bonds",
"commodities",
"crypto currencies"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f6191481b90522415f7dde6cdaf33545a21b3c862ec02d722043f49f4ee8fe0e",
"md5": "3f178ec19a25e1e4f59e35ca76e5fca6",
"sha256": "6b22be054d440bdcf04076867d1fc6c6aae44bb8c1b95ba1b8525ff1aae3b4ee"
},
"downloads": -1,
"filename": "ejtraderMT-3.17-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3f178ec19a25e1e4f59e35ca76e5fca6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 23511,
"upload_time": "2023-06-16T16:29:28",
"upload_time_iso_8601": "2023-06-16T16:29:28.699003Z",
"url": "https://files.pythonhosted.org/packages/f6/19/1481b90522415f7dde6cdaf33545a21b3c862ec02d722043f49f4ee8fe0e/ejtraderMT-3.17-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "694cb60174f104eec6624defb218ed5d8ee6ce5bc5ffa6df6dc7edbd3a415cf2",
"md5": "a068c53bd45bbdfa182e80c572bfa67b",
"sha256": "31f5f1d2db8d788deb6903c20f0f95cf61ea62af38a4573fc80b379d3a66d85f"
},
"downloads": -1,
"filename": "ejtraderMT-3.17.tar.gz",
"has_sig": false,
"md5_digest": "a068c53bd45bbdfa182e80c572bfa67b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 27839,
"upload_time": "2023-06-16T16:29:30",
"upload_time_iso_8601": "2023-06-16T16:29:30.758242Z",
"url": "https://files.pythonhosted.org/packages/69/4c/b60174f104eec6624defb218ed5d8ee6ce5bc5ffa6df6dc7edbd3a415cf2/ejtraderMT-3.17.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-16 16:29:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "traderpedroso",
"github_project": "ejtraderMT",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "ejtradermt"
}