There is a program that connects to the server and receives some data from it + signals every 15 or 60 seconds.

require 'faye/websocket' require 'eventmachine' data = [] EM.run { ws = Faye::WebSocket::Client.new('wss://olymptrade.com/ws2') ws.on :open do |event| p [:open] ws.send('{"uuid":"JCBQ7XBRMYSL0JB4N5","pair":"Bitcoin","size":60}') end ws.on :message do |event| p [:message, event.data] data << event.data data_servertime = data[0].gsub(/[^\d]/, '').to_i data.delete_at(0) if ((data_servertime % 15) == 0) puts "Прошло 15 секунд" elsif ((data_servertime % 60) == 0) puts "Прошло 60 секунд" end end ws.on :close do |event| p [:close, event.code, event.reason] ws = nil end } 

When launched, it constantly displays the received data to the console:

 [:message, "{\"pair\":\"Bitcoin\",\"time\":1516567298,\"open\":11146.938,\"low\":11146.938,\"high\":11146.938,\"close\":11146.938}"] [:message, "{\"servertime\":1516567298}"] 

Questions:

  1. How do I put the rest of the data in the array (except servertime) pair, time, open, low, high, close

  2. How to make it so that all this information is not constantly displayed on the screen, but only what I output using the puts command

  • I apologize that I doubled but did not find another way to raise the topic. and remove the old one. if it can be done for money, please tell us how. - Anna
  • This can be done for free: click on the "edit" question and add a question. He will rise to the top, although perhaps not immediately. - D-side

0