forexfactory calendar downloader
futures io futures trading

forexfactory calendar downloader
Updated: Views / Replies:16,350 / 13
Created: by enjoyaol Attachments:3

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 100,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Thread Tools Search this Thread

forexfactory calendar downloader

  #11 (permalink)
Stuttgart, Germany
Trading Experience: Master
Platform: Tradestation, Jigsaw
Broker/Data: TS Brokerage / InteractiveBrokers / Rithmic
Favorite Futures: ES, TF, NQ, Stocks
Posts: 21 since May 2010
Thanks: 23 given, 21 received

i had some issues with the "actual" and found another (working) script by accident...

from bs4 import BeautifulSoup
import requests
import datetime
import logging
import csv

def setLogger():
                    format='%(asctime)s - %(levelname)s - %(message)s',
    console = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')

def getEconomicCalendar(startlink,endlink):

    # write to console current status"Scraping data for link: {}".format(startlink))

    # get the page and make the soup
    baseURL = ""
    r = requests.get(baseURL + startlink)
    data = r.text
    soup = BeautifulSoup(data, "lxml")

    # get and parse table data, ignoring details and graph
    table = soup.find("table", class_="calendar__table")

    # do not use the ".calendar__row--grey" css selector (reserved for historical data)
    trs ="tr.calendar__row.calendar_row")
    fields = ["date","time","currency","impact","event","actual","forecast","previous"]

    # some rows do not have a date (cells merged)
    curr_year = startlink[-4:]
    curr_date = ""
    curr_time = ""
    for tr in trs:

        # fields may mess up sometimes, see Tue Sep 25 2:45AM French Consumer Spending
        # in that case we append to errors.csv the date time where the error is
            for field in fields:
                data ="td.calendar__cell.calendar__{}.{}".format(field,field))[0]
                # print(data)
                if field=="date" and data.text.strip()!="":
                    curr_date = data.text.strip()
                elif field=="time" and data.text.strip()!="":
                    # time is sometimes "All Day" or "Day X" (eg. WEF Annual Meetings)
                    if data.text.strip().find("Day")!=-1:
                        curr_time = "12:00am"
                        curr_time = data.text.strip()
                elif field=="currency":
                    currency = data.text.strip()
                elif field=="impact":
                    # when impact says "Non-Economic" on mouseover, the relevant
                    # class name is "Holiday", thus we do not use the classname
                    impact = data.find("span")["title"]
                elif field=="event":
                    event = data.text.strip()
                elif field=="actual":
                    actual = data.text.strip()
                elif field=="forecast":
                    forecast = data.text.strip()
                elif field=="previous":
                    previous = data.text.strip()

            dt = datetime.datetime.strptime(",".join([curr_year,curr_date,curr_time]),
                                            "%Y,%a%b %d,%I:%M%p")
            with open("errors.csv","a") as f:

    # exit recursion when last available link has reached
    if startlink==endlink:"Successfully retrieved data")

    # get the link for the next week and follow
    follow ="")
    follow = follow[0]["href"]

if __name__ == "__main__":
    Run this using the command "python `script_name`.py >> `output_name`.csv"

Reply With Quote

Can you help answer these questions
from other members on futures io?
How to detach charts and save chart position
Block order question
Emini and Emicro Index
GetRTAccountEquity - EasyLanguage, MultiCharts, Daily Account P&L
Need help to code these studies
Does Tradestation on windows server?
Best Threads (Most Thanked)
in the last 7 days on futures io
Recession? Depression? Bailout!
278 thanks
ES futures Spoo-nalysis SP500/SPX
255 thanks
Coronavirus COVID-19
185 thanks
Understanding Footprint Charts / Number bars
107 thanks
What's your "comfort" number?
51 thanks
  #12 (permalink)
Salt Lake City, Utah
Trading Experience: Beginner
Platform: Jigsaw, NinjaTrader8
Favorite Futures: ZB
Posts: 478 since Apr 2016
Thanks: 16 given, 454 received

That's funny. I searched and searched for something like this and couldn't find it. Now after I've already written my own code I see this thread.

The code did the parsing part. The next bit was to get the bot to poll forexfactory at the right time and report the results. However, I put that part on the shelf after I found some twitter bots. Seeing how that goes before I go to finishing it.

Reply With Quote
  #13 (permalink)
Manchester, UK
Posts: 1 since Jul 2017
Thanks: 0 given, 0 received

I've been using the script corvin wrote for the past year, works perfect on a linux system and then using grep to filter what you want out.

It's written in Python2

I can't post URL's so search Corvin Codirla, he has a link to the script on his website.

Reply With Quote
  #14 (permalink)
Suffield, CT
Trading Experience: Advanced
Platform: MC, NT, Python, R
Broker/Data: IB, Oanda, IQFeed
Favorite Futures: ES, NQ, YM, CL, RB, 6E
Fu510n's Avatar
Posts: 104 since Oct 2009
Thanks: 780 given, 100 received

Tweaked for Python3

Jens89 View Post

do you have an alternative for python 3? I see that mechanize is only available for python2. it'd be awesome if you could change it for python3 as I'm not that good of a python programmer yet!


I just saw your request as I went back to grab the code I tweaked previously - as I've mostly been using Python 3 of late, I updated the code to work with Python 3 now (embedded below). Primarily just had to swap out the cookielib module with http.cookiejar and update print() statements to the Python 3 syntax variant.


#!/usr/bin/env python

from __future__ import unicode_literals
import sys
import datetime
import getopt
# import codecs
import pprint
import lxml.html
import mechanize
#import cookielib
import http.cookiejar

# some utils
pp = pprint.PrettyPrinter()
debug = 0

# variables
#OUTFILE = r"events.csv"
USAGE = " <-h> <-f {filename}> <-w {this|next|mmmdd.yyyy}> <-m {this|next|mmm.yyyy}>\n"

# our month list for the URL
monthslist = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]

# sets up the browser
br = mechanize.Browser()
#cj = cookielib.LWPCookieJar()
cj = http.cookiejar.LWPCookieJar()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

# set correct timezone"")
formindex = 0
for form in br.forms():
    if "timezone.php" in form.action:
        form["timezoneoffset"] = ["0"]
    formindex += 1

# br.submit()

