class ZaifWrapper::Client::ZaifStreamApi

Constants

REQUEST_URL_BASE

Public Class Methods

new(port = 8888) click to toggle source
# File lib/zaif_wrapper/client.rb, line 174
def initialize(port = 8888)
  @port = port
end

Public Instance Methods

stream(currency_pair, output_filename = nil) click to toggle source

wss://ws.zaif.jp/stream?currency_pair={currency_pair}

# File lib/zaif_wrapper/client.rb, line 179
def stream(currency_pair, output_filename = nil)
  f = if output_filename.nil?
        STDOUT
      else
        File.open(output_filename, 'a')
      end

  ws = WebSocket::Client::Simple.connect "#{REQUEST_URL_BASE}#{@port}/stream?currency_pair=#{currency_pair}"
  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