Created
September 20, 2017 11:43
-
-
Save prdn/c8e7abc16fc58ef73fb8c7595ed7d96d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
pair = 'BTCUSD' | |
csv = [['Date', 'Open', 'High', 'Low', 'Close', 'Volume']] | |
end_t = Time.now.to_i * 1000 | |
loop do | |
body = HTTParty.get("https://api.bitfinex.com/v2/candles/trade:1h:t#{pair}/hist?_bfx=1&limit=1500&end="+end_t.to_s).body | |
body = Oj.load(body) rescue nil | |
break if body.nil? | |
break if body.size == 0 | |
body.each do |e| | |
csv << [Time.at(e[0] / 1000).strftime('%Y-%m-%d %H:00:00'), e[1], e[3], e[4], e[2], e[5]] | |
end | |
end_t = body.last[0] - 1 | |
sleep 5 | |
end | |
File.write('/home/bke01/candles.csv', csv.map{ |v| v.join(",") }.join("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment