I'm trying to communicate with CoinEx (cryptocurrency exchange) API via WebSocket using Ruby 2.6. I have the following code:
require 'faye/websocket'
require 'eventmachine'
url = 'wss://socket.coinex.com/'
# url = 'wss://stream.binance.com:9443/ws/ltcbtc#miniTicker'
EM.run do
ws = Faye::WebSocket::Client.new(url)
ws.on :open do |event|
p [:open]
...
end
ws.on :message do |event|
p [:message]
...
end
ws.on :close do |event|
p [:close, event.code, event.reason]
...
end
end
When I run this code, I always see [:close, 1006, ""] immediately, without [:open]. I hacked deeply into gems (faye/websocket and eventmachine) and added some debug output to have better understanding of what is going on. Now my traceback is as follows:
/home/chernish2/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faye-websocket-0.10.9/lib/faye/websocket/client.rb:87:in `unbind'
/home/chernish2/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:1483:in `event_callback'
/home/chernish2/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run_machine'
/home/chernish2/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run'
/home/chernish2/soft/trader2/test/ws_test.rb:36:in `<main>'
emit_error(), message=Errno::ENETUNREACH
[:close, 1006, ""]
Which really doesn't make any sense to me since another URL
url = 'wss://stream.binance.com:9443/ws/ltcbtc#miniTicker'
works just fine, and when I'm using https://github.com/altangent/ccxws library (nodejs) it connects to CoinEx using exactly the same URL as in my code without any troubles which means I don't have problems connecting to CoinEx WS endpoint.
So what is wrong with my code? Thank you in advance!
Oh, it is working now, without any changes from my side. Seems like there was some problems on the server side.
Related
I'm trying to get a pure command line oauth flow for an installed app and it's not easy to piece this together... Docs are sorely lacking... I started with the drive example (https://github.com/google/google-api-ruby-client-samples/tree/master/drive) but when it gets to client.authorization = flow.authorize(file_storage) it tries to start webrick to put up a web page. I need something that works similarly to the CLI tools provided by google: it needs to print out the URL I need to visit and then read in the response that I can copy&paste. Is this possible with the google ruby client?
Looks like the following monkey-patch works:
module Google
class APIClient
class InstalledAppFlow
def authorize_cli(storage)
puts "Please visit: #{#authorization.authorization_uri.to_s}"
printf "Enter the code: code="
code = gets
#authorization.code = code
#authorization.fetch_access_token!
if #authorization.access_token
if storage.respond_to?(:write_credentials)
storage.write_credentials(#authorization)
end
#authorization
else
nil
end
end
end
end
end
New to ActiveMQ. Using ruby stomp gem. I believe I'm successfully publish'ing messages to the server, as I see them in the queue in my browser admin client. But on subscribe nothing happens, no error, no output. The "in subscribe" test text from puts never appears in stdout, nor does the msg.
Should I be using a different naming format for the queues?
require 'stomp'
port = 61613
client = Stomp::Client.new( 'admin', 'admin', '127.0.0.1', port )
client.publish("/queue/mine2", "hello world!")
puts "about to subscribe"
client.subscribe("/queue/mine2") do |msg|
puts "in subscribe"
puts msg
end
client.close
I believe You are closing the client before it gets a chance to receive anything.
If there is no preemption between client.subscribe and client.close background thread that listens for new messages never gets run.
You should try adding
client.join
before closing it.
Although client.join did successfully pull down the first message or two for me, after it ran, the code completely stopped working, and the subscriber would simply hang again. I was starting my client in a very similar way (just lacking creds):
client = Stomp::Client.new('localhost', 61613)
But I was able to get it working by using a URL instead:
client = Stomp::Client.new('stomp://localhost:61613')
With creds, it would look something like:
client = Stomp::Client.new('stomp://login:passcode#host:port')
Hope this helps the next person with this issue.
I am using watir-webdriver + ruby + win7 to test same pages. and I would get these logs while I start the ie explorer by using watir-webdriver:
Started InternetExplorerDriver server (32-bit)
2.32.3.0
Listening on port 5555
are there any methods to remove these logs? any help would be appreciated!
IEDriver supports a --silent flag that suppresses diagnostic output when the server is started.
Unfortunately, at least to my knowledge, it is not configurable when creating a browser instance. Instead, you need to directly modify the Selenium::Webdriver::IE::Server class' server_args method. You can modify the lib\selenium\webdriver\ie\server.rb file directly, but it is probably easier to monkey patch.
To monkey patch the silent flag, add the following to your code some point after requiring watir-webdriver (ie selenium-webdriver) but before opening the browser.
class Selenium::WebDriver::IE::Server
old_server_args = instance_method(:server_args)
define_method(:server_args) do
old_server_args.bind(self).() << "--silent"
end
end
For example, the following will no longer log any messages.
require 'watir-webdriver'
class Selenium::WebDriver::IE::Server
old_server_args = instance_method(:server_args)
define_method(:server_args) do
old_server_args.bind(self).() << "--silent"
end
end
b = Watir::Browser.new :ie
I would like to write an application in Ruby using Qt which will communicate over the network with other instances.
How can I integrate Qt's event loop with DRb or EventMachine?
EDIT:
I found the answer when I will have more time I will post it
require 'eventmachine'
require 'Qt4'
app = Qt::Application.new(ARGV)
hello_button = Qt::PushButton.new("Hello EventMachine")
hello_button.resize(100,20)
hello_button.show
EventMachine.run do
EM.add_periodic_timer(0.01) do
app.process_events
end
end
I starting to work with Ruby and Soap and had some questions:
How do I generate a WSDL file for the service I created?
Will it be compatible with an .NET client ?
begin
class MyServer < SOAP::RPC::StandaloneServer
# Handler methods
def add(a, b)
return a + b
end
def div(a, b)
return a / b
end
# Expose our services
def initialize(*args)
add_method(self, 'add', 'a', 'b')
add_method(self, 'div', 'a', 'b')
end
end
server = MyServer.new("MyServer",
'urn:ruby:calculation', 'localhost', 8080)
trap('INT'){
server.shutdown
}
server.start
rescue => err
puts err.message
end
ActionWebService (previously in Rails core, now a gem) has tools to generate WSDL files. You can use the tools even if you're not running your service within Rails.
http://www.datanoise.com/articles/2008/7/2/actionwebservice-is-back
As for whether it will work with a .NET client, the answer is maybe. Many .NET clients seem to expect Microsoft's "extended" SOAP info, which .NET webservices provide by default. If the client is also able to consume a service without that extra stuff, then sure.
UPDATE #1
The above link no longer appears to work. There are however forks of ActionWebService that have popped up over on github. You can see a pretty good list of them here. Here are a couple of links to some key versions:
original datanoise version
clevertechru's port, works w/ Rails 3.1.* & Ruby 1.9