Created
September 17, 2012 11:58
-
-
Save thisredone/3736918 to your computer and use it in GitHub Desktop.
Downloads tick data from dukascopy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'typhoeus' | |
require 'pry' | |
$currencies = { | |
"AUDJPY" => 1175270400, # starting from 2007.03.30 16:00 | |
"AUDNZD" => 1229961600, # starting from 2008.12.22 16:00 | |
"AUDUSD" => 1175270400, # starting from 2007.03.30 16:00 | |
"CADJPY" => 1175270400, # starting from 2007.03.30 16:00 | |
"CHFJPY" => 1175270400, # starting from 2007.03.30 16:00 | |
"EURAUD" => 1175270400, # starting from 2007.03.30 16:00 | |
"EURCAD" => 1222167600, # starting from 2008.09.23 11:00 | |
"EURCHF" => 1175270400, # starting from 2007.03.30 16:00 | |
"EURGBP" => 1175270400, # starting from 2007.03.30 16:00 | |
"EURJPY" => 1175270400, # starting from 2007.03.30 16:00 | |
"EURNOK" => 1175270400, # starting from 2007.03.30 16:00 | |
"EURSEK" => 1175270400, # starting from 2007.03.30 16:00 | |
"EURUSD" => 1175270400, # starting from 2007.03.30 16:00 | |
"GBPCHF" => 1175270400, # starting from 2007.03.30 16:00 | |
"GBPJPY" => 1175270400, # starting from 2007.03.30 16:00 | |
"GBPUSD" => 1175270400, # starting from 2007.03.30 16:00 | |
"NZDUSD" => 1175270400, # starting from 2007.03.30 16:00 | |
"USDCAD" => 1175270400, # starting from 2007.03.30 16:00 | |
"USDCHF" => 1175270400, # starting from 2007.03.30 16:00 | |
"USDJPY" => 1175270400, # starting from 2007.03.30 16:00 | |
"USDNOK" => 1222639200, # starting from 2008.09.28 22:00 | |
"USDSEK" => 1222642800, # starting from 2008.09.28 23:00 | |
"USDSGD" => 1222642800, # starting from 2008.09.28 23:00 | |
"AUDCAD" => 1266318000, # starting from 2010.02.16 11:00 | |
"AUDCHF" => 1266318000, # starting from 2010.02.16 11:00 | |
"CADCHF" => 1266318000, # starting from 2010.02.16 11:00 | |
"EURNZD" => 1266318000, # starting from 2010.02.16 11:00 | |
"GBPAUD" => 1266318000, # starting from 2010.02.16 11:00 | |
"GBPCAD" => 1266318000, # starting from 2010.02.16 11:00 | |
"GBPNZD" => 1266318000, # starting from 2010.02.16 11:00 | |
"NZDCAD" => 1266318000, # starting from 2010.02.16 11:00 | |
"NZDCHF" => 1266318000, # starting from 2010.02.16 11:00 | |
"NZDJPY" => 1266318000, # starting from 2010.02.16 11:00 | |
"XAGUSD" => 1289491200, # starting from 2010.11.11 16:00 | |
"XAUUSD" => 1305010800, # starting from 2011.05.10 07:00 | |
} | |
curs = $currencies.select { |x,_| x == 'EURUSD' } | |
hydra = Typhoeus::Hydra.new | |
curs.each do |currency, starting_time| | |
time, now = Time.at(starting_time), Time.now | |
[time, now].each &:gmtoff | |
rs = [] | |
while time < now | |
m, d, h = [time.month, time.day, time.hour].map { |x| x.to_s.rjust(2, ?0) } | |
rs << Typhoeus::Request.new("http://www.dukascopy.com/datafeed/#{currency}/#{time.year}/#{m}/#{d}/#{h}h_ticks.bi5") | |
time += 3600 | |
end | |
rs.each_slice(50) do |slice| | |
slice.each { |r| hydra.queue r } | |
hydra.run | |
slice.each do |r| | |
f = r.url[/datafeed\/(.+)/,1] | |
FileUtils.mkdir_p File.dirname(f) | |
File.write(f, r.response.body) rescue nil | |
end | |
print '.' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment