Package: ejtraderMT
EjtraderMT Python Metatrader 5 APIInstall stable version using pippip install ejtraderMT -UFrom source codefor developers attention may contain countless bugsgit clone https://github.com/ejtraderLabs/ejtraderMT
cd ejtraderMT
python setup.py install

or 

pip install git+https://github.com/ejtraderLabs/ejtraderMT.gitRuning Metatrader 5 on Docker or windows machineEasy way is using docker make sure to have docker runing on your machinedocker 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:5or docker composeversion: '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 vncgithubAccess Metatrader 5 via VNCdownload VNC VIEWER  or any other vnc client of your preference:Downloadusername: root
password: rootharder way installing direct to your Metatrader 5 on Windows MachineFirst download MQL5 source code and install it on the Metatrader 5githubsecond download and install Microsoft Visual C++ 2015DownloadimportfromejtraderMTimportMetatraderConnect Metatrader 5make sure ejtraderMT expert are load on the chart'''to change the host IP example Metatrader("192.168.1.100") ouyou 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 defaultto use more than one option just use , example Metatrader(host='hostIP',tz_local=True)'''api=Metatrader()Account informationaccountInfo=api.accountInfo()print(accountInfo)print(accountInfo['broker'])print(accountInfo['balance'])Economic Calendarsymbol="EURUSD"fromDate="20/08/2021"toDate="24/08/2022"calendar=api.calendar(symbol,fromDate,toDate)print(calendar)currencyimpacteventcountryactualforecastpreviousdate2021-08-2006:00:00EUR2PPIm/m(ppi-mm)Germany(DE)1.90.91.32021-08-2006:00:00EUR1PPIy/y(ppi-yy)Germany(DE)10.49.48.52021-08-2017:00:00USD2BakerHughesUSOilRigCount(baker-hughes-us-...UnitedStates(US)405None3972021-08-2017:00:00USD2BakerHughesUSTotalRigCount(baker-hughes-u...UnitedStates(US)503None5002021-08-2019:30:00EUR1CFTCEURNon-CommercialNetPositions(cftc-eur...EuropeanUnion(EU)57.6KNone33.9K........................2022-08-2414:30:00USD1EIAHeatingOilStocksChange(eia-heating-oil-...UnitedStates(US)0.845M-0.013M0.249M2022-08-2414:30:00USD1EIAGasolineStocksChange(eia-gasoline-stocks...UnitedStates(US)-0.027M-1.829M-4.642M2022-08-2414:30:00USD1EIARefineryCrudeOilDailyInputsChange(eia...UnitedStates(US)-0.168MNone-0.158M2022-08-2414:30:00USD1EIARefineryUtilizationRateChange(eia-refin...UnitedStates(US)0.3None-0.82022-08-2417:00:00USD15-YearNoteAuction(5-year-note-auction)UnitedStates(US)3.23None2.86History Dataframe ReadyHistory from Date to Date# 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)openhighlowclosevolumespreaddate2021-02-2123:00:001.211351.211381.211311.211347.0352021-02-2123:01:001.211301.211351.211301.211356.0432021-02-2123:04:001.211501.211841.211341.2118413.0312021-02-2123:05:001.211631.212071.211481.2118139.0422021-02-2123:06:001.211891.211931.211821.2118217.064.....................2021-02-2402:56:001.216291.216291.215901.2159451.052021-02-2402:57:001.215921.215921.215741.2157434.052021-02-2402:58:001.215741.215791.215721.2157535.052021-02-2402:59:001.215761.215881.215731.2158255.052021-02-2403:00:001.215831.216011.215781.2159880.05[3104rowsx6columns]History by period unit like 27 candles# you can add unlimited actives to list  ["EURUSD","GBPUSD","AUDUSD"]symbol="EURUSD"timeframe="M1"fromDate=27history=api.history(symbol,timeframe,fromDate)print(history)openhighlowclosevolumespreaddate2021-02-2619:23:001.208461.208571.208371.2085684.052021-02-2619:24:001.208551.208581.208421.2084771.052021-02-2619:25:001.208461.208491.208321.2084569.052021-02-2619:26:001.208441.208451.208231.2083364.052021-02-2619:27:001.208331.208361.208211.2083453.05.....................2021-02-2622:55:001.207211.207301.207181.2071946.0132021-02-2622:56:001.207181.207381.207181.2073139.0122021-02-2622:57:001.207301.207311.207161.2071745.0182021-02-2622:58:001.207161.207311.206941.2070477.0162021-02-2622:59:001.207021.207051.207021.2070416.037History for lastest period gread for predict# you can add unlimited actives to list  ["EURUSD","GBPUSD","AUDUSD"]symbol="EURUSD"timeframe="M1"fromDate=27history=api.history(symbol,timeframe)print(history)openhighlowclosevolumespreaddate2021-02-2619:23:001.208461.208571.208371.2085684.052021-02-2619:24:001.208551.208581.208421.2084771.052021-02-2619:25:001.208461.208491.208321.2084569.052021-02-2619:26:001.208441.208451.208231.2083364.052021-02-2619:27:001.208331.208361.208211.2083453.05History for multiple symbols merged dataframe# you can add unlimited actives to list  ["EURUSD","GBPUSD","AUDUSD"] etcsymbol=["EURUSD","GBPUSD"]timeframe="M1"fromDate="20/02/2021"toDate="24/02/2021"history=api.history(symbol,timeframe,fromDate,toDate)print(history)openhighlowclosevolumespreadgbpusd_opengbpusd_highgbpusd_lowgbpusd_closegbpusd_volumegbpusd_spreaddate2021-02-2123:00:001.211351.211381.211311.211347.0351.401131.401131.401101.401102.01302021-02-2123:04:001.211501.211841.211341.2118413.0311.401191.401191.401191.401191.01022021-02-2123:05:001.211631.212071.211481.2118139.0421.401741.401741.401671.4016811.0612021-02-2123:06:001.211891.211931.211821.2118217.0641.401561.401701.401321.4015510.0462021-02-2123:07:001.211811.211821.211801.211824.0821.401561.401561.401561.401561.063.......................................2021-02-2402:56:001.216291.216291.215901.2159451.051.418331.418351.417861.4180062.082021-02-2402:57:001.215921.215921.215741.2157434.051.417981.418011.417651.4176654.082021-02-2402:58:001.215741.215791.215721.2157535.051.417671.417891.417671.4176864.082021-02-2402:59:001.215761.215881.215731.2158255.051.417691.417821.417641.4176942.092021-02-2403:00:001.215831.216011.215781.2159880.051.417701.417971.417461.4178495.08[3097rowsx12columns]Live streaming PricefromejtraderMTimportMetatraderapi=Metatrader()symbols=["EURUSD","GBPUSD","AUDUSD"]timeframe="TICK"# stream pricewhileTrue:price=api.price(symbols,timeframe)print(price)Live streaming eventsfromejtraderMTimportMetatraderapi=Metatrader()symbols=["EURUSD","GBPUSD","AUDUSD"]timeframe="TICK"# stream eventwhileTrue:event=api.event(symbols,timeframe)print(event)Trading and Orders ManipulationYou can create market or pending order with the commands.Market Orders# symbol, volume, stoploss, takeprofit, deviationapi.buy("EURUSD",0.01,1.18,1.19,5)api.sell("EURUSD",0.01,1.18,1.19,5)Limit Orders# symbol, volume, stoploss, takeprofit, price, deviationapi.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#symbol, volume, stoploss, takeprofit, price, deviationapi.buyStop("EURUSD",0.01,1.18,1.20,1.19,5)api.sellStop("EURUSD",0.01,1.19,1.17,1.18,5)Positions & Manipulationpositions=api.positions()if'positions'inpositions:forpositioninpositions['positions']:api.CloseById(position['id'])Orders & Manipulationorders=api.orders()if'orders'inorders:fororderinorders['orders']:api.CancelById(order['id'])Modify possitionapi.positionModify(id,stoploss,takeprofit)Modify orderapi.orderModify(id,stoploss,takeprofit,price)close by symbolapi.CloseBySymbol("EURUSD")close particial# id , volumeapi.ClosePartial(id,volume)If you want to cancel all Ordersapi.cancel_all()if you want to close all positionsapi.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-APINew funcion persistent history Data on SQLite Multithreringfor saving to databasefromejtraderMTimportMetatraderapi=Metatrader()symbols=["EURUSD"]# you can also use combind dataframe = ["EURUSD","GBPUSD","AUDUSD"]timeframe="M1"# saving 20 years of OHLCfromDate="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 fromDateits will pull history fromDate till nowapi.history(symbol,timeframe,fromDate,database=True)"""# example of saving 20 years of M1 OHLC takes around 3 minutes on a 4 core CPU30%|█████████████████████████████████▋|2174/7305[01:10<02:28,34.60it/s]Read from DatabasefromejtraderMTimportMetatraderapi=Metatrader()symbol=["EURUSD"]data=api.history(symbol)# example reading 20 year of M1 OHLC takes around 2 seconds read more than 7 million canldesElapsedruntime:2.041501855secondsdateopenhighlowclosevolumespread02001-01-0104:02:000.942200.942200.942200.942201.05012001-01-0104:03:000.942400.942400.942400.942401.05022001-01-0110:47:000.942500.942500.942500.942501.05032001-01-0111:40:000.941900.941900.941900.941901.05042001-01-0114:45:000.939700.939900.939700.939903.050........................72861952020-12-3117:56:001.221471.221521.221471.2215220.0872861962020-12-3117:57:001.221521.221621.221481.2215758.0872861972020-12-3117:58:001.221571.221671.221521.2216677.0972861982020-12-3117:59:001.221671.221771.221541.22154129.0872861992020-12-3118:00:001.221561.221561.221551.221552.011[7286200rowsx7columns]Future add comming sooneconomic calendar
level 1 for futures only
level 2 for futures only