Class: ZaifWrapper::Client::ZaifStreamApi
- Inherits:
-
Object
- Object
- ZaifWrapper::Client::ZaifStreamApi
- Defined in:
- lib/zaif_wrapper/client.rb
Constant Summary collapse
- REQUEST_URL_BASE =
'wss://ws.zaif.jp:'
Instance Method Summary collapse
-
#initialize(port = 8888) ⇒ ZaifStreamApi
constructor
A new instance of ZaifStreamApi.
-
#stream(currency_pair, output_filename = nil) ⇒ Object
wss://ws.zaif.jp/stream?currency_pair=currency_pair.
Constructor Details
#initialize(port = 8888) ⇒ ZaifStreamApi
Returns a new instance of ZaifStreamApi.
174 175 176 |
# File 'lib/zaif_wrapper/client.rb', line 174 def initialize(port = 8888) @port = port end |
Instance Method Details
#stream(currency_pair, output_filename = nil) ⇒ Object
wss://ws.zaif.jp/stream?currency_pair=currency_pair
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# 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 |