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.
232 233 234 |
# File 'lib/zaif_wrapper/client.rb', line 232 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
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/zaif_wrapper/client.rb', line 237 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 |