Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MQL5 Economic Calendar Data Scraper

Overview

This Python script automates the extraction of historical economic calendar data from the MQL5 website. It utilizes Playwright for browser automation to navigate the dynamic date-picker interface and retrieve event details, including actual, forecast, and previous values, along with importance ratings. The collected data is processed, cleaned, and exported to a CSV file for further analysis.

Features

  • Automated Navigation: Programmatically controls the MQL5 economic calendar interface to select specific date ranges.
  • Dynamic Content Handling: Waits for JavaScript-rendered content to load before extracting data, ensuring completeness.
  • Data Cleaning: Removes currency symbols, normalizes whitespace, and handles HTML entities to ensure data consistency.
  • Configurable Date Range: Allows users to specify start and end years and months for data extraction.
  • Output Format: Saves the scraped data into a structured CSV file (mql5_calendar_YYYY_YYYY.csv) with UTF-8 encoding.

Prerequisites

  • Python 3.7+
  • Required libraries:
    • pandas
    • playwright

Install the dependencies using pip:

pip install pandas playwright

After installing playwright, install the required browser binaries:

playwright install chromium

Usage

  1. Clone or download the script TESTecdata.py.
  2. Run the script from the terminal:
python TESTecdata.py
  1. Follow the interactive prompts to enter the desired date range:
    • First year
    • Last year
    • First month
    • Last month

Example input:

Please input the first year you wanna scrape data: 2020
Please input the last year you wanna scrape data: 2026
Please input the first month you wanna scrape data: 1
Please input the last month you wanna scrape data: 1
  1. The script will launch a Chromium browser instance, navigate to the MQL5 economic calendar, and begin scraping data for the specified period. Progress is logged in the console.
  2. Upon completion, the data is saved to a CSV file in the current directory.

Output Structure

The resulting CSV file contains the following columns:

Column Description
Date Event date (YYYY-MM-DD)
Time Event time
Currency Currency code associated with the event
Event Name of the economic event
Actual Actual released value
Forecast Market forecast value
Previous Previous period's value
Importance Impact level (e.g., High, Medium, Low)

Notes

  • Execution Time: Scraping large date ranges may take significant time due to the need for page loads and dynamic content rendering.
  • Headless Mode: The browser runs in non-headless mode (headless=False) by default to facilitate debugging and monitoring. Modify the launch() parameter if headless execution is preferred.
  • Rate Limiting: The script includes deliberate delays to avoid overwhelming the server and to ensure data integrity. Adjust timeouts cautiously if modifying the code.
  • Error Handling: Basic error handling is implemented for network issues and unexpected interruptions. Users can stop the process safely using Ctrl+C.

License

This project is provided as-is for educational and research purposes. Ensure compliance with MQL5's terms of service when using this scraper.

About

Little economic calendar parser

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages