Skip to content

Instantly share code, notes, and snippets.

@evianzhow
Created February 28, 2017 02:46
Show Gist options
  • Save evianzhow/93b30edb5e1ac44f3dd2de7ef9a543d9 to your computer and use it in GitHub Desktop.
Save evianzhow/93b30edb5e1ac44f3dd2de7ef9a543d9 to your computer and use it in GitHub Desktop.
Downloader script for www.histdata.com
#!/usr/bin/env ruby
# This script only support ASCII format
# and tick download.
require 'uri'
require 'net/http'
require 'mechanize'
agent = Mechanize.new
agent.pluggable_parser.default = Mechanize::Download
for i_date in 2009..2017 # change date
date = i_date.to_s
for i_month in 1..12 # change month
month = '%02d' % i_month
datemonth = date + month
fxpair = 'XAUUSD' # change your instrument
platform = 'ASCII'
timeframe = 'T'
saved_name = 'HISTDATA_COM_' + [platform, fxpair, timeframe, datemonth].join('_') + '.zip'
referer_uri = "http://www.histdata.com/download-free-forex-historical-data/?/#{platform.downcase}/tick-data-quotes/#{fxpair.downcase}/#{date}/#{month}"
puts "Downloading: #{saved_name}"
if File.exist?saved_name
puts "Downloaded: #{saved_name}, skipping."
next
end
p = agent.get(referer_uri)
next_p = p.form_with(:name => 'file_down').submit
next_p.save(saved_name)
end
end
@sklinkert
Copy link

Thanks, it's saving me a lot of time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment