Scraper to easily extract historical forex, stock, ect. prices from MetaTrader5 with Python
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
MT5Scraper is designed to help obtaining historical price data from MetaTrader5 and simplify the process. It is possible to list all available symbols as a tree with the MT5Scraper class. So it is very easy to retrieve and save data for the desired symbols.
To use the module some requirements must be met and some simple steps must be taken.
In order to work with the MT5Scraper class, it is necessary that MetaTrader 5 is already installed on the system. In addition, an account must be set up so that the queries can be made.
MetaTrader5 provides a lot of binary wheels but only for w32 and w64. No Linux, no MacOS and no source code. Accordingly, as MT5Scraper requires MetaTrader5, the installation is only possible under Windows.
Install the module with pip
pip3 install git+https://github.com/XO30/MT5Scraper
Import the class MT5Scraper from the library mt5_scraper
from mt5_scraper import MT5Scraper
Make an instance of the class
In total, the following 3 parameters must be passed:
- login: login to your MT5 account
- server: server name of the account
- password: password to the account
scraper = MT5Scraper(1234, 'SERVERNAME', 'PASSWORD')
print(scraper)
With the method get_symbol_count you get the number of symbols the account has in total.
scraper.get_symbol_count()
With the method get_symbols you get a list of all symbols. Additionally the whole structure is displayed as a tree.
all_symbols = scraper.get_symbols()
It is possible to pass the following parameters to the method get_symbols:
- symbol_path: path, to the desired symbols
- visualize: should the tree structure be output
stocks_switzerland = scraper.get_symbols('Stocks/Switzerland/Software & IT Services', visualize=True)
with the method get_historical_data you can download the historical prices of the desired symbols. The method has the following parameters:
- symbol_list: list containing the desired symbols
- timeframe: desired timeframe (D1, H1, etc.)
- start_date: prices from (Y, M, D, h, m, s)
- end_date: prices until (Y, M, D, h, m, s)
- save: True if dataframe should be saved else False
- save_path: folder Path to save the csv
In total there are 21 timeframes to choose: M1, M2, M3, M4, M5, M6, M10, M12, M15, M20, M30, H1, H2, H3, H4, H6, H8, H12, D1, W1, MN1
data = scraper.get_historical_data(stocks_switzerland,
'H1',
(2022, 1, 1),
(2023, 1, 11, 13, 0),
save=True,
save_path='stocks_switzerland_D1')
data['TEMN.S']
Distributed under the Apache-2.0 license. See LICENSE.txt
for more information.
Stefan Siegler: dev@siegler.one
Project Link: https://github.com/XO30/MT5Scraper