Skip to content
This repository was archived by the owner on Aug 3, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions lib/zaif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

require "zaif/version"
require "zaif/exceptions"
require 'websocket-client-simple'

module Zaif
class API
Expand Down Expand Up @@ -65,19 +66,19 @@ def get_depth(currency_code, counter_currency_code = "jpy")
#
# Trade API
#

# Get user infomation.
# Need api key.
# @return [Hash] Infomation of user.
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
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -228,6 +248,6 @@ def get_cool_down
sleep(@cool_down_time)
end
end

end
end
1 change: 1 addition & 0 deletions zaif.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down