def getData(html, outfile):
    Gets data from one page of events
    root = lxml.html.fromstring(html)
    #lines = root.find_class("calendar__row calendar_row calendar__row--grey")
    #if not lines:
    lines = root.find_class("calendar__row calendar_row")

    # curWeekDay = None
    curMonthDay = None
    time = curTime = ""
    # pp.pprint(lines)
    for event in lines:
        # pp.pprint(event)
        if len(event.xpath("td[@class='calendar__cell calendar__date date']")) > 0:
            date = event.xpath("td[@class='calendar__cell calendar__date date']")[0]

        # get the day of the month
        weekDay = date.xpath("span")
        monthDay = date.xpath("span/span")
        if len(weekDay) > 0:
            # curWeekDay = weekDay[0].text
            # print "curWeekDay=[" + curWeekDay + "]"
            curMonthDay = monthDay[0].text
            if debug:
                print( "curMonthDay=[", curMonthDay, "]" )

        # get the time
        curTime = time
        time = event.xpath("td[contains(@class, 'calendar__time')]")[0].text if len(event.xpath("td[contains(@class, 'calendar__time')]")) else ""
        if time == '' or time == None:
            time = curTime
        if debug:
            print( "time=[", str(time), "]" )

        # get currency
        currency = event.xpath("td[contains(@class, 'calendar__currency')]")[0].text if len(event.xpath("td[contains(@class, 'calendar__currency')]")) else ""
        currency = currency.strip( "\n" )
        if currency == None:
        if debug:
            print( "currency=[", currency, "]" )

        # get impact
        impact = event.xpath("td[contains(@class, 'calendar__impact')]/div/span/@title")[0] if len(event.xpath("td[contains(@class, 'calendar__impact')]/div/span/@title")) else ""
        if debug:
            print( "impact=[", impact, "]" )

        # get name of event
        nevent = event.xpath("td[contains(@class, 'calendar__event')]/div/span")[0].text if len(event.xpath("td[contains(@class, 'calendar__event')]/div/span")) else ""
        if debug:
            print( "nevent=[", nevent, "]" )

        # get actual
        actual = event.xpath("td[contains(@class, 'calendar__actual')]/span")[0].text if len(event.xpath("td[contains(@class, 'calendar__actual')]/span")) else ""

        # retry if actual is in a span (can happen if they colorize it)
        # if actual is None or len(actual.strip()) == 0:
        #     actual = event.xpath("td[@class='actual']/span")[0].text if len(event.xpath("td[@class='actual']/span")) else ""
        actual = actual.strip().replace("\n", " ") if actual is not None else ""
        if debug:
            print( "actual=[", actual, "]" )

        # get forecast
        forecast = event.xpath("td[contains(@class, 'calendar__forecast')]")[0].text if len(event.xpath("td[contains(@class, 'calendar__forecast')]")) else ""
        # retry if forecast is in a span (can happen if they colorize it)
        # if forecast is None or len(forecast.strip()) == 0:
        #    forecast = event.xpath("td[@class='forecast']/span")[0].text if len(event.xpath("td[@class='forecast']/span")) else ""
        forecast = forecast.strip().replace("\n", " ") if forecast is not None else ""
        if debug:
            print( "forecast=[", forecast, "]" )

        # get previous
        previous = event.xpath("td[contains(@class, 'calendar__previous')]")[0].text if len(event.xpath("td[contains(@class, 'calendar__previous')]")) else ""
        # retry if previous is in a span (can happen if they colorize it)
        if previous is None or len(previous.strip()) == 0:
            previous = event.xpath("td[contains(@class, 'calendar__previous')]/span")[0].text if len(event.xpath("td[contains(@class, 'calendar__previous')]/span")) else ""
        previous = previous.strip().replace("\n", " ") if previous is not None else ""
        if debug:
            print( "previous=[", previous, "]\n" )

        outfile.write("{};{};{};{};{};{};{};{}\n".format(curMonthDay, time, currency, impact, nevent, actual, forecast, previous))


    opts, args = getopt.getopt(sys.argv[1:], "f:hm:w:")
except getopt.GetoptError:

for opt, arg in opts:

    if opt == "-h":

    if opt == "-f":
        OUTFILE = arg
    elif opt == "-w" or opt == "-m":
        outfile = open(OUTFILE, "w") if OUTFILE != "" else sys.stdout
        if opt == "-w":
            url = "{}{}".format(WEEKURL, arg)
            url = "{}{}".format(MONTHURL, arg)
        sys.stderr.write("Getting {} from {}\n".format(arg, url))
        html = br.response().read()
        getData(html, outfile)
        if outfile is not sys.stdout:

outfile = open(OUTFILE, "w") if OUTFILE != "" else sys.stdout
while year <= END_YEAR:
    for month in monthslist:
        url = "{}{}.{}".format(MONTHURL, month, year)
        sys.stderr.write("Getting {} {} from {}\n".format(month.title(), year, url))
        html = br.response().read()
        getData(html, outfile)
    year += 1
if outfile is not sys.stdout:

Follow me on Twitter Visit my Facebook Reply With Quote
The following user says Thank You to Fu510n for this post:


futures io Trading Community Platforms and Indicators Matlab, R project and Python > forexfactory calendar downloader

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

futures io is celebrating 10-years w/ over $18,000 in prizes!

Right now

$250 Amazon Gift Cards with our "Thanks Contest" challenge!

Right now

Similar Threads
Thread Thread Starter Forum Replies Last Post
Economic Events Downloader (news) Nicolas11 Platforms and Indicators 27 June 2nd, 2018 10:16 AM
chard downloader NT7 snusnufreak NinjaTrader 3 December 10th, 2013 04:02 PM
Market Analyzer as a Historical Downloader? LostTrader NinjaTrader 2 February 17th, 2013 09:49 PM
NT7 excel downloader tinkerz NinjaTrader 0 February 16th, 2013 04:11 PM
Data Downloader StockJock Platforms and Indicators 22 April 8th, 2012 01:44 PM

All times are GMT -4. The time now is 05:09 PM. (this page content is cached, log in for real-time version)

Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432,
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts