diff --git a/lib/zaif.rb b/lib/zaif.rb index 8bbe5ed..f2be50f 100644 --- a/lib/zaif.rb +++ b/lib/zaif.rb @@ -8,6 +8,7 @@ require "zaif/version" require "zaif/exceptions" +require 'websocket-client-simple' module Zaif class API @@ -65,7 +66,7 @@ def get_depth(currency_code, counter_currency_code = "jpy") # # Trade API # - + # Get user infomation. # Need api key. # @return [Hash] Infomation of user. @@ -73,11 +74,11 @@ def get_info json = post_ssl(@zaif_trade_url, "get_info", {}) return json end - + # Get your trade history. # Avalible options: from. count, from_id, end_id, order, since, end, currency_pair # Need api key. - # @param [Hash] + # @param [Hash] def get_my_trades(option = {}) json = post_ssl(@zaif_trade_url, "trade_history", option) # Convert to datetime @@ -139,6 +140,25 @@ def withdraw(currency_code, address, amount, option = {}) return json end + def stream(currency_code, counter_currency_code = "jpy", output_filename = nil) + f = if output_filename.nil? + STDOUT + else + File.open(output_filename, 'a') + end + ws = WebSocket::Client::Simple.connect "wss://ws.zaif.jp:8888/stream?currency_pair=#{currency_code}_#{counter_currency_code}" + ws.on :message do |msg| + f.puts msg.data + "\n" + end + + ws.on :close do |e| + f.close unless output_filename.nil? + end + + loop do + end + end + # # Class private method # @@ -228,6 +248,6 @@ def get_cool_down sleep(@cool_down_time) end end - + end end diff --git a/zaif.gemspec b/zaif.gemspec index 53c890f..687f7ee 100644 --- a/zaif.gemspec +++ b/zaif.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] + spec.add_dependency 'websocket-client-simple' spec.add_development_dependency "bundler", "~> 1.6" spec.add_development_dependency "rake", "~>0" spec.add_development_dependency "rspec", "~>0